Can ctest use relative path to run test? There is no problem to run ctest after cmake. But if I copy the whole folder to somewhere else, ctest cannot run properly. It is using absolute path and cannot find the binary.
Asked
Active
Viewed 436 times
2 Answers
0
I am currently facing the same issue. This answer is a work in progess answer:
- when building your tests, when you call
add_test
, make sure that you use relative path, with an ugly trick like [1] - after the build, you must update DartConfiguration.tcl, like in [2]
[1]
get_target_property(_OUTPUT_DIRECTORY ${__TEST_EXE}
RUNTIME_OUTPUT_DIRECTORY)
if(${_OUTPUT_DIRECTORY} STREQUAL "_OUTPUT_DIRECTORY-NOTFOUND")
set(_OUTPUT_DIRECTORY "./")
endif()
set(__ABS_TEST_EXE
${_OUTPUT_DIRECTORY}/$<TARGET_FILE_NAME:${__TEST_EXE}>)
string(REPLACE ${CMAKE_CURRENT_BINARY_DIR}/ "./" __TEST_EXE_PATH
${__ABS_TEST_EXE})
add_test(NAME ${_TEST_NAME} COMMAND ${__TEST_EXE_PATH})
[2]
- BuildDirectory: /absolute/path/to/you/build
+ BuildDirectory: ./

Jérôme
- 2,640
- 3
- 26
- 39