I have the following problem: I enabled precompiled headers for my CMake project using target_precompile_headers(${APPLICATION_NAME} PRIVATE include/precompiled/pch.h) . This worked, however only for a freshly generated project. If I want to add a new source file to my project, after generation, it will throw this compiletime error: error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "path/to/cmake_pch.hxx"' to your source?. The only solution right now is, to completely regenerate the project after every new source file I add. This can't be the solution, right? Does anyone know what could be the fix?
Using Visual Studio 17.14.7
This is the CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(artisDX)
set(CMAKE_CXX_STANDARD 20)
message(STATUS "Configuring sources...")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(APPLICATION_NAME "artisDX")
file(GLOB_RECURSE ARTISDX_SOURCES "src/*.cpp")
file(GLOB_RECURSE ARTISDX_HEADERS "include/*.h")
add_executable(${APPLICATION_NAME} ${ARTISDX_SOURCES} ${ARTISDX_HEADERS})
target_precompile_headers(${APPLICATION_NAME} PRIVATE include/precompiled/pch.h)
...
GLOB_RECURSEand you will be happy. Cmake doesn't watch for new files in random directories. Otherwise you have to reconfigure and rebuild the projects.file(GLOB_RECURSE)isn't aware about your new file. See documentation for this command and that question.