conan icon indicating copy to clipboard operation
conan copied to clipboard

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

Open SpaceIm opened this issue 3 years ago • 0 comments

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)

  • checkout this PR of libccd recipe (conan v2 migration): https://github.com/conan-io/conan-center-index/pull/12110 (this commit: https://github.com/conan-io/conan-center-index/pull/12110/commits/14aa84b08d915dd01c1b43b599b012b3293ff79a)
  • remove tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW" from its conanfile.py
  • run conan create . libccd/2.1@ -o libccd:shared=False

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:

  • In libccd CMakeLists:
    • cmake_minimum_required is < 3.13: https://github.com/danfis/libccd/blob/v2.1/CMakeLists.txt#L1
    • BUILD_SHARED_LIBS is overridden as an option() defaulted to ON: https://github.com/danfis/libccd/blob/v2.1/CMakeLists.txt#L23
  • without https://cmake.org/cmake/help/latest/policy/CMP0077.html set to NEW, option() removes non-cached variable of the same name

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 avatar Aug 10 '22 23:08 SpaceIm