Update:
As @mathstuf has pointed out in his own answer, as of version 2.8.12 CMake supports generator expressions within the WORKING_DIRECTORY
argument of add_test
. This makes the rest of my answer only applicable to CMake v2.8.11 and below.
As far as I know, it's not really possible to pass a "$" through ADD_TEST
without it ending up escaped in CTestTestfile.cmake
.
Really the "CMake" way to handle this situation is probably to pass the dependent exes to the test exe as a command line parameter, which would involve changing the test code. If the dependent executables are all CMake targets, they can be referenced in the ADD_TEST
command using "$<TARGET_FILE:tgt>
" where tgt
is the name of the CMake target.
There is however a big, dirty hack you could use to get round this. Replace your ADD_TEST
command with:
ADD_TEST(NAME test WORKING_DIRECTORY "@WORKING_DIR@" COMMAND test ${TEST_ARGS})
FILE(WRITE ${CMAKE_BINARY_DIR}/CTestCustom.cmake
"SET(WORKING_DIR \"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/\\\${CTEST_CONFIGURATION_TYPE}\")\n")
FILE(APPEND ${CMAKE_BINARY_DIR}/CTestCustom.cmake
"CONFIGURE_FILE(${CMAKE_BINARY_DIR}/CTestTestfile.cmake ${CMAKE_BINARY_DIR}/CTestTestfile.cmake @ONLY)\n")
This is (ab)using CTest's behaviour by creating a CTestCustom.cmake
file which is invoked before the CTestTestfile.cmake
. After running CMake, CTestTestfile.cmake
has the line
SET_TESTS_PROPERTIES(test PROPERTIES WORKING_DIRECTORY "@WORKING_DIR@")
By running CTest and invoking CTestCustom.cmake
, the "@WORKING_DIR@"
is replaced with the correct value.
It really is a hack; messing with auto-generated CMake files is asking for trouble, but it could do until you get time to refactor your tests or CMake becomes better able to support a per-configuration WORKING_DIRECTORY
.