CMake: Disable unity builds project-wide #158
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have a project that uses xz via CMake's
FetchContent
module. This basically downloads xz and makes it part of the parent project usingadd_subdirectory
.After adding xz like this, I could no longer compile my project as a unity build because xz doesn't appear to support this. xz could certainly be modified to support this type of build, but that's not simply a one-time fix but a long term commitment.
These are the types of errors it generates:
This PR disables unity builds for the entire xz project directory. Because of how variable scoping works, if someone includes xz in their project and enables unity builds then it's still applied to any other part of the build that doesn't explicitly disable it for themselves.
Disabling unity builds when it doesn't work is recommended as per the
UNITY_BUILD
target property documentation:Unity builds can sometimes reveal UB as compilation errors because the compiler can suddenly analyse across what would normally be separate compilation units. I just want to make it abundantly clear that I DON'T think that's what is going on here.
xz just employs some code patterns that happen to be incompatible with unity builds.