Repository navigation
cmake: honor options set by a parent project - #5077
Merged
Merged
Conversation
Since 49fe2ec (v1.6.0), cmake_policy(VERSION) runs inside include(ZstdVersion), which has its own policy scope. CMP0077 was then unset for the rest of build/cmake, so option() discarded the values a parent project set before add_subdirectory(), such as set(ZSTD_BUILD_PROGRAMS OFF). NO_POLICY_SCOPE applies the policies to the whole project again, as in v1.5.7. Fix suggested by alexhadd in #5074.
terrelln
approved these changes
Nov 30, 2026
Cyan4973
added a commit
that referenced
this pull request
Dec 4, 2026
The parent project of the CMake subdirectory consumer now sets ZSTD_BUILD_PROGRAMS OFF and ZSTD_LEGACY_SUPPORT ON with set(), before add_subdirectory(), instead of passing them with -D. Configuration fails if the zstd program target exists, and the consumer fails if v0.7 frames are not recognized. This covers #5077: before it, both options were ignored.
Cyan4973
added a commit
that referenced
this pull request
Dec 4, 2026
The parent project of the CMake subdirectory consumer now sets ZSTD_BUILD_PROGRAMS OFF and ZSTD_LEGACY_SUPPORT ON with set(), before add_subdirectory(), instead of passing them with -D. Configuration fails if the zstd program target exists, and the consumer fails if v0.7 frames are not recognized. This covers #5077: before it, both options were ignored.
Cyan4973
added a commit
that referenced
this pull request
Dec 4, 2026
The parent project of the CMake subdirectory consumer now sets ZSTD_BUILD_PROGRAMS OFF and ZSTD_LEGACY_SUPPORT ON with set(), before add_subdirectory(), instead of passing them with -D. Configuration fails if the zstd program target exists, and the consumer fails if v0.7 frames are not recognized. This covers #5077: before it, both options were ignored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This affects projects that build zstd with CMake as a subproject, with
add_subdirectory(zstd/build/cmake).Problem
Since v1.6.0, the options such a project sets before
add_subdirectory(), likeset(ZSTD_BUILD_PROGRAMS OFF)orset(ZSTD_LEGACY_SUPPORT ON), are ignored, with a CMP0077 warning.Options passed with
-Don the command line still work.cmake_policy(VERSION)moved intoZstdVersion.cmake(49fe2ec), andinclude()gives it its own policy scope.So CMP0077 is unset for the rest of
build/cmake, andoption()overwrites the parent's value.Fix
include(ZstdVersion NO_POLICY_SCOPE): the policies apply to the whole project again, as in v1.5.7.Credit to @alexhadd, who found the cause and proposed this fix in #5074.
Test
With cmake 3.31.8 and a parent project that sets
ZSTD_BUILD_PROGRAMS OFFandZSTD_LEGACY_SUPPORT ON:dev: 2 CMP0077 warnings, the programs are built, and the library gets-DZSTD_LEGACY_SUPPORT=0.-DZSTD_LEGACY_SUPPORT=5.The standalone build of
build/cmakestill configures without warning.A CI check will follow in #5048, whose parent project passes options with
-D, and so doesn't catch this.Fixes #5074