Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL 3.2.0 target_precompile_headers makes Xcode 16.2 fail compilation #12078

Open
tanis2000 opened this issue Jan 24, 2025 · 6 comments
Open
Assignees
Milestone

Comments

@tanis2000
Copy link

I am not entirely sure this is an issue in the CMake definition of SDL or a bug in CMake or a bug in Xcode.

The actual problem is that

target_precompile_headers(SDL3-shared PRIVATE "$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:${PROJECT_SOURCE_DIR}/src/SDL_internal.h>")
and
target_precompile_headers(SDL3-static PRIVATE "$<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:${PROJECT_SOURCE_DIR}/src/SDL_internal.h>")
are generating a project with the GCC_PRECOMPILE_PREFIX_HEADER set to YES and with a path to the .pch files.

Somehow, those .pch are considered bad by Xcode and it is right because the actual files being included are some .gch files instead.

When using ninja everything works fine. Maybe someone already experienced this and knows why this is happening?

For the time being, a work-around is to comment those two lines and Xcode compiles correctly.

Here is the full error:

CompileC /Users/tanis/Documents/binocle-c/build-ios/build/SDL3-static.build/Debug-iphoneos/Objects-normal/arm64/SDL_dynapi.o /Users/tanis/Documents/binocle-c/src/deps/sdl/src/dynapi/SDL_dynapi.c normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target 'SDL3-static' from project 'binocle')
    cd /Users/tanis/Documents/binocle-c
    
    Using response file: /Users/tanis/Documents/binocle-c/build-ios/build/SDL3-static.build/Debug-iphoneos/Objects-normal/arm64/e6072d4f65d7061329687fe24e3d63a7-common-args.resp
    
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -ivfsstatcache /Users/tanis/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/iphoneos18.2-22C146-d5b9239ec3bf5b3adbecdf21472871e3.sdkstatcache -fmessage-length\=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -fno-color-diagnostics -Wno-trigraphs -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-implicit-atomic-properties -Wno-objc-interface-ivars -Wno-arc-repeated-use-of-weak -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -Wno-implicit-fallthrough -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -Wno-sign-conversion -Wno-infinite-recursion -Wno-comma -Wno-block-capture-autoreleasing -Wno-strict-prototypes -Wno-semicolon-before-method-body -index-store-path /Users/tanis/Library/Developer/Xcode/DerivedData/binocle-ajdlzgsclnvvzchhdyxdfskbcwga/Index.noindex/DataStore -Wall -Wundef -Wfloat-conversion -fno-strict-aliasing -Wdocumentation -Wdocumentation-unknown-command -Wshadow -Wno-unused-local-typedefs -Wimplicit-fallthrough -fcolor-diagnostics -Wno-error\=deprecated-declarations @/Users/tanis/Documents/binocle-c/build-ios/build/SDL3-static.build/Debug-iphoneos/Objects-normal/arm64/e6072d4f65d7061329687fe24e3d63a7-common-args.resp -DCMAKE_SKIP_PRECOMPILE_HEADERS -include /Users/tanis/Documents/binocle-c/build-ios/build/SharedPrecompiledHeaders/SharedPrecompiledHeaders/16518934971014217302/cmake_pch.h -MMD -MT dependencies -MF /Users/tanis/Documents/binocle-c/build-ios/build/SDL3-static.build/Debug-iphoneos/Objects-normal/arm64/SDL_dynapi.d --serialize-diagnostics /Users/tanis/Documents/binocle-c/build-ios/build/SDL3-static.build/Debug-iphoneos/Objects-normal/arm64/SDL_dynapi.dia -c /Users/tanis/Documents/binocle-c/src/deps/sdl/src/dynapi/SDL_dynapi.c -o /Users/tanis/Documents/binocle-c/build-ios/build/SDL3-static.build/Debug-iphoneos/Objects-normal/arm64/SDL_dynapi.o -index-unit-output-path /SDL3-static.build/Debug-iphoneos/Objects-normal/arm64/SDL_dynapi.o

�[0;1;31merror: �[0m�[1minput is not a PCH file: '/Users/tanis/Documents/binocle-c/build-ios/build/SharedPrecompiledHeaders/SharedPrecompiledHeaders/16518934971014217302/cmake_pch.h.gch'�[0m
�[0;1;31mfatal error: �[0m�[1mfile '/Users/tanis/Documents/binocle-c/build-ios/build/SharedPrecompiledHeaders/SharedPrecompiledHeaders/16518934971014217302/cmake_pch.h.gch' is not a valid precompiled PCH file�[0m
2 errors generated.
@slouken slouken added this to the 3.2.2 milestone Jan 24, 2025
@madebr
Copy link
Contributor

madebr commented Jan 24, 2025

What CMake version are you using? (Please provide the output of cmake --version)

What if you use a recent cmake version?
You can download macOS dmg's here: https://cmake.org/download/

I'm thinking you're seeing this issue, which got fixed in CMake ~3.22.
But CMake 3.22 is more then 2 years old. So you might be seeing another issue.

@tanis2000
Copy link
Author

It’s 3.31.5, I am always on the latest available in homebrew on macOS.

Actually the issue looks more like https://gitlab.kitware.com/cmake/cmake/-/issues/22832

The error output is the same.

I left a comment there, but that issue is 3 years old with no resolution

@madebr
Copy link
Contributor

madebr commented Jan 24, 2025

From your error message, why is it adding -x objective-c when compiling SDL_dynapi.c?
SDL_dynapi.c is also the only source for which we explicitly disabled precompiled headers.

@slouken When you build SDL on macOS using the CMake project, does this also happen to you?

cmake -S /path/to/SDL -B /tmp/SDL-cmake-build -GXcode --fresh
cmake --build /tmp/SDL-cmake-build

@slouken
Copy link
Collaborator

slouken commented Jan 24, 2025

cmake version 3.30.4
** BUILD SUCCEEDED **

@madebr
Copy link
Contributor

madebr commented Jan 24, 2025

@tanis2000
Is XCode 16.2 the latest? Does it also happen with older/newer versions?

If you really want to build SDL3 with XCode, then I can only suggest to configure with -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON.
(SDL3 does not re-use precompiled headers btw, as the example at https://gitlab.kitware.com/cmake/cmake/-/issues/22832 does)

@tanis2000
Copy link
Author

From your error message, why is it adding -x objective-c when compiling SDL_dynapi.c?

I'm not 100% sure but it might come from this: I had to add enable_language(OBJC) as a workaround on the main project. You can see the rationale here: https://gitlab.kitware.com/cmake/cmake/-/issues/24104

There is an open issue in this repo, too: #6454

Is XCode 16.2 the latest? Does it also happen with older/newer versions?

Yes, it is the latest. And I have no idea if it happens with older versions. It's quite common for people on macOS to work with the latest version of Xcode as it is the only way to have your iOS apps compile against the latest iOS SDK.

If you really want to build SDL3 with XCode, then I can only suggest to configure with -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON. (SDL3 does not re-use precompiled headers btw, as the example at https://gitlab.kitware.com/cmake/cmake/-/issues/22832 does)

Good suggestion, thanks. That way I do not need to touch the CMakeLists.txt in SDL and I can just use the sources as they are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants