# HG changeset patch # User David Demelier # Date 1525898087 -7200 # Node ID 91bc29e873992bc055449c77789e583626c31b00 # Parent 808171f7bfa2b540d188e5478337e267f83bfc1a Irccd: use Boost.Predef, closes #805 @1h diff -r 808171f7bfa2 -r 91bc29e87399 MIGRATING.md --- a/MIGRATING.md Wed May 09 20:11:50 2018 +0200 +++ b/MIGRATING.md Wed May 09 22:34:47 2018 +0200 @@ -58,7 +58,7 @@ - The property `Directory.count` has been removed. -### Module Plugin +#### Module Plugin The following properties in `Irccd.Plugin` has been renamed: @@ -69,3 +69,6 @@ Note: these paths are no more automatically detected and set with the new `[paths]` and `[paths.]` sections. +#### Module System + + - The function `Irccd.System.name` has now well defined return value. diff -r 808171f7bfa2 -r 91bc29e87399 cmake/IrccdSystem.cmake --- a/cmake/IrccdSystem.cmake Wed May 09 20:11:50 2018 +0200 +++ b/cmake/IrccdSystem.cmake Wed May 09 22:34:47 2018 +0200 @@ -73,27 +73,6 @@ endif () # -# System identification. -# ------------------------------------------------------------------- -# - -if (WIN32) - set(IRCCD_SYSTEM_WINDOWS TRUE) -elseif (APPLE) - set(IRCCD_SYSTEM_MAC TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - set(IRCCD_SYSTEM_FREEBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "DragonFly") - set(IRCCD_SYSTEM_DRAGONFLYBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") - set(IRCCD_SYSTEM_NETBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") - set(IRCCD_SYSTEM_OPENBSD TRUE) -elseif (CMAKE_SYSTEM_NAME MATCHES "Linux") - set(IRCCD_SYSTEM_LINUX TRUE) -endif () - -# # Portability requirements. # ------------------------------------------------------------------- # @@ -159,12 +138,10 @@ # If HAVE_GETLOGIN is defined, include: # # #include -if (NOT IRCCD_SYSTEM_WINDOWS) - check_function_exists(getlogin HAVE_GETLOGIN) +check_function_exists(getlogin HAVE_GETLOGIN) - if (NOT HAVE_UNISTD_H) - set(HAVE_GETLOGIN FALSE) - endif () +if (NOT HAVE_UNISTD_H) + set(HAVE_GETLOGIN FALSE) endif () # getpid() function diff -r 808171f7bfa2 -r 91bc29e87399 cmake/function/IrccdDefineExecutable.cmake --- a/cmake/function/IrccdDefineExecutable.cmake Wed May 09 20:11:50 2018 +0200 +++ b/cmake/function/IrccdDefineExecutable.cmake Wed May 09 22:34:47 2018 +0200 @@ -37,7 +37,7 @@ function(irccd_define_executable) set(options "") set(oneValueArgs DESCRIPTION TARGET) - set(multiValueArgs SOURCES FLAGS LIBRARIES INCLUDES) + set(multiValueArgs SOURCES FLAGS LIBRARIES INCLUDES OPTIONS) cmake_parse_arguments(EXE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -54,6 +54,7 @@ add_executable(${EXE_TARGET} ${EXE_SOURCES}) target_include_directories(${EXE_TARGET} PRIVATE ${EXE_INCLUDES}) target_compile_definitions(${EXE_TARGET} PRIVATE ${EXE_FLAGS}) + target_compile_options(${EXE_TARGET} PRIVATE ${EXE_OPTIONS}) target_link_libraries(${EXE_TARGET} ${EXE_LIBRARIES}) set_target_properties( diff -r 808171f7bfa2 -r 91bc29e87399 cmake/internal/sysconfig.hpp.in --- a/cmake/internal/sysconfig.hpp.in Wed May 09 20:11:50 2018 +0200 +++ b/cmake/internal/sysconfig.hpp.in Wed May 09 22:34:47 2018 +0200 @@ -47,20 +47,6 @@ #define IRCCD_VERSION "@IRCCD_VERSION@" /* - * System identification. - * ------------------------------------------------------------------ - */ - -#cmakedefine IRCCD_SYSTEM_WINDOWS -#cmakedefine IRCCD_SYSTEM_MAC -#cmakedefine IRCCD_SYSTEM_FREEBSD -#cmakedefine IRCCD_SYSTEM_DRAGONFLYBSD -#cmakedefine IRCCD_SYSTEM_NETBSD -#cmakedefine IRCCD_SYSTEM_OPENBSD -#cmakedefine IRCCD_SYSTEM_LINUX -#cmakedefine IRCCD_SYSTEM_UNKNOWN - -/* * User definable options. * ------------------------------------------------------------------ */ diff -r 808171f7bfa2 -r 91bc29e87399 doc/src/api/module/Irccd.System/Irccd.System.name.md --- a/doc/src/api/module/Irccd.System/Irccd.System.name.md Wed May 09 20:11:50 2018 +0200 +++ b/doc/src/api/module/Irccd.System/Irccd.System.name.md Wed May 09 22:34:47 2018 +0200 @@ -1,6 +1,20 @@ # Function Irccd.System.name -Get the operating system name. Usually Windows, FreeBSD, Linux and such. +Get the operating system name. Returns one of: + +- Linux +- Windows +- FreeBSD +- DragonFlyBSD +- OpenBSD +- NetBSD +- macOS +- Android +- Aix +- Haiku +- iOS +- Solaris +- Unknown # Synopsis diff -r 808171f7bfa2 -r 91bc29e87399 irccd/CMakeLists.txt --- a/irccd/CMakeLists.txt Wed May 09 20:11:50 2018 +0200 +++ b/irccd/CMakeLists.txt Wed May 09 22:34:47 2018 +0200 @@ -23,11 +23,9 @@ DESCRIPTION "The main irccd daemon." SOURCES CMakeLists.txt main.cpp INCLUDES ${irccd_SOURCE_DIR} + OPTIONS + $<$:-Wno-deprecated-declarations> LIBRARIES libirccd $<$:libirccd-js> ) - -if (IRCCD_SYSTEM_MAC) - target_compile_options(irccd PRIVATE -Wno-deprecated-declarations) -endif () diff -r 808171f7bfa2 -r 91bc29e87399 irccdctl/main.cpp --- a/irccdctl/main.cpp Wed May 09 20:11:50 2018 +0200 +++ b/irccdctl/main.cpp Wed May 09 22:34:47 2018 +0200 @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -72,7 +73,7 @@ using boost::asio::ip::tcp; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; @@ -177,7 +178,7 @@ */ std::unique_ptr read_connect_local(const ini::section& sc) { -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; const auto it = sc.find("path"); @@ -342,7 +343,7 @@ */ std::unique_ptr parse_connect_local(const option::result& options) { -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS option::result::const_iterator it; if ((it = options.find("-P")) == options.end() && (it = options.find("--path")) == options.end()) diff -r 808171f7bfa2 -r 91bc29e87399 libcommon/CMakeLists.txt --- a/libcommon/CMakeLists.txt Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/CMakeLists.txt Wed May 09 22:34:47 2018 +0200 @@ -64,11 +64,11 @@ Boost::system $<$:OpenSSL::Crypto> $<$:OpenSSL::SSL> - $<$:dl> - $<$:resolv> - $<$:mswsock> + $<$:resolv> + $<$:mswsock> $<$:shlwapi> $<$:ws2_32> + $<$:dl> PUBLIC_INCLUDES $ $ diff -r 808171f7bfa2 -r 91bc29e87399 libcommon/irccd/ini.cpp --- a/libcommon/irccd/ini.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/ini.cpp Wed May 09 22:34:47 2018 +0200 @@ -26,8 +26,10 @@ #include +#include + // for PathIsRelative. -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS # include #endif @@ -44,7 +46,7 @@ inline bool is_absolute(const std::string& path) noexcept { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS return !PathIsRelative(path.c_str()); #else return path.size() > 0 && path[0] == '/'; @@ -288,7 +290,7 @@ std::string file; if (!is_absolute(value)) { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS file = path + "\\" + value; #else file = path + "/" + value; diff -r 808171f7bfa2 -r 91bc29e87399 libcommon/irccd/socket_acceptor.hpp --- a/libcommon/irccd/socket_acceptor.hpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/socket_acceptor.hpp Wed May 09 22:34:47 2018 +0200 @@ -26,8 +26,6 @@ #include -#include - #include "acceptor.hpp" #include "socket_stream.hpp" @@ -148,7 +146,7 @@ */ using ip_acceptor = socket_acceptor; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS /** * Convenient Unix acceptor type. diff -r 808171f7bfa2 -r 91bc29e87399 libcommon/irccd/socket_connector.hpp --- a/libcommon/irccd/socket_connector.hpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/socket_connector.hpp Wed May 09 22:34:47 2018 +0200 @@ -31,8 +31,6 @@ #include "connector.hpp" #include "socket_stream.hpp" -#include - namespace irccd { namespace io { @@ -162,7 +160,7 @@ */ using ip_connector = socket_connector; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS /** * Convenient Unix conncetor type. diff -r 808171f7bfa2 -r 91bc29e87399 libcommon/irccd/socket_stream.hpp --- a/libcommon/irccd/socket_stream.hpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/socket_stream.hpp Wed May 09 22:34:47 2018 +0200 @@ -32,6 +32,7 @@ #include #include +#include #include "stream.hpp" @@ -229,7 +230,7 @@ */ using ip_stream = socket_stream; -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS /** * Convenient Unix stream type. diff -r 808171f7bfa2 -r 91bc29e87399 libcommon/irccd/string_util.cpp --- a/libcommon/irccd/string_util.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/string_util.cpp Wed May 09 22:34:47 2018 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include "sysconfig.hpp" #if defined(HAVE_POPEN) @@ -183,7 +185,7 @@ std::string subst_shell_attrs(const std::string& content) { -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS auto list = split(content, ","); if (list.empty()) diff -r 808171f7bfa2 -r 91bc29e87399 libcommon/irccd/system.cpp --- a/libcommon/irccd/system.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libcommon/irccd/system.cpp Wed May 09 22:34:47 2018 +0200 @@ -26,10 +26,11 @@ #include #include +#include #include "sysconfig.hpp" -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS # include # include #else @@ -40,11 +41,11 @@ # include #endif -#if defined(IRCCD_SYSTEM_LINUX) +#if BOOST_OS_LINUX # include #endif -#if defined(IRCCD_SYSTEM_MAC) +#if BOOST_OS_MACOS # include # include #endif @@ -157,7 +158,7 @@ { boost::filesystem::path path; -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS char folder[MAX_PATH] = {0}; if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, folder) == S_OK) { @@ -198,7 +199,7 @@ { boost::filesystem::path path; -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS char folder[MAX_PATH] = {0}; if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, folder) == S_OK) { @@ -242,20 +243,30 @@ std::string name() { -#if defined(IRCCD_SYSTEM_LINUX) +#if BOOST_OS_LINUX return "Linux"; -#elif defined(IRCCD_SYSTEM_WINDOWS) +#elif BOOST_OS_WINDOWS return "Windows"; -#elif defined(IRCCD_SYSTEM_FREEBSD) +#elif BOOST_OS_BSD_FREE return "FreeBSD"; -#elif defined(IRCCD_SYSTEM_DRAGONFLYBSD) +#elif BOOST_OS_BSD_DRAGONFLY return "DragonFlyBSD"; -#elif defined(IRCCD_SYSTEM_OPENBSD) +#elif BOOST_OS_BSD_OPEN return "OpenBSD"; -#elif defined(IRCCD_SYSTEM_NETBSD) +#elif BOOST_OS_BSD_NET return "NetBSD"; -#elif defined(IRCCD_SYSTEM_MAC) - return "Mac"; +#elif BOOST_OS_MACOS + return "macOS"; +#elif BOOST_OS_ANDROID + return "Android"; +#elif BOOST_OS_AIX + return "Aix"; +#elif BOOST_OS_HAIKU + return "Haiku"; +#elif BOOST_OS_IOS + return "iOS"; +#elif BOOST_OS_SOLARIS + return "Solaris"; #else return "Unknown"; #endif @@ -274,7 +285,7 @@ */ std::string version() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS const auto version = GetVersion(); const auto major = (DWORD)(LOBYTE(LOWORD(version))); const auto minor = (DWORD)(HIBYTE(LOWORD(version))); @@ -308,16 +319,16 @@ */ std::uint64_t uptime() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS return ::GetTickCount64() / 1000; -#elif defined(IRCCD_SYSTEM_LINUX) +#elif BOOST_OS_LINUX struct sysinfo info; if (sysinfo(&info) < 0) throw std::runtime_error(std::strerror(errno)); return info.uptime; -#elif defined(IRCCD_SYSTEM_MAC) +#elif BOOST_OS_MACOS struct timeval boottime; size_t length = sizeof (boottime); int mib[2] = { CTL_KERN, KERN_BOOTTIME }; @@ -351,7 +362,7 @@ */ std::uint64_t ticks() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS _timeb tp; _ftime(&tp); @@ -377,7 +388,7 @@ */ std::string home() { -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS char path[MAX_PATH]; if (SHGetFolderPathA(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, path) != S_OK) diff -r 808171f7bfa2 -r 91bc29e87399 libirccd-js/irccd/js/directory_jsapi.cpp --- a/libirccd-js/irccd/js/directory_jsapi.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd-js/irccd/js/directory_jsapi.cpp Wed May 09 22:34:47 2018 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include #include @@ -356,7 +358,7 @@ duk_put_number_list(plugin->context(), -1, constants); duk_put_function_list(plugin->context(), -1, functions); -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS duk_push_string(plugin->context(), "\\"); #else duk_push_string(plugin->context(), "/"); diff -r 808171f7bfa2 -r 91bc29e87399 libirccd/irccd/daemon/dynlib_plugin.cpp --- a/libirccd/irccd/daemon/dynlib_plugin.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/dynlib_plugin.cpp Wed May 09 22:34:47 2018 +0200 @@ -20,14 +20,15 @@ #include #include +#include #include #include "dynlib_plugin.hpp" -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS # define DYNLIB_EXTENSION ".dll" -#elif defined(IRCCD_SYSTEM_MAC) +#elif BOOST_OS_MACOS # define DYNLIB_EXTENSION ".dylib" #else # define DYNLIB_EXTENSION ".so" diff -r 808171f7bfa2 -r 91bc29e87399 libirccd/irccd/daemon/irccd.cpp --- a/libirccd/irccd/daemon/irccd.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/irccd.cpp Wed May 09 22:34:47 2018 +0200 @@ -18,6 +18,8 @@ #include +#include + #include #include @@ -84,7 +86,7 @@ /* * TODO: improve that with CMake options. */ -#if defined(IRCCD_SYSTEM_WINDOWS) +#if BOOST_OS_WINDOWS std::string normal = "log.txt"; std::string errors = "errors.txt"; #else diff -r 808171f7bfa2 -r 91bc29e87399 libirccd/irccd/daemon/server.cpp --- a/libirccd/irccd/daemon/server.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/server.cpp Wed May 09 22:34:47 2018 +0200 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include #include @@ -23,7 +25,7 @@ #include #include -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS # include # include # include @@ -504,7 +506,7 @@ * This is needed if irccd is started before DHCP or if DNS cache is * outdated. */ -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS (void)res_init(); #endif diff -r 808171f7bfa2 -r 91bc29e87399 libirccd/irccd/daemon/transport_util.cpp --- a/libirccd/irccd/daemon/transport_util.cpp Wed May 09 20:11:50 2018 +0200 +++ b/libirccd/irccd/daemon/transport_util.cpp Wed May 09 22:34:47 2018 +0200 @@ -20,6 +20,8 @@ #include +#include + #include #include #include @@ -128,7 +130,7 @@ { assert(sc.key() == "transport"); -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; const auto path = sc.get("path").value(); diff -r 808171f7bfa2 -r 91bc29e87399 tests/src/libcommon/io/main.cpp --- a/tests/src/libcommon/io/main.cpp Wed May 09 20:11:50 2018 +0200 +++ b/tests/src/libcommon/io/main.cpp Wed May 09 22:34:47 2018 +0200 @@ -19,6 +19,7 @@ #define BOOST_TEST_MODULE "io" #include #include +#include #include @@ -39,7 +40,7 @@ using boost::asio::ssl::context; #endif -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS using boost::asio::local::stream_protocol; #endif @@ -145,7 +146,7 @@ #endif // !HAVE_SSL -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS class local_io_test : public io_test { public: @@ -170,7 +171,7 @@ } }; -#endif // !IRCCD_SYSTEM_WINDOWS +#endif // !BOOST_OS_WINDOWS /** * List of fixtures to tests. @@ -180,7 +181,7 @@ #if defined(HAVE_SSL) , ssl_io_test #endif -#if !defined(IRCCD_SYSTEM_WINDOWS) +#if !BOOST_OS_WINDOWS , local_io_test #endif >;