Makefile generators use wrong relative path for build subdirectories under the source directory but not under the main build directory
cmake version 3.20.0-rc1
When setting FETCHCONTENT_SOURCE_DIR_<ucName>
using the generators "NMake Makefile" and "Unix Makefile", the generated CMakeFiles/Makefile2
file mixes up relative path names and absolute path names when referring to the target associated with the set FETCHCONTENT_SOURCE_DIR_<ucName>
.
This does not happen when using the "Visual Studio 16 2019" generator and building the resulting solution.
See my main project CMakeLists.txt (rtek_CMakeLists.txt), the dependency CMakeLists.txt (sdslib_CMakeLists.txt) and the generated Makefile2 attached.
Error:
make[1]: *** No rule to make target '../_deps/sdslib-build/CMakeFiles/sdslib.dir/all', needed by 'CMakeFiles/rtek.dir/all'. Stop.
make: *** [Makefile:91: all] Error 2
Relevant part of my file structure:
repos/
rtek/
_deps/
build/
CMakeFiles/
Makefile2
CMakeLists.txt
sdslib-cpp/
CMakeLists.txt
Configure & build steps:
cd repos/rtek
cmake -S. -B./build -G"NMake Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DFETCHCONTENT_SOURCE_DIR_SDSLIB="../sdslib-cpp"
cmake --build build
- I tried using an absolute path with FETCHCONTENT_SOURCE_DIR_SDSLIB, but that had no effect.
Relevant parts of Makefile2
:
# refers to sdslib.dir\all by relative path name
CMakeFiles\rtek.dir\all: ..\_deps\sdslib-build\CMakeFiles\sdslib.dir\all
# ...
# sdslib.dir\all defined by full path name
C:\Users\stewa\source\repos\rtek\_deps\sdslib-build\CMakeFiles\sdslib.dir\all:
# ...
# sdslib-build/all refers to sdslib.dir/all as absolute path
C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/all: C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/CMakeFiles/sdslib.dir/all
Doing the following find-and-replace in Makefile2
fixes the generated build:
-
C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/CMakeFiles/sdslib.dir/all
->../_deps/sdslib-build/CMakeFiles/sdslib.dir/all
-
C:/Users/stewa/source/repos/rtek/_deps/sdslib-build/all
->../_deps/sdslib-build/all