CTest: add_subdirectory on Cygwin will cause a failure if the path has spaces
Given a build path with spaces and a Cygwin environment the following code will fail:
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(BadCygwin)
add_subdirectory(subdir)
enable_testing()
add_test(NAME main COMMAND main)
subdir/CMakeLists.txt
add_executable(main main.cpp)
subdir/main.cpp
int main()
{
return 0;
}
When ctest -V
is run, this CMake error will popup:
CMake Error at CTestTestfile.cmake:9 (subdirs):
subdirs Could not find include file: /cygdrive/c/Projects/test/path_followed_by_a
space/build/subdir/CTestTestfile.cmake
If we swap add_subdirectory(subdir)
with subdirs(subdir)
everything will work fine, because subdirs
command will not generate a subdir/CTestTestfile.cmake
and ctest will not try to load it, and fail because of the space. add_subdirectory
does create this file, with just comments inside of it, and ctest will fail because of the space in the path.