From a3e095c4374ea8c960d215c27af8ca5eea0fa00c Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Wed, 26 Jun 2024 13:13:19 +0200 Subject: [PATCH] #350: Guard tests and examples with corresponding option checks --- CMakeLists.txt | 24 ++++++++++++++---------- examples/CMakeLists.txt | 1 + tests/CMakeLists.txt | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e009ffb..ae6680c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,9 +11,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") add_compile_options(-fcolor-diagnostics) endif() -include (CTest) -enable_testing() - function(deprecated_option old_option new_option description default_value) option(${new_option} "${description}" ${default_value}) if(DEFINED ${old_option}) @@ -162,16 +159,23 @@ set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set(PROJECT_EXAMPLE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/examples) set(PROJECT_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) -include (CTest) -enable_testing() - add_subdirectory(src) -add_custom_target(magistrate_examples) -add_subdirectory(examples) +if (magistrate_tests_enabled + AND "${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}") + # CTest implies enable_testing() and defines the BUILD_TESTING option. + # The default of BUILD_TESTING is ON. + # Testing is only enabled if the actual project being built is VT. + include(CTest) -add_custom_target(magistrate_tests) -add_subdirectory(tests) + add_custom_target(magistrate_tests) + add_subdirectory(tests) +endif() + +if(magistrate_examples_enabled) + add_custom_target(magistrate_examples) + add_subdirectory(examples) +endif() configure_file( cmake/checkpointConfig.cmake.in diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9a09da46..80072500 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -30,6 +30,7 @@ if (magistrate_examples_enabled) ${EXAMPLE} ${PROJECT_EXAMPLE_DIR}/${EXAMPLE}.cc ) + add_dependencies(magistrate_examples ${EXAMPLE}) target_include_directories(${EXAMPLE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../src) add_test_for_example_magistrate( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0c53ef3a..107653ef 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -87,6 +87,7 @@ if (magistrate_tests_enabled) ${PROJECT_TEST_UNIT_DIR}/${TEST}.cc ) + add_dependencies(magistrate_tests ${TEST}) magistrate_link_target(${TEST} 0) add_test(