$ cat CMakeLists.txt cmake_minimum_required(VERSION 3.10) project(configure_file) set(HAVE_JPEG 0) set(HAVE_PNG 0) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_executable(hello hello.c) $ cat config.h.in /* This is a comment: * Don't do this: #cmakedefine HAVE_JPEG 1 */ #cmakedefine HAVE_PNG 1 $ cat hello.c #include #include "config.h" int main (int argc, char **argv) { printf ("Hello, World !\n"); return 0; } $ cmake --version cmake version 3.20.5 $ cd build $ cmake .. -- The C compiler identification is GNU 9.3.0 -- The CXX compiler identification is GNU 9.3.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /git/testprogramme/configure_file/build $ make [ 50%] Building C object CMakeFiles/hello.dir/hello.c.o In file included from /git/testprogramme/configure_file/hello.c:2: /git/testprogramme/configure_file/build/config.h:3:2: error: expected identifier or ‘(’ before ‘/’ token 3 | */ | ^ make[2]: *** [CMakeFiles/hello.dir/build.make:76: CMakeFiles/hello.dir/hello.c.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/hello.dir/all] Error 2 make: *** [Makefile:91: all] Error 2 $ cat config.h /* This is a comment: /* #undef HAVE_JPEG */ */ /* #undef HAVE_PNG */