Last active
August 24, 2019 11:11
-
-
Save FerryT/7eb71f8c7c26159a904cf7fd99123f63 to your computer and use it in GitHub Desktop.
CMake tests that are build only when tests are run
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
cmake_minimum_required(VERSION 3.12 FATAL_ERROR) | |
project(MyProject) | |
add_executable(main src/main.cpp) | |
enable_testing() | |
# add a build target for the test executable | |
add_executable(testing src/testing.cpp) | |
# configure the target so it does not compile by default | |
set_target_properties(testing PROPERTIES EXCLUDE_FROM_ALL TRUE) | |
# add a test that actually compiles the text executable | |
# if this test fails, the test executable could not be compiled | |
# explicitly compile the target (`make testing` in this case) to see what failed | |
add_test(NAME TestExecutable COMMAND "${CMAKE_COMMAND}" | |
--build "${CMAKE_BINARY_DIR}" | |
--config "$<CONFIG>" | |
--target "testing" | |
) | |
# add some test | |
add_test(Test1 testing) | |
# making sure it depends on the text executable, so it will be build | |
# before the test is run. | |
set_tests_properties(Test1 PROPERTIES DEPENDS TestExecutable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment