Output directory for CTestTestfile.cmake should be possible to control
TLDR
Please provide the possibility to:
- place the generated
CTestTestfile.cmake
file in a different directory (e.g. via test propertyCTEST_OUTPUT_DIRECTORY
) - add
SUBDIRS(${CTEST_OUTPUT_DIRECTORY})
to the originalCTestTestfile.cmake
location (to keepcmake --build $build_dir --target test
working the same)
Use case + problem description
My use case is a setup where we're using a separate output directory for produced executables and shared libraries from the rest of the build tree. (This is accomplished through the RUNTIME_OUTPUT_DIRECTORY
and LIBRARY_OUTPUT_DIRECTORY
target properties). The goal of this is to be able to copy just this directory tree from one machine to another to run several CI test sets on (i.e. without all the object and archive files).
Unfortunately this currently requires us to do several things:
- very carefully transform all paths used in
add_test
,REQUIRED_FILES
andATTACHED_FILES
to be relative to theRUNTIME_OUTPUT_DIRECTORY
- at build time move the generated
CTestTestfile.cmake
fromCMAKE_CURRENT_BINARY_DIR
to theRUNTIME_OUTPUT_DIRECTORY
- add a new
CTestTestfile.cmake
insideCMAKE_CURRENT_BINARY_DIR
containing justSUBDIRS(${RUNTIME_OUTPUT_DIRECTORY})
(to not breakcmake --build $build_dir --target test
, which is still used on developer machines) - maintain a list of all sub-directories (i.e. all instances of
RUNTIME_OUTPUT_DIRECTORY
) we've moved aCTestTestfile.cmake
to, to generate files containing just the rightSUBDIRS
commands to be able to use ctest on that tree of executables/libraries
(2) and (3) are very error prone when multiple calls to add_test
are present in the same CMakeLists.txt
(i.e. subdir of a project). The reason why this is error prone is because (3) may get in the way of (2), so we have to be very careful never to use our replacement SUBDIR(${RUNTIME_OUTPUT_DIRECTORY})
file, from (3), as input for (2). We've had race conditions here (where make -j8 fails sometimes, while make -j1 never did).
Having just the ability to specify an alternative output directory where the generated CTestTestfile.cmake
should be placed would already help a lot (e.g. by having a test property CTEST_OUTPUT_DIRECTORY
).
(1) is mostly difficult because we cannot use file(RELATIVE_PATH)
on generator expressions. So instead of $<TARGET_FILE:test-executable>
we're now using ${RUNTIME_OUTPUT_DIRECTORY}/$<TARGET_FILE_NAME:test-executable>
as the to-transform path with file(RELATIVE_PATH)
. That's mostly just unfortunate because of the repetition, including the conditionals on whether to set the RUNTIME_OUTPUT_DIRECTORY
target property at all. The only possible solution to that which I can see is to provide a new generator expression that does what file(RELATIVE_PATH)
does. This is less of a problem than (2)/(3) though.
(4) is mostly just a convenience thing where I'm hoping that maybe the logic, inside CMake itself, used to generate SUBDIRS()
calls could be reused.