Skip to content
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

[bug] CMakeToolchain: BUILD_SHARED_LIBS & CMAKE_POSITION_INDEPENDENT_CODE not honored if CMP0077 OLD (or not set) and turned as options in upstream CMakeLists #11840

Closed
SpaceIm opened this issue Aug 10, 2022 · 5 comments · Fixed by #12401
Assignees
Milestone

Comments

@SpaceIm
Copy link
Contributor

SpaceIm commented Aug 10, 2022

Environment Details (include every applicable attribute)

  • Operating System+version: macOS Montery
  • Compiler+version: AppleCland 13
  • Conan version: 1.51.1
  • Python version: 3.9.13

Steps to reproduce (Include if Applicable)

A shared lib is created instead of a static lib, while it was working fine with the conan v1 flavor of this recipe. If CMAKE_POLICY_DEFAULT_CMP0077 is injected as a CMakeToolchain cache_variables (by the way this name is super misleading, since CMakeToolchain variables are CMake cache variables, and CMakeToolchain cache_variables are CMakePresets cacheVariables), static lib is properly created.

Explanation:

Logs (Executed commands with output) (Include/Attach if Applicable)

Click to expand log
Exporting package recipe
libccd/2.1 exports: File 'conandata.yml' found. Exporting it...
libccd/2.1 exports: Copied 1 '.yml' file: conandata.yml
libccd/2.1: The stored package has not changed
libccd/2.1: Using the exported files summary hash as the recipe revision: 754e548f10cd5c5a13b36bd666b79ac2
libccd/2.1: Exported revision: 754e548f10cd5c5a13b36bd666b79ac2
Configuration (profile_host):
[settings]
arch=x86_64
build_type=Debug
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
[options]
libccd:shared=False
[build_requires]
[env]
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

Configuration (profile_build):
[settings]
arch=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=13
os=Macos
[options]
[build_requires]
[env]
[conf]
tools.cmake.cmaketoolchain:generator=Ninja

libccd/2.1: Forced build from source
libccd/2.1 (test package): Installing package
Requirements
    libccd/2.1 from 'conancenter' - Cache
Packages
    libccd/2.1:92958fbd7bb641f338e28ce02103bd2e6bd0c465 - Build

Installing (downloading, building) binaries...
libccd/2.1: Copying sources to build folder
libccd/2.1: Building your package in /Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465
libccd/2.1: Generator txt created conanbuildinfo.txt
libccd/2.1: Calling generate()
libccd/2.1: Aggregating env generators
libccd/2.1: Calling build()
libccd/2.1: CMake command: cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE="/Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465/build/generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Debug" "/Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465/src"
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Using Conan toolchain: /Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465/build/generators/conan_toolchain.cmake
-- Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC)
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The C compiler identification is AppleClang 13.1.6.13160021
-- The CXX compiler identification is AppleClang 13.1.6.13160021
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:23 (option):
  Policy CMP0077 is not set: option() honors normal variables.  Run "cmake
  --help-policy CMP0077" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  For compatibility with older versions of CMake, option is clearing the
  normal variable 'BUILD_SHARED_LIBS'.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Performing Test COMPILER_SUPPORTS_VISIBILITY
-- Performing Test COMPILER_SUPPORTS_VISIBILITY - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465/build/Debug
libccd/2.1: CMake command: cmake --build "/Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465/build/Debug" '--' '-j12'
[7/7] Creating library symlink src/libccd.2.dylib src/libccd.dylib
libccd/2.1: Package '92958fbd7bb641f338e28ce02103bd2e6bd0c465' built
libccd/2.1: Build folder /Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465/build/Debug
libccd/2.1: Generated conaninfo.txt
libccd/2.1: Generated conanbuildinfo.txt
libccd/2.1: Generating the package
libccd/2.1: Package folder /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465
libccd/2.1: Calling package()
libccd/2.1: Copied 1 file: BSD-LICENSE
libccd/2.1: CMake command: cmake --install "/Users/spaceim/.conan/data/libccd/2.1/_/_/build/92958fbd7bb641f338e28ce02103bd2e6bd0c465/build/Debug" --prefix "/Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465"
-- Install configuration: "Debug"
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/ccd/ccd-config.cmake
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/ccd/ccd-config-version.cmake
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/pkgconfig/ccd.pc
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/share/doc/ccd/BSD-LICENSE
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/libccd.2.0.dylib
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/libccd.2.dylib
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/libccd.dylib
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/include/ccd/ccd.h
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/include/ccd/compiler.h
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/include/ccd/ccd_export.h
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/include/ccd/quat.h
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/include/ccd/vec3.h
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/include/ccd/config.h
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/ccd/ccd-targets.cmake
-- Installing: /Users/spaceim/.conan/data/libccd/2.1/_/_/package/92958fbd7bb641f338e28ce02103bd2e6bd0c465/lib/ccd/ccd-targets-debug.cmake
libccd/2.1 package(): Packaged 1 file: BSD-LICENSE
libccd/2.1 package(): Packaged 6 '.h' files
libccd/2.1 package(): Packaged 3 '.dylib' files: libccd.dylib, libccd.2.0.dylib, libccd.2.dylib
libccd/2.1 package(): Packaged 1 '.cmake' file: conan-official-libccd-targets.cmake
libccd/2.1: Package '92958fbd7bb641f338e28ce02103bd2e6bd0c465' created
libccd/2.1: Created package revision 945ad782be184094cd6378b52deaa4af
@SpaceIm SpaceIm changed the title [bug] CMakeToolchain: BUILD_SHARED_LIBS & CMAKE_POSITION_INDEPENDENT_CODE not honored if CMP0077 (OLD or not set) and turned as options in upstream CMakeLists [bug] CMakeToolchain: BUILD_SHARED_LIBS & CMAKE_POSITION_INDEPENDENT_CODE not honored if CMP0077 OLD (or not set) and turned as options in upstream CMakeLists Aug 10, 2022
@jcar87 jcar87 self-assigned this Aug 11, 2022
@SpaceIm
Copy link
Contributor Author

