libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.77k stars 1.81k forks source link

clang: warning: precompiled header 'cmake_pch_arm64.h' is not first '-include' #7429

Closed icculus closed 1 year ago

icculus commented 1 year ago

Seeing this with every file compiled, with the latest in SDL3 on macOS:

clang: warning: precompiled header '/Users/icculus/projects/SDL/buildbot/CMakeFiles/SDL3-shared.dir/cmake_pch_arm64.h.pch' was ignored because '-include /Users/icculus/projects/SDL/buildbot/CMakeFiles/SDL3-shared.dir/cmake_pch_arm64.h' is not first '-include'

Example command line:

/usr/local/bin/ccache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -DSDL3_shared_EXPORTS -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=0 -DSDL_BUILD_MINOR_VERSION=0 -DUSING_GENERATED_CONFIG_H -I/Users/icculus/projects/SDL/buildbot/include-config-debug -I/Users/icculus/projects/SDL/src -I/Users/icculus/projects/SDL/buildbot/include -I/Users/icculus/projects/SDL/include -I/Users/icculus/projects/SDL/include/SDL3 -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.6 -fPIC -fvisibility=hidden -Wno-error=deprecated-declarations -D_THREAD_SAFE -fobjc-arc -idirafter /Users/icculus/projects/SDL/src/video/khronos -Wall -fno-strict-aliasing -Wdeclaration-after-statement -Wdocumentation -Wdocumentation-unknown-command -fcomment-block-commands=threadsafety -Wshadow -Winvalid-pch -Xarch_arm64 -include/Users/icculus/projects/SDL/buildbot/CMakeFiles/SDL3-shared.dir/cmake_pch_arm64.h -MD -MT CMakeFiles/SDL3-shared.dir/src/SDL.c.o -MF CMakeFiles/SDL3-shared.dir/src/SDL.c.o.d -o CMakeFiles/SDL3-shared.dir/src/SDL.c.o -c /Users/icculus/projects/SDL/src/SDL.c

This is with CMake 3.25.0 on macOS, using this command line:

cmake -DCMAKE_BUILD_TYPE=Debug -G Ninja ..

I have not bisected this, but I will if the problem isn't obvious.

CC @madebr

madebr commented 1 year ago

The warning is not obvious to me. The warning hints we're doing multiple -includeXXX's, but the command line shows we're not doing that. Either ways, the CMake script is not force including anything.

So I can only make guesses. A bisection would be most welcome.

For reference, this is the compile command when using clang on Linux (no warnings):

/usr/bin/ccache /usr/lib64/ccache/clang -DSDL3_shared_EXPORTS -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=0 -DSDL_BUILD_MINOR_VERSION=0 -DUSING_GENERATED_CONFIG_H -I/home/maarten/projects/SDL/cmake-build-debug-llvm/include-config- -I/home/maarten/projects/SDL/src -I/home/maarten/projects/SDL/cmake-build-debug-llvm/include -I/home/maarten/projects/SDL/include -I/home/maarten/projects/SDL/include/SDL3 -isystem /usr/include/pipewire-0.3 -isystem /usr/include/spa-0.2 -isystem /home/maarten/projects/SDL/cmake-build-debug-llvm/wayland-generated-protocols -isystem /usr/include/libdecor-0 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -isystem /usr/include/ibus-1.0 -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/sysprof-4 -isystem /usr/include/libmount -isystem /usr/include/blkid -fPIC -fvisibility=hidden -mmmx -msse -msse2 -msse3 -D_REENTRANT -idirafter /home/maarten/projects/SDL/src/video/khronos -Wall -fno-strict-aliasing -Wdeclaration-after-statement -Wdocumentation -Wdocumentation-unknown-command -fcomment-block-commands=threadsafety -Wshadow -fcolor-diagnostics -Winvalid-pch -Xclang -include-pch -Xclang /home/maarten/projects/SDL/cmake-build-debug-llvm/CMakeFiles/SDL3-shared.dir/cmake_pch.h.pch -Xclang -include -Xclang /home/maarten/projects/SDL/cmake-build-debug-llvm/CMakeFiles/SDL3-shared.dir/cmake_pch.h -MD -MT CMakeFiles/SDL3-shared.dir/src/SDL.c.o -MF CMakeFiles/SDL3-shared.dir/src/SDL.c.o.d -o CMakeFiles/SDL3-shared.dir/src/SDL.c.o -c /home/maarten/projects/SDL/src/SDL.c

On Linux, the pch is added using a slightly different method as yours:

-Xclang -include-pch -Xclang /path/to/cmake_pch.h.pch -Xclang -include -Xclang /path/to/cmake_pch.h.pch
icculus commented 1 year ago

Ah, it's ccache causing the problem, for reasons I don't really understand. It's weird, this isn't a new install of anything.

madebr commented 1 year ago

Before you do a ccache -C to clean your cache, perhaps the ccache logs can make you wiser?

Prepend the compile command with the following, and look at the files in the ccache_debug folder

CCACHE_DEBUGDIR=$PWD/ccache_debug CCACHE_DEBUG=1

My log contains the following lines, which means ccache is currently not working with pch.

[2023-03-09T01:23:14.997864 95216] You have to specify "pch_defines,time_macros" sloppiness when creating precompiled headers
[2023-03-09T01:23:14.997868 95216] Failed; falling back to running the real compiler
[2023-03-09T01:23:14.997871 95216] Executing /usr/bin/clang -Dpchlib_EXPORTS -fPIC -fvisibility=hidden -Winvalid-pch -fpch-instantiate-templates -Xclang -emit-pch -Xclang -include -Xclang /tmp/pchtest/build/CMakeFiles/pchlib.dir/cmake_pch.h -x c-header -MD -MT CMakeFiles/pchlib.dir/cmake_pch.h.pch -MF CMakeFiles/pchlib.dir/cmake_pch.h.pch.d -o CMakeFiles/pchlib.dir/cmake_pch.h.pch -c /tmp/pchtest/build/CMakeFiles/pchlib.dir/cmake_pch.h.c

edit After running ccache -o sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime, cache retrieval seems to work.

icculus commented 1 year ago

Yeah, same message in the debug logs here.

But honestly, start to finish on the Mac Mini, a non-ccache build takes under 3 seconds, so I'd rather not use it (and wonder if this is something we should be forcing upon people in CMakeLists, instead of SDL_CCACHE defaulting to OFF).

madebr commented 1 year ago

Let's disable it by default. I just tried testing ccache on ci, and for an unknown reason it took much longer to finish.

madebr commented 1 year ago

See c304fbded