Set BUILD_SHARED_LIBS and CMAKE_POSITION_INDEPENDENT_CODE as Cache variables in toolchain - #12401
Merged
jcar87 merged 7 commits intoNov 2, 2022
Conversation
jcar87
force-pushed
the
bugfix/build-shared-libs-option-and-policy
branch
from
November 1, 2022 10:43
1178075 to
8f6e9ef
Compare
jcar87
marked this pull request as ready for review
November 2, 2022 13:54
czoido
approved these changes
Nov 2, 2022
franramirez688
approved these changes
Nov 2, 2022
Co-authored-by: Francisco Ramírez <franchuti688@gmail.com>
garethsb
added a commit
to garethsb/conan-center-index
that referenced
this pull request
Nov 14, 2022
bump required_conan_version to ">=1.54.0" to get conan-io/conan#12401
|
Note that this also resolves the similar issue if the upstream CMakeLists.txt uses: A workaround in Conan 1.53.0 is: Whereas CMP077 is for |
Member
|
Thanks for the tips @garethsb ! |
conan-center-bot
pushed a commit
to conan-io/conan-center-index
that referenced
this pull request
Nov 16, 2022
* Bump boost/1.80.0, openssl/1.1.1s, zlib/1.2.13 * conan v2: ConanFile, tools * Use export_conandata_patches and apply_conandata_patches * conan v2: CMakeDeps generator * Delete CMakeLists.txt as no longer required * Hopefully unbreak patches and add patch_type and patch_description * Hm, maybe omitting base_path was right after all * Missed patch_type and patch_description from one patch * Apply suggestions from code review Co-authored-by: Uilian Ries <uilianries@gmail.com> * CMakeDeps: update patches to use CMake targets rather than CONAN_INCLUDE_DIRS_xxx and CONAN_LIBS_xxx * Sanity check exported symbol for a public static constant * conan v2 test_package bump required_conan_version to ">=1.54.0" to get conan-io/conan#12401 * workaround for conan 1.53.0 Co-authored-by: Uilian Ries <uilianries@gmail.com>
prince-chrismc
pushed a commit
to prince-chrismc/conan-center-index
that referenced
this pull request
Nov 16, 2022
* Bump boost/1.80.0, openssl/1.1.1s, zlib/1.2.13 * conan v2: ConanFile, tools * Use export_conandata_patches and apply_conandata_patches * conan v2: CMakeDeps generator * Delete CMakeLists.txt as no longer required * Hopefully unbreak patches and add patch_type and patch_description * Hm, maybe omitting base_path was right after all * Missed patch_type and patch_description from one patch * Apply suggestions from code review Co-authored-by: Uilian Ries <uilianries@gmail.com> * CMakeDeps: update patches to use CMake targets rather than CONAN_INCLUDE_DIRS_xxx and CONAN_LIBS_xxx * Sanity check exported symbol for a public static constant * conan v2 test_package bump required_conan_version to ">=1.54.0" to get conan-io/conan#12401 * workaround for conan 1.53.0 Co-authored-by: Uilian Ries <uilianries@gmail.com>
|
Unfortunately, it looks like the 1.53.0 workaround wasn't effective... all packages were built, all test packages passed... but actually a shared package had been built and used in some cases. #14227 settled on a different workaround: - tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0126"] = "NEW"
+ tc.variables["BUILD_SHARED_LIBS"] = self.options.shared |
3 tasks
2 tasks
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.
…riables in CMakeToolchain
Changelog: Bugfix: When recipes have
sharedandfPICas options, defineBUILD_SHARED_LIBSandCMAKE_POSITION_INDEPENDENT_CODEas CACHE variables in the generatedcmake_toolchain.cmakeinstead of regular variables, so that they are not masked by further calls tooptions().Docs: Omit
Close #11840
Notes
The bug in #11840 can happen when CMake is operating on a policy version older than 3.13 and the project's CMake scripts make
option()calls for eitherBUILD_SHARED_LIBSandCMAKE_POSITION_INDEPENDENT_CODE. These calls can shadow the values defined by the toolchain (if the toolchain has been loaded already byproject()). Usingoption()for these variables seems valid as per CMake's own documentation.These variables are only defined in the generated
conan_toolchain.cmakeif the recipe hasfPICandsharedas options. These may be a tad outside of the scope of CMake toolchains.By setting them as cache variables, we ensure that
option()does not override their values ifoption()is called after the toolchain is loaded, but we also ensure that if the users manually and explicitly overrides the value via-Dflag, that value will be respected too.One caveat is that for projects that set the values after
cmake_minimum_required()but beforeproject()- the behaviour remains undefined, the value will depend on how the variable is set.