Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-compilation/Testing/CMakeLists.txt
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35 lines (29 sloc)
1.37 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tell cmake where to put the executables that it creates | |
# also creates the directory if needed | |
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin) | |
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin ) | |
# tell cmake where to find the catch2 library | |
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch) | |
add_library(Catch INTERFACE) | |
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) | |
# tell cmake where to find the captureio library | |
set(CAPIO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/captureio) | |
add_library(Capio INTERFACE) | |
target_include_directories(Capio INTERFACE ${CAPIO_INCLUDE_DIR}) | |
# create the tests | |
# test files start with "test_" and end in ".cpp" | |
# create a seperate executable for each test file | |
enable_testing() | |
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/test_*.cpp") | |
foreach(filename ${files}) | |
# if test file is "test_thingy.cpp" then created test will be called "test_thingy" | |
get_filename_component(THIS_TEST ${filename} NAME_WE) | |
set(TEST_RUNNER ${THIS_TEST}) | |
# create the executable, include the catch2 library | |
add_executable(${TEST_RUNNER} ${filename} ${HEADERS}) | |
target_link_libraries(${TEST_RUNNER} Catch) | |
target_link_libraries(${TEST_RUNNER} Capio) | |
# say that this executable is a test so that ctest will run it | |
add_test(NAME ${THIS_TEST} | |
COMMAND ${TEST_RUNNER} ) | |
endforeach() | |