-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set BUILD_SHARED_LIBS and CMAKE_POSITION_INDEPENDENT_CODE as Cache variables in toolchain #12401
Set BUILD_SHARED_LIBS and CMAKE_POSITION_INDEPENDENT_CODE as Cache variables in toolchain #12401
Conversation
1178075
to
8f6e9ef
Compare
conans/test/functional/toolchains/cmake/test_cmake_toolchain.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Francisco Ramírez <franchuti688@gmail.com>
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 |
Thanks for the tips @garethsb ! |
* 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>
* 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 |
…riables in CMakeToolchain
Changelog: Bugfix: When recipes have
shared
andfPIC
as options, defineBUILD_SHARED_LIBS
andCMAKE_POSITION_INDEPENDENT_CODE
as CACHE variables in the generatedcmake_toolchain.cmake
instead 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_LIBS
andCMAKE_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.cmake
if the recipe hasfPIC
andshared
as 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-D
flag, 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.