cmake_minimum_required(VERSION 4.0.0) project(Void VERSION 1.2.3 LANGUAGES C CXX) if(PROJECT_IS_TOP_LEVEL) option(BUILD_SHARED_LIBS "Build Void modules as shared libraries" ON) elseif(NOT DEFINED BUILD_SHARED_LIBS) # Keep Void's shared default local when embedded so a dependency does not # silently change the linkage policy of its parent project. set(BUILD_SHARED_LIBS ON) endif() option(VOID_ENABLE_TESTING "Build the test suite" ON) option(VOID_ENABLE_BENCHMARKS "Build reproducible benchmark baselines" OFF) option(VOID_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF) option(VOID_ENABLE_ASAN "Enable AddressSanitizer (Clang/GCC)" OFF) option(VOID_ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (Clang/GCC)" OFF) option(VOID_ENABLE_TSAN "Enable ThreadSanitizer (Clang/GCC)" OFF) option(VOID_ENABLE_COVERAGE "Enable code coverage instrumentation" OFF) set(CMAKE_CXX_STANDARD 26) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_MODULE_MAP_FORMAT "gcc") set(CXX_SCAN_FOR_MODULES OFF) # , , etc. if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16) add_compile_options($<$:-freflection>) endif() include(GNUInstallDirs) include(CMakePackageConfigHelpers) set(EXPORT_SET_NAME ${PROJECT_NAME}Targets) include(cmake/Capabilities.cmake) void_probe_capabilities() 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 "^(INTERNAL_DEPS|EXTERNAL_DEPS|OPTIONAL_DEPS|DEPS_WIN32|DEPS_UNIX|OPTIONS_WIN32|OPTIONS_UNIX|EXTRA_HEADERS|EXCLUDE_HEADERS)$") 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) else() void_add_module(${module_path}) endif() endif() endforeach() void_finalize_modules() void_report_capabilities() if(VOID_ENABLE_TESTING) enable_testing() add_subdirectory(tests) endif() if(VOID_ENABLE_BENCHMARKS) add_subdirectory(benchmarks) endif() get_property(ALL_DISCOVERED_MODULES GLOBAL PROPERTY VOID_MODULES) get_property(ALL_MODULE_DEPENDENCY_RECORDS GLOBAL PROPERTY VOID_MODULE_DEPENDENCY_RECORDS) set(VOID_MODULES_LIST "${ALL_DISCOVERED_MODULES}") set(VOID_MODULE_DEPENDENCY_RECORDS "${ALL_MODULE_DEPENDENCY_RECORDS}") if(WIN32 AND NOT CYGWIN) set(VOID_BOOST_STACKTRACE_COMPONENT stacktrace_windbg) else() set(VOID_BOOST_STACKTRACE_COMPONENT stacktrace_addr2line) endif() write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/VoidConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) # Support headers shared by several modules (e.g. Void/Detail/Enum.hpp, used by # Core, Log, Configuration and Data). They belong to no module's FILE_SET, so # they are installed here; every module's install include dir covers them. install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/Void/Detail" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/Void") install(EXPORT ${EXPORT_SET_NAME} NAMESPACE ${PROJECT_NAME}:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/VoidTesting.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/VoidTestScanner.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" )