SpaceIm commented Aug 11, 2022

So I guess the correct fix is to set BUILD_SHARED_LIBS & CMAKE_POSITION_INDEPENDENT_CODE as CACHE BOOL variables in conan_toolchain.cmake.

SpaceIm added a commit to SpaceIm/conan-center-index that referenced this issue Aug 17, 2022
@jwillikers
Copy link
Contributor

I just hit this issue porting GTest to Conan V2 on Conan Center: conan-io/conan-center-index#12326

@jcar87
Copy link
Contributor

jcar87 commented Aug 18, 2022

Hi @SpaceIm, @jwillikers for reporting this issue. We will work on a fix to address the case where a project treats this as global cache variables.

@jcar87 jcar87 added this to the 1.52 milestone Aug 18, 2022
conan-center-bot pushed a commit to conan-io/conan-center-index that referenced this issue Aug 22, 2022
* conan v2 support

* explicit cpp_info.libs

* no CMAKE_BINARY_DIR patch needed with CMakeToolchain

* set CMP0077 to NEW to avoid CMake warning

* add ref to conan-io/conan#11840

* fix indentation
@jcar87
Copy link
Contributor

jcar87 commented Aug 23, 2022

We have seen other cases where variables defined in the toolchain file generated by Conan end up "conflicting" in some way if the variables are (re)defined by the project CMakeLists, in a way that it conflicts or overrides the value that was provided in the toolchain.

Defining them as cache variables directly in the toolchain file is a possibility, but it is still not equivalent to defining them with -D in the command line - as the CMake toolchain files are loaded at specific times (the first project() call call and then multiple times internally by CMake) - so we still some risk, especially if projects define varibles/options before the first call to project().

While defining them in the generated CMake preset files would be great, that would limit the usability of this to users with the most recent versions of CMake.

We will work on a proof of concept to pass variables in a way that is equivalent to -D, outside of the toolchain file, without burdening the user with having to do multiple -D calls, and still retaining compatibility with CMake 3.15 in Conan 2.0.

@memsharded memsharded modified the milestones: 1.52, 1.53 Aug 29, 2022
leha-bot added a commit to leha-bot/conan-center-index that referenced this issue Aug 31, 2022
conan-center-bot pushed a commit to conan-io/conan-center-index that referenced this issue Sep 1, 2022
* double-conversion: add version 3.2.1

Generated and committed by [Conan Center Bot](https://github.com/qchateau/conan-center-bot)
Find more updatable recipes in the [GitHub Pages](https://qchateau.github.io/conan-center-bot/)

* double-conversion: Drop PDBs from package dir

* double-conversion: Fix shared build using workaround from conan-io/conan#11840

Co-authored-by: Quentin Chateau via Conan Center Bot <quentin.chateau@gmail.com>
ericLemanissier pushed a commit to ericLemanissier/conan-center-index that referenced this issue Sep 26, 2022
* double-conversion: add version 3.2.1

Generated and committed by [Conan Center Bot](https://github.com/qchateau/conan-center-bot)
Find more updatable recipes in the [GitHub Pages](https://qchateau.github.io/conan-center-bot/)

* double-conversion: Drop PDBs from package dir

* double-conversion: Fix shared build using workaround from conan-io/conan#11840

Co-authored-by: Quentin Chateau via Conan Center Bot <quentin.chateau@gmail.com>
@czoido czoido modified the milestones: 1.53, 1.54 Oct 4, 2022
@prince-chrismc
Copy link
Contributor

This is required in 55 CCI recipes so far https://github.com/conan-io/conan-center-index/search?q=CMAKE_POLICY_DEFAULT_CMP0077&type=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants