I am using configure_file
to generate a source file containing version information for my project:
CMakeLists.txt
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(dummy VERSION 0.1 LANGUAGES C)
configure_file(version.c.in version.c)
set_source_files_properties(version.c PROPERTIES GENERATED TRUE)
add_executable(dummy-version ${CMAKE_CURRENT_BINARY_DIR}/version.c)
version.c.in
#include <stdio.h>
const char *dummy_version(void) {
return "@dummy_VERSION@";
}
int main(int argc, char **argv) {
printf("%s\n", dummy_version());
return 0;
}
If I do the following using the default Makefile generator:
$ cd build-make
$ cmake ..
$ make clean
$ make
everything builds fine, but if I do the same with Ninja:
$ cd build-ninja
$ cmake -G Ninja ..
$ ninja clean
$ ninja
I get a compiler error because the file version.c
is missing.
I have seen this issue, that seems to point to the fact that the GENERATED
property is not needed, but I was wondering why the file is kept when using make clean
and deleted when using ninja clean
. Is there a reason behind this difference?