-1

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)

...
5
  • 1
    Don't use GLOB_RECURSE and you will be happy. Cmake doesn't watch for new files in random directories. Otherwise you have to reconfigure and rebuild the projects. Commented Jul 2 at 9:45
  • 1
    "If I want to add a new source file to my project, after generation ..." - then you should regenerate your project in any case. file(GLOB_RECURSE) isn't aware about your new file. See documentation for this command and that question. Commented Jul 2 at 9:54
  • Thank you for the answers - adding them explicitly now and it works as intended! Commented Jul 2 at 11:13
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a minimal reproducible example. Commented Jul 2 at 13:47
  • In general; don't use precompileled headers. They may speed up your compile times, but they cause so many other issues. Commented Jul 2 at 19:27

1 Answer 1

0

As commented above the problem was that GLOB_RECURSE doesn't scan for new files after the project was generated. I've switched to explicitly defining my sources and includes, which is an extra manual step for every sourcefile you add, however it comes with the added benefit of actually knowing whats included or not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.