Win11 (x64-86)
cygiwn v3.7.0
cmake v4.2.1Mastering Modern CMake pg. 21
cmake --build build only works after a make.
project/CMakeLists.txt
cmake_minimum_Required(VERSION 3.15)
project(HelloWorld CXX)
add_subdirectory(src)
project/src/CMakeLists.txt
add_executable(HelloWorld main.cpp)
target_include_directories(HelloWorld PRIVATE ../include)
Directory structure
project/
src/main.cpp
include/
Command Execution Sequience
cd project
cmake -B build
cmake --build build # fails
cd build
make
cd ..
cmake --build build # succeeds
Error Message:
gmake[2]: *** No rule to make target ‘/d/home/skidmarks/Projects/Test/cmake/Modern_CMake/src/main.cpp’, needed by ‘src/CMakeFiles/HelloWorld.dir/main.cpp.o’. Stop.
gmake[1]: *** [CMakeFiles/Makefile2:106: src/CMakeFiles/HelloWorld.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2
The order of commands (cmake --build build and make) is immaterial. cmake always fails until make is executed and always succeeds afterwards. Is there any reason for this?