Makefiles generator. CMAKE_DEPENDS_USE_COMPILER=FALSE conflicts with DEPFILE in add_custom_command()
CMake v3.21.
Seems like for custom commands with DEPFILE
cmake generates compiler_depend.ts
at configuration phase. With CMAKE_DEPENDS_USE_COMPILER=FALSE
the files are not created and build fails with:
make[2]: *** No rule to make target `CMakeFiles/.../compiler_depend.ts', needed by ...
Interestingly default value for this variable is false, according to documentation. NB This option is unconditionally set by CLion (reported).
How to reproduce. CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(gen_test)
set(SRC_FILE "1.cpp")
add_custom_command(
COMMAND /bin/bash ${CMAKE_CURRENT_SOURCE_DIR}/gen_src.sh ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/1.txt
OUTPUT ${SRC_FILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gen_src.sh
DEPFILE ${SRC_FILE}.d
)
add_executable(test ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE})
gen_src.sh:
#!/bin/bash
printf '#include <stdio.h>\nint main(){ printf("Hello world!!!\\n"); }\n' > $1
printf "$1: $2\n" > $1.d
1.txt is just an empty file to refer from dependency file.
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_DEPENDS_USE_COMPILER=FALSE
...
$ make
make[2]: *** No rule to make target `CMakeFiles/test.dir/compiler_depend.ts', needed by `1.cpp'. Stop.
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2