[CMake] add_custom_command on test input files
Olaf Peter
ope-devel at gmx.de
Fri Apr 21 13:29:37 EDT 2017
Hello,
for my project I have a sub dir with test case which feeds the tests
'*.input' and allows to check to output '*.expected'. For documentation
purpose, I have a python script which generates a TestMatrix.rst file.
Using CMake I have:
dir structure:
$root/{src,include,utils,test}
test/CMakeLists.txt
project(test LANGUAGES CXX)
...
set(TEST_MATRIX_GENERATOR
${CMAKE_CURRENT_SOURCE_DIR}/../utils/gen_test_matrix.py)
set(TEST_MATRIX_GENERATOR_TARGET
${CMAKE_CURRENT_SOURCE_DIR}/test_matrix.rst)
file(GLOB_RECURSE TEST_CASE_FILES
LIST_DIRECTORIES true
"${CMAKE_CURRENT_SOURCE_DIR}/test_case/" "*.expected"
)
add_custom_command(
TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${TEST_MATRIX_GENERATOR} ${CMAKE_CURRENT_SOURCE_DIR} >
${TEST_MATRIX_GENERATOR_TARGET}
DEPENDS ${TEST_MATRIX_GENERATOR} ${TEST_CASE_FILES}
BYPRODUCT ${TEST_MATRIX_GENERATOR_TARGET}
COMMENT "Generate TestCase Matrix (RST)"
)
set_source_files_properties(
${TEST_MATRIX_GENERATOR_TARGET}
PROPERTIES GENERATED TRUE
)
but I assume, this isn't clever since it doesn't depend on the test_case
dirs/files as I've seen so far. Changes in these file doesn't trigger
the generation process, removing the ${TEST_MATRIX_GENERATOR_TARGET}
doesn't recreate it. How to get it working/generating on each changes
(additions) of the files/dirs in test_case?
Thanks,
Olaf
More information about the CMake
mailing list