Xcode generator adds compile flags to storyboards when PCH is enabled which results in build error
There's storyboard build error when the following conditions are met:
- Xcode generator is used
- Storyboard has property
MACOSX_PACKAGE_LOCATION Resources
- Precompiled headers are used
- There're CXX or OBJCXX sources in the target
The error is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.ibtool.errors</key>
<array>
<dict>
<key>description</key>
<string>Unable to rename classes, class name parsing failed.</string>
</dict>
<dict>
<key>description</key>
<string>Not enough arguments provided; where is the input document to operate on?</string>
</dict>
</array>
</dict>
</plist>
I guess the fix should be to not set the CMAKE_SKIP_PRECOMPILE_HEADERS
flag to sources that have MACOSX_PACKAGE_LOCATION
property.
You can find test project here: https://github.com/kambala-decapitator/cmake-storyboard-bug
Initially I stumbled on this in iOS project, but on other Apple platforms it's the same.
However, compiling xcassets (asset catalog) with actool
doesn't result in an error as the compile flag isn't passed to the command invocation (but the flag is also present in pbxproj).
Some background
At first I was banging my head why project suddenly stopped compiling (apparently I've upgraded my installed CMake). Then I looked at the storyboard build command:
ibtool ... -DCMAKE_SKIP_PRECOMPILE_HEADERS ...
Then I started wondering how the heck it appeared there. Inspecting the generated pbxproj revealed this:
{isa = PBXBuildFile; fileRef = 342A202B41BA494B8A88089B /* LaunchScreen.storyboard */; settings = {COMPILER_FLAGS = "-DCMAKE_SKIP_PRECOMPILE_HEADERS "; }; }
I couldn't understand what's adding that, so I added a quick workaround:
sed -i '' \
-e 's|\.storyboard \*/; settings = {COMPILER_FLAGS = "-DCMAKE_SKIP_PRECOMPILE_HEADERS "; };|.storyboard */;|g' \
*.xcodeproj/project.pbxproj
Then I started thorough investigation and came to target_precompile_headers
call, searching bugtracker I found #23138 (closed) whose PRs contain exactly adding CMAKE_SKIP_PRECOMPILE_HEADERS
flag to all sources for PCH+Xcode.
Storyboard is added as source file as it's the only way to make it appear in "Copy Bundle Resources" build phase. I tried setting various source file properties like HEADER_FILE_ONLY
but nothing helped. Then I finally found a CMake-level workaround to replace my sed
edit:
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.22.0")
set_source_files_properties(Main.storyboard PROPERTIES LANGUAGE CXX)
endif()
language should be the same as the one there's PCH for.