diff --git a/CMakeLists.txt b/CMakeLists.txt index f21ddf4..9f3b37b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,8 +30,47 @@ set(EXPORT_SET_NAME ${PROJECT_NAME}Targets) include(cmake/Module.cmake) +# Modules to configure, with the modules they need (INTERNAL_DEPS, followed +# transitively); empty configures every module. OPTIONAL_DEPS are used only +# when named too. A project that embeds Void selects what it links, so the +# external packages of modules it never builds (LibArchive, OpenSSL, SQLite, +# libsodium) need not exist, as when cross-compiling. +set(VOID_ENABLED_MODULES "" CACHE STRING + "Void modules to configure (and their internal dependencies); empty for all") +set(_void_selected "") +if(VOID_ENABLED_MODULES) + set(_void_pending ${VOID_ENABLED_MODULES}) + while(_void_pending) + list(POP_FRONT _void_pending _void_module) + if(_void_module IN_LIST _void_selected) + continue() + endif() + set(_void_module_file "${CMAKE_CURRENT_SOURCE_DIR}/src/${_void_module}/module.cmake") + if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/${_void_module}") + message(FATAL_ERROR "[Void] VOID_ENABLED_MODULES names an unknown module '${_void_module}'") + endif() + list(APPEND _void_selected ${_void_module}) + if(EXISTS "${_void_module_file}") + file(READ "${_void_module_file}" _void_text) + # The words after INTERNAL_DEPS up to the next keyword or ')'. + if(_void_text MATCHES "INTERNAL_DEPS([^)]*)") + separate_arguments(_void_words UNIX_COMMAND "${CMAKE_MATCH_1}") + foreach(_void_word IN LISTS _void_words) + if(_void_word MATCHES "^[A-Z0-9_]+$") + break() + endif() + list(APPEND _void_pending ${_void_word}) + endforeach() + endif() + endif() + endwhile() +endif() + file(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/*) foreach(module_path ${children}) + if(_void_selected AND NOT module_path IN_LIST _void_selected) + continue() + endif() if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/${module_path}) if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/${module_path}/module.cmake) include(src/${module_path}/module.cmake) diff --git a/src/Testing/SignalHandler.cpp b/src/Testing/SignalHandler.cpp index 8b5e383..2f27d1f 100644 --- a/src/Testing/SignalHandler.cpp +++ b/src/Testing/SignalHandler.cpp @@ -47,18 +47,27 @@ static void crash_handler(int sig) { void install_signal_handlers(CrashCallback on_crash) { g_crash_callback = std::move(on_crash); +#ifdef _WIN32 + // No sigaction on Windows: the C runtime's signal() covers these four. + std::signal(SIGSEGV, crash_handler); std::signal(SIGABRT, crash_handler); std::signal(SIGFPE, crash_handler); std::signal(SIGILL, crash_handler); +#else struct sigaction sa{}; sa.sa_handler = crash_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGSEGV, &sa, nullptr); sigaction(SIGABRT, &sa, nullptr); sigaction(SIGFPE, &sa, nullptr); sigaction(SIGILL, &sa, nullptr); #ifdef SIGBUS sigaction(SIGBUS, &sa, nullptr); #endif +#endif } void uninstall_signal_handlers() { +#ifdef _WIN32 + std::signal(SIGSEGV, SIG_DFL); std::signal(SIGABRT, SIG_DFL); std::signal(SIGFPE, SIG_DFL); std::signal(SIGILL, SIG_DFL); +#else struct sigaction sa{}; sa.sa_handler = SIG_DFL; sigaction(SIGSEGV, &sa, nullptr); sigaction(SIGABRT, &sa, nullptr); sigaction(SIGFPE, &sa, nullptr); sigaction(SIGILL, &sa, nullptr); #ifdef SIGBUS sigaction(SIGBUS, &sa, nullptr); +#endif #endif g_crash_callback = nullptr; }