c++visual-studiovisual-c++cmakepch

Unexpected end of file while looking for precompiled header


I've been trying to organize my code into sub-folders, and I've been careful to not do anything extra than that since my last commit. I am currently getting a bunch of C1010 errors saying:

unexpected end of file while looking for precompiled header. Did you forget to add #include "pch.h" to your source?

Each file does have the appropriate relative include path for the precompiled header file. If I attempt to "de-relativize" the precompiled header includes, then Intellisense starts throwing errors..

I suspect that my cmake code might be at fault here.. Specifically this section:...

if (MSVC)
    set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Minecraft)

    set_target_properties(Minecraft PROPERTIES COMPILE_FLAGS "/Yupch.h")
    set_source_files_properties("src/pch.cpp" PROPERTIES COMPILE_FLAGS "/Ycpch.h")

    target_compile_options(Minecraft PRIVATE "/W4" "/MP" "/std:c++17")
endif()

Solution

  • So replacing the following code...

    if (MSVC)
        set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Minecraft)
    
        set_target_properties(Minecraft PROPERTIES COMPILE_FLAGS "/Yupch.h")
        set_source_files_properties("src/pch.cpp" PROPERTIES COMPILE_FLAGS "/Ycpch.h")
    
        target_compile_options(Minecraft PRIVATE "/W4" "/MP" "/std:c++17")
    endif()
    

    with

    if (MSVC)
        set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Minecraft)
    
        target_precompile_headers(Minecraft PRIVATE "src/pch.h")
    
        target_compile_options(Minecraft PRIVATE "/W4" "/MP" "/std:c++17")
    endif()
    

    solved the issue!