Warning, /acts/Tests/UnitTests/CMakeLists.txt is written in an unsupported language. File is not indexed.
0001 # add a unittest executable w/ default dependencies and register it.
0002
0003 # the common libraries which are linked to every unittest can be
0004 # extended by setting the `unittest_extra_libraries` variables before
0005 # calling the macro.
0006
0007 add_custom_target(unit_tests)
0008
0009 macro(add_unittest _name _source)
0010 # automatically prefix the target name
0011 set(_target "ActsUnitTest${_name}")
0012 add_executable(${_target} ${_source})
0013 # define required BOOST_TEST_... macros here to ensure consistent names
0014 target_compile_definitions(${_target} PRIVATE "-DBOOST_TEST_DYN_LINK")
0015 set_source_files_properties(
0016 ${_source}
0017 PROPERTIES COMPILE_DEFINITIONS "BOOST_TEST_MODULE=${_target}"
0018 )
0019 target_include_directories(${_target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
0020 target_link_libraries(
0021 ${_target}
0022 PRIVATE
0023 ActsCore
0024 ActsTestsCommonHelpers
0025 Boost::unit_test_framework
0026 ${unittest_extra_libraries}
0027 )
0028 # register as unittest executable
0029 add_test(NAME ${_name} COMMAND ${_target})
0030 add_dependencies(unit_tests ${_target})
0031 endmacro()
0032
0033 # This function adds a non compile test. To this end it
0034 # - Adds a target to process the file at `src`, and converts begin/end macros
0035 # to `#if defined` in an extra file
0036 # - Adds an executable target for that source file, excludes it from the default build
0037 # Set a preprocessor define to enable ONE critical section.
0038 # - Adds a test job to ctest which invokes CMake to build this executable target.
0039 # The test is set to fail if the build succeeds, i.e. testing if something doesn't compile
0040 # - Adds a closure test where it's supposed to actually compile if all of the
0041 # critical sections are removed
0042 function(add_non_compile_test name src)
0043 # Don't add anything if the corresponding flag is not set
0044 if(NOT ACTS_BUILD_NONCOMPILE_TESTS)
0045 return()
0046 endif()
0047
0048 # Figure out where to put the output file
0049 cmake_path(ABSOLUTE_PATH src)
0050 get_filename_component(_filename ${src} NAME)
0051 set(_processed_source "${CMAKE_CURRENT_BINARY_DIR}/${_filename}")
0052
0053 # Add a build step to generate the source file by invoking a CMake script
0054 add_custom_command(
0055 OUTPUT ${_processed_source}
0056 DEPENDS ${src}
0057 COMMAND
0058 "${CMAKE_COMMAND}" -DINPUT_FILE=${src}
0059 -DOUTPUT_FILE=${_processed_source} -P
0060 ${CMAKE_SOURCE_DIR}/cmake/ActsGenerateNonCompileTest.cmake
0061 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
0062 )
0063 add_custom_target("${name}_generated_source" DEPENDS ${_processed_source})
0064
0065 # Create the executable target, add the generated source code as a
0066 # dependencies, so that it's generated when required.
0067 set(test "ActsNonCompileTest${name}Closure")
0068 set(target "${test}_Executable")
0069 add_executable(${target} ${_processed_source})
0070 target_link_libraries(${target} PUBLIC ActsCore ActsTestsCommonHelpers)
0071 add_dependencies(${target} "${name}_generated_source")
0072
0073 # Don't build this target by default
0074 set_target_properties(
0075 ${target}
0076 PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON
0077 )
0078
0079 # Add the test that calls into CMake to build the target. This one we expect to succeed
0080 add_test(
0081 NAME ${test}
0082 COMMAND
0083 ${CMAKE_COMMAND} --build . --target ${target} --config
0084 $<CONFIGURATION>
0085 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
0086 )
0087
0088 # Loop over critical section markers and add one pair of executable targets and
0089 # and test jobs. The test jobs are flipped, so success is failure.
0090 file(READ ${src} content)
0091 string(
0092 REGEX MATCHALL
0093 "ACTS_DOES_NOT_COMPILE_BEGIN\\(([A-Za-z0-9]+)\\)"
0094 matches
0095 ${content}
0096 )
0097 foreach(match ${matches})
0098 string(
0099 REGEX REPLACE
0100 "ACTS_DOES_NOT_COMPILE_BEGIN\\(([A-Za-z0-9]+)\\)"
0101 "\\1"
0102 match
0103 ${match}
0104 )
0105
0106 set(test "ActsNonCompileTest${name}${match}")
0107 set(target "${test}_Executable")
0108 add_executable(${target} ${_processed_source})
0109 target_link_libraries(${target} PUBLIC ActsCore ActsTestsCommonHelpers)
0110 target_compile_definitions(${target} PRIVATE "-D${match}")
0111 add_dependencies(${target} "${name}_generated_source")
0112
0113 set_target_properties(
0114 ${target}
0115 PROPERTIES EXCLUDE_FROM_ALL ON EXCLUDE_FROM_DEFAULT_BUILD ON
0116 )
0117
0118 add_test(
0119 NAME ${test}
0120 COMMAND
0121 ${CMAKE_COMMAND} --build . --target ${target} --config
0122 $<CONFIGURATION>
0123 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
0124 )
0125 set_tests_properties(${test} PROPERTIES WILL_FAIL ON)
0126 endforeach()
0127 endfunction()
0128
0129 add_subdirectory(Core)
0130 add_subdirectory_if(Examples ACTS_BUILD_EXAMPLES AND ACTS_BUILD_EXAMPLES_UNITTESTS)
0131 add_subdirectory_if(Benchmarks ACTS_BUILD_BENCHMARKS)
0132 add_subdirectory_if(Fatras ACTS_BUILD_FATRAS)
0133 add_subdirectory(Plugins)
0134 add_subdirectory_if(Alignment ACTS_BUILD_ALIGNMENT)