Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,802
    • Issues 3,802
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 13
    • Merge requests 13
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #23071

Closed
Open
Created Jan 03, 2022 by Benjamin de la Fuente@benjamin1

PCH combined with UNITY_BUILD generates error C1010 when compiling single file with Ctrl+F7 in Visual Studio since CMake 3.20

Since CMake 3.20, if you try to compile a single .c or .cpp file in Visual Studio with Ctrl+F7 in a target configured to use PCH and UNITY_BUILD both enabled, then you will see the next error:

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "[PATH_TO_PCH]/cmake_pch.hxx"' to your source?

In previous versions (since 3.17 to 3.19) this was working as expected, but after 3.20 some precompiled settings has been moved from file configurations to project configuration, making the setting for precompiled headers common for all source files in the project (both original source files and auto-generated unity build files). Prior to 3.20 this precompiled settings only affect to unity build auto-generated files.

When you don't use UNITY_BUILD, everything works because the force include rule applies to all the original files, but when you enable UNITY_BUILD, the force include for PCH only applies to auto-generated unity build files. One possible solution would be to apply the same force include rules to all files in the project. In fact this is one workaround I've tried for this problem, and seems to work, at least for me:

if(MSVC)
    target_compile_options(${projectName} PRIVATE /FI$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${projectName}.dir/$<CONFIG>/cmake_pch.h>)
    target_compile_options(${projectName} PRIVATE /FI$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${projectName}.dir/$<CONFIG>/cmake_pch.hxx>)
endif()
Edited Jan 04, 2022 by Benjamin de la Fuente
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking