Files
Structive/core/main.cmake
T
2026-08-08 21:21:23 +08:00

78 lines
5.0 KiB
CMake

add_library(structive_property_core INTERFACE)
add_library(structive::property_core ALIAS structive_property_core)
set_target_properties(structive_property_core PROPERTIES EXPORT_NAME property_core)
target_include_directories(structive_property_core INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>" "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_compile_features(structive_property_core INTERFACE cxx_std_20)
if(STRUCTIVE_BUILD_EXAMPLES)
add_executable(structive_property_core_example "${CMAKE_CURRENT_LIST_DIR}/example/main.cpp")
target_link_libraries(structive_property_core_example PRIVATE structive::property_core)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(structive_property_core_example PRIVATE -Wall -Wextra -Wpedantic)
endif()
endif()
if(STRUCTIVE_BUILD_TESTS)
find_package(Threads REQUIRED)
add_executable(structive_property_core_test "${CMAKE_CURRENT_LIST_DIR}/tests/property_core_test.cpp")
add_executable(structive_property_runtime_api_test "${CMAKE_CURRENT_LIST_DIR}/tests/runtime_api_test.cpp")
add_executable(structive_property_synchronization_test "${CMAKE_CURRENT_LIST_DIR}/tests/synchronization_test.cpp")
target_link_libraries(structive_property_core_test PRIVATE structive::property_core Threads::Threads)
target_link_libraries(structive_property_runtime_api_test PRIVATE structive::property_core Threads::Threads)
target_link_libraries(structive_property_synchronization_test PRIVATE structive::property_core Threads::Threads)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(structive_property_core_test PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(structive_property_runtime_api_test PRIVATE -Wall -Wextra -Wpedantic)
target_compile_options(structive_property_synchronization_test PRIVATE -Wall -Wextra -Wpedantic)
endif()
add_test(NAME structive_property_core_test COMMAND structive_property_core_test)
add_test(NAME structive_property_runtime_api_test COMMAND structive_property_runtime_api_test)
add_test(NAME structive_property_synchronization_test COMMAND structive_property_synchronization_test)
set_tests_properties(structive_property_core_test structive_property_runtime_api_test structive_property_synchronization_test PROPERTIES LABELS "unit;core")
function(structive_add_core_header_test header)
string(REPLACE "/" "_" target_suffix "${header}")
string(REPLACE "." "_" target_suffix "${target_suffix}")
set(target "structive_header_${target_suffix}")
set(source "${CMAKE_CURRENT_BINARY_DIR}/structive_header_tests/${target}.cpp")
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/structive_header_tests")
file(WRITE "${source}" "#include <${header}>\nint main() {\n return 0;\n}\n")
add_executable("${target}" "${source}")
target_link_libraries("${target}" PRIVATE structive::property_core)
add_test(NAME "${target}" COMMAND "${target}")
set_tests_properties("${target}" PROPERTIES LABELS "header;core")
endfunction()
set(structive_core_headers
structive/property/accessor.hpp
structive/property/attributes.hpp
structive/property/descriptor.hpp
structive/property/fixed_string.hpp
structive/property/meta.hpp
structive/property/property.hpp
structive/property/property_object.hpp
structive/property/schema.hpp
structive/property/synchronization.hpp
structive/property/type_descriptor.hpp
structive/property/validation.hpp
)
foreach(header IN LISTS structive_core_headers)
structive_add_core_header_test("${header}")
endforeach()
include(CheckCXXSourceCompiles)
function(structive_expect_compile_failure name source)
file(READ "${source}" source_text)
set(CMAKE_REQUIRED_INCLUDES "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(result_variable "STRUCTIVE_COMPILE_FAIL_${name}")
unset("${result_variable}" CACHE)
check_cxx_source_compiles("${source_text}" "${result_variable}")
if(${result_variable})
message(FATAL_ERROR "Structive compile-fail contract unexpectedly compiled: ${name}")
endif()
endfunction()
structive_expect_compile_failure(duplicate_key "${CMAKE_CURRENT_LIST_DIR}/tests/compile_fail/duplicate_key.cpp")
structive_expect_compile_failure(duplicate_storage "${CMAKE_CURRENT_LIST_DIR}/tests/compile_fail/duplicate_storage.cpp")
structive_expect_compile_failure(missing_key "${CMAKE_CURRENT_LIST_DIR}/tests/compile_fail/missing_key.cpp")
structive_expect_compile_failure(capability_mismatch "${CMAKE_CURRENT_LIST_DIR}/tests/compile_fail/capability_mismatch.cpp")
structive_expect_compile_failure(incompatible_constraint "${CMAKE_CURRENT_LIST_DIR}/tests/compile_fail/incompatible_constraint.cpp")
structive_expect_compile_failure(foreign_sync_member "${CMAKE_CURRENT_LIST_DIR}/tests/compile_fail/foreign_sync_member.cpp")
endif()