Skip to content
GitLab
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 4,107
    • Issues 4,107
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 19
    • Merge requests 19
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and 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
  • CMakeCMake
  • CMakeCMake
  • Issues
  • #22384
Closed
Open
Issue created Jul 05, 2021 by refnum@refnum

Xcode generator does not support multi-language precompiled headers

Attached is a small project containing .c, .cpp, .m, and .mm source files where target_precompile_headers() is used to precompile a single prefix.h.

The generated Xcode project contains:

    GCC_PRECOMPILE_PREFIX_HEADER = YES
    GCC_PREFIX_HEADER            = .../CMakeFiles/Test.dir/Debug/cmake_pch.hxx

The GCC_PREFIX_HEADER header is compiled by Xcode once for each language in the project:

    clang -x c-header             -target ...
    clang -x c++-header           -target ...
    clang -x objective-c-header   -target ...
    clang -x objective-c++-header -target ...

However the cmake_pch.hxx header only includes its contents when __cplusplus is defined:

    #ifndef CMAKE_SKIP_PRECOMPILE_HEADERS
    #ifdef __cplusplus
    #include "/Users/test/Desktop/xcode_pch/prefix.h"
    #endif // __cplusplus
    #endif // CMAKE_SKIP_PRECOMPILE_HEADERS

This means that prefix.h is only visible to C++ and Objective-C++ source.

As Xcode's GCC_PREFIX_HEADER setting only takes a single path the Xcode generator should generate a single language-agnostic header:

    GCC_PRECOMPILE_PREFIX_HEADER = YES
    GCC_PREFIX_HEADER            = .../CMakeFiles/Test.dir/Debug/cmake_pch.h
 
 
    #ifndef CMAKE_SKIP_PRECOMPILE_HEADERS
    #include "/Users/test/Desktop/xcode_pch/prefix.h"
    #endif // CMAKE_SKIP_PRECOMPILE_HEADERS

Xcode will then generate per-language builds of this precompiled header itself, passing the correct build to each source file as required.

xcode_pch.tar.gz

Edited Jul 05, 2021 by refnum
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking