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(
0015 ${_target}
0016 PRIVATE "-DBOOST_TEST_DYN_LINK")
0017 set_source_files_properties(${_source} PROPERTIES
0018 COMPILE_DEFINITIONS "BOOST_TEST_MODULE=${_target}")
0019 target_include_directories(
0020 ${_target}
0021 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
0022 target_link_libraries(
0023 ${_target}
0024 PRIVATE
0025 ActsCore
0026 ActsTestsCommonHelpers
0027 Boost::unit_test_framework
0028 ${unittest_extra_libraries})
0029 # register as unittest executable
0030 add_test(NAME ${_name} COMMAND ${_target})
0031 add_dependencies(unit_tests ${_target})
0032 endmacro()
0033
0034 # This function adds a non compile test. To this end it
0035 # - Adds a target to process the file at `src`, and converts begin/end macros
0036 # to `#if defined` in an extra file
0037 # - Adds an executable target for that source file, excludes it from the default build
0038 # Set a preprocessor define to enable ONE critical section.
0039 # - Adds a test job to ctest which invokes CMake to build this executable target.
0040 # The test is set to fail if the build succeeds, i.e. testing if something doesn't compile
0041 # - Adds a closure test where it's supposed to actually compile if all of the
0042 # critical sections are removed
0043 function(add_non_compile_test name src)
0044
0045 # Don't add anything if the corresponding flag is not set
0046 if(NOT ACTS_BUILD_NONCOMPILE_TESTS)
0047 return()
0048 endif()
0049
0050 # Figure out where to put the output file
0051 cmake_path(ABSOLUTE_PATH src)
0052 get_filename_component(_filename ${src} NAME)
0053 set(_processed_source "${CMAKE_CURRENT_BINARY_DIR}/${_filename}")
0054
0055 # Add a build step to generate the source file by invoking a CMake script
0056 add_custom_command(
0057 OUTPUT ${_processed_source}
0058 DEPENDS ${src}
0059 COMMAND "${CMAKE_COMMAND}"
0060 -DINPUT_FILE=${src}
0061 -DOUTPUT_FILE=${_processed_source}
0062 -P ${CMAKE_SOURCE_DIR}/cmake/ActsGenerateNonCompileTest.cmake
0063 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
0064 )
0065 add_custom_target(
0066 "${name}_generated_source"
0067 DEPENDS ${_processed_source}
0068 )
0069
0070 # Create the executable target, add the generated source code as a
0071 # dependencies, so that it's generated when required.
0072 set(test "ActsNonCompileTest${name}Closure")
0073 set(target "${test}_Executable")
0074 add_executable(${target} ${_processed_source})
0075 target_link_libraries(${target} PUBLIC ActsCore ActsTestsCommonHelpers)
0076 add_dependencies(${target} "${name}_generated_source")
0077
0078 # Don't build this target by default
0079 set_target_properties(${target} PROPERTIES
0080 EXCLUDE_FROM_ALL ON
0081 EXCLUDE_FROM_DEFAULT_BUILD ON)
0082
0083 # Add the test that calls into CMake to build the target. This one we expect to succeed
0084 add_test(NAME ${test}
0085 COMMAND ${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
0086 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
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(REGEX MATCHALL "ACTS_DOES_NOT_COMPILE_BEGIN\\(([A-Za-z0-9]+)\\)" matches ${content})
0092 foreach(match ${matches})
0093 string(REGEX REPLACE "ACTS_DOES_NOT_COMPILE_BEGIN\\(([A-Za-z0-9]+)\\)" "\\1" match ${match})
0094
0095 set(test "ActsNonCompileTest${name}${match}")
0096 set(target "${test}_Executable")
0097 add_executable(${target} ${_processed_source})
0098 target_link_libraries(${target} PUBLIC ActsCore ActsTestsCommonHelpers)
0099 target_compile_definitions(${target} PRIVATE "-D${match}")
0100 add_dependencies(${target} "${name}_generated_source")
0101
0102 set_target_properties(${target} PROPERTIES
0103 EXCLUDE_FROM_ALL ON
0104 EXCLUDE_FROM_DEFAULT_BUILD ON)
0105
0106 add_test(NAME ${test}
0107 COMMAND ${CMAKE_COMMAND} --build . --target ${target} --config $<CONFIGURATION>
0108 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
0109 set_tests_properties(${test} PROPERTIES WILL_FAIL ON)
0110 endforeach()
0111
0112 endfunction()
0113
0114 add_subdirectory(Core)
0115 add_subdirectory_if(Examples ACTS_BUILD_EXAMPLES)
0116 add_subdirectory_if(Benchmarks ACTS_BUILD_BENCHMARKS)
0117 add_subdirectory_if(Fatras ACTS_BUILD_FATRAS)
0118 add_subdirectory(Plugins)
0119 add_subdirectory_if(Alignment ACTS_BUILD_ALIGNMENT)