151 lines
5.5 KiB
CMake
151 lines
5.5 KiB
CMake
cmake_minimum_required(VERSION 4.0)
|
|
|
|
foreach(required IN ITEMS VOID_BUILD_DIR VOID_TEST_SOURCE_DIR VOID_TEST_ROOT
|
|
VOID_CXX_COMPILER VOID_CTEST_COMMAND)
|
|
if(NOT DEFINED ${required} OR "${${required}}" STREQUAL "")
|
|
message(FATAL_ERROR "${required} is required")
|
|
endif()
|
|
endforeach()
|
|
|
|
file(REMOVE_RECURSE "${VOID_TEST_ROOT}")
|
|
set(install_prefix "${VOID_TEST_ROOT}/install")
|
|
set(relocated_prefix "${VOID_TEST_ROOT}/relocated-install")
|
|
|
|
set(_active_modules "")
|
|
if(DEFINED VOID_ACTIVE_MODULES AND NOT VOID_ACTIVE_MODULES STREQUAL "")
|
|
string(REPLACE "," ";" _active_modules "${VOID_ACTIVE_MODULES}")
|
|
endif()
|
|
|
|
function(has_modules out_var)
|
|
if(NOT _active_modules)
|
|
set(${out_var} TRUE PARENT_SCOPE)
|
|
return()
|
|
endif()
|
|
foreach(m IN LISTS ARGN)
|
|
if(NOT m IN_LIST _active_modules)
|
|
set(${out_var} FALSE PARENT_SCOPE)
|
|
return()
|
|
endif()
|
|
endforeach()
|
|
set(${out_var} TRUE PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
set(install_command "${CMAKE_COMMAND}" --install "${VOID_BUILD_DIR}"
|
|
--prefix "${install_prefix}")
|
|
if(DEFINED VOID_BUILD_CONFIG AND NOT VOID_BUILD_CONFIG STREQUAL "")
|
|
list(APPEND install_command --config "${VOID_BUILD_CONFIG}")
|
|
endif()
|
|
execute_process(COMMAND ${install_command} COMMAND_ERROR_IS_FATAL ANY)
|
|
|
|
set(_gen_args "")
|
|
if(DEFINED VOID_GENERATOR AND NOT VOID_GENERATOR STREQUAL "")
|
|
list(APPEND _gen_args -G "${VOID_GENERATOR}")
|
|
endif()
|
|
if(DEFINED VOID_MAKE_PROGRAM AND NOT VOID_MAKE_PROGRAM STREQUAL "")
|
|
list(APPEND _gen_args "-DCMAKE_MAKE_PROGRAM=${VOID_MAKE_PROGRAM}")
|
|
endif()
|
|
|
|
set(_consumers_run 0)
|
|
|
|
function(run_consumer name prefix_dir build_subdir)
|
|
set(source_dir "${VOID_TEST_SOURCE_DIR}/${name}")
|
|
set(build_dir "${VOID_TEST_ROOT}/${build_subdir}")
|
|
execute_process(
|
|
COMMAND "${CMAKE_COMMAND}" -S "${source_dir}" -B "${build_dir}"
|
|
${_gen_args}
|
|
"-DCMAKE_PREFIX_PATH=${prefix_dir}"
|
|
"-DCMAKE_CXX_COMPILER=${VOID_CXX_COMPILER}"
|
|
${ARGN}
|
|
COMMAND_ERROR_IS_FATAL ANY)
|
|
|
|
set(build_command "${CMAKE_COMMAND}" --build "${build_dir}")
|
|
set(test_command "${VOID_CTEST_COMMAND}" --test-dir "${build_dir}"
|
|
--output-on-failure)
|
|
if(DEFINED VOID_BUILD_CONFIG AND NOT VOID_BUILD_CONFIG STREQUAL "")
|
|
list(APPEND build_command --config "${VOID_BUILD_CONFIG}")
|
|
list(APPEND test_command -C "${VOID_BUILD_CONFIG}")
|
|
endif()
|
|
execute_process(COMMAND ${build_command} COMMAND_ERROR_IS_FATAL ANY)
|
|
execute_process(COMMAND ${test_command} COMMAND_ERROR_IS_FATAL ANY)
|
|
math(EXPR _next "${_consumers_run} + 1")
|
|
set(_consumers_run "${_next}" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
set(_no_external_deps
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_LibArchive=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_OpenSSL=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_Threads=TRUE)
|
|
|
|
# A header-only component must remain independently consumable even when every
|
|
# optional external package is explicitly unavailable.
|
|
has_modules(_has_core Core)
|
|
if(_has_core)
|
|
run_consumer(CoreOnly "${install_prefix}" "CoreOnly" ${_no_external_deps})
|
|
endif()
|
|
|
|
has_modules(_has_memory Memory Core)
|
|
if(_has_memory)
|
|
run_consumer(MemoryOnly "${install_prefix}" "MemoryOnly" ${_no_external_deps})
|
|
endif()
|
|
|
|
has_modules(_has_binary Binary Memory Functional Core)
|
|
if(_has_binary)
|
|
run_consumer(Binary "${install_prefix}" "Binary" ${_no_external_deps})
|
|
endif()
|
|
|
|
has_modules(_has_algorithms Algorithms Math Core)
|
|
if(_has_algorithms)
|
|
run_consumer(AlgorithmsOnly "${install_prefix}" "AlgorithmsOnly" ${_no_external_deps})
|
|
endif()
|
|
|
|
has_modules(_has_unicode Unicode Text Core)
|
|
if(_has_unicode)
|
|
run_consumer(UnicodeOnly "${install_prefix}" "UnicodeOnly" ${_no_external_deps})
|
|
endif()
|
|
|
|
# Foundation consumer with Core-formatting bridge and zero external packages.
|
|
has_modules(_has_foundation Math Text Time Functional Binary FunctionalCoreFormatting Memory Core)
|
|
if(_has_foundation)
|
|
run_consumer(Foundation "${install_prefix}" "Foundation" ${_no_external_deps})
|
|
endif()
|
|
|
|
# Exercise the transitive dependency closure for runtime modules while proving
|
|
# unrelated Sodium and SQLite dependencies are not loaded.
|
|
has_modules(_has_audited Archive Binary Crypto Plugin System Update)
|
|
if(_has_audited)
|
|
run_consumer(Audited "${install_prefix}" "Audited"
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
|
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
|
endif()
|
|
|
|
# Compiled shared modules keep their third-party implementation dependencies
|
|
# private, but every installed runtime library must remain linkable and
|
|
# executable from a clean consumer project.
|
|
has_modules(_has_external Net Security Sqlite Stacktrace)
|
|
if(_has_external)
|
|
run_consumer(External "${install_prefix}" "External")
|
|
endif()
|
|
|
|
if(_consumers_run EQUAL 0)
|
|
message(FATAL_ERROR
|
|
"VoidInstalledComponentConsumers ran 0 consumers for active modules '${VOID_ACTIVE_MODULES}'")
|
|
endif()
|
|
|
|
# Relocatability verification: rename the install tree so original install path
|
|
# no longer exists, then configure/build/run consumers against relocated path.
|
|
file(RENAME "${install_prefix}" "${relocated_prefix}")
|
|
|
|
if(_has_foundation)
|
|
run_consumer(Foundation "${relocated_prefix}" "RelocatedFoundation" ${_no_external_deps})
|
|
elseif(_has_binary)
|
|
run_consumer(Binary "${relocated_prefix}" "RelocatedBinary" ${_no_external_deps})
|
|
endif()
|
|
|
|
if(_has_external)
|
|
run_consumer(External "${relocated_prefix}" "RelocatedExternal")
|
|
endif()
|