Conan: [bug] fPIC automatic handling fails when using cmake_find_package generator

Created on 20 Jul 2020  路  2Comments  路  Source: conan-io/conan

Environment Details (include every applicable attribute)

  • Conan version: 1.27.1

Steps to reproduce (Include if Applicable)

When creating a package with fPIC=True, the CMake build helper will set CONAN_CMAKE_POSITION_INDEPENDENT_CODE=ON.

However, this will only work when using the cmake generator (and using the conan_basic_setup macro, which checks for CONAN_CMAKE_POSITION_INDEPENDENT_CODE).
It does nothing when using cmake_find_package generators, the cmake_paths generator is likely to be affected as well.

The doc states that the CMake helper will set CMAKE_POSITION_INDEPENDENT_CODE accordingly though, which is incorrect.

Most helpful comment

Oops, didn't even see that was bincrafters' doc 馃う

Thanks, I'll try those options out!

All 2 comments

Hi @theodelrieu,

You are linking the Bincrafters documentation which we are not responsible for. What we have documented is that the CMake build helper handle the fPIC option in a recipe by setting CONAN_CMAKE_POSITION_INDEPENDENT_CODE automatically, as you can check here: https://docs.conan.io/en/latest/reference/build_helpers/cmake.html

This variable is only used by the cmake generator (I think it is missing from the documentation here https://docs.conan.io/en/latest/reference/generators/cmake.html) but it is definitely not set by the cmake_find_package(_multi) generators, nor by cmake_paths. This is because those generators only provide information about dependencies (in the case of cmake_paths it just relies on the packaged *.cmake files).

This is a trade-off as you can tell, that is the reason we are working on the toolchain concept: https://docs.conan.io/en/latest/creating_packages/toolchains.html

To work around your issue, you can try the new toolchain feature or use both cmake and cmake_find_package generators and keep the conan_basic_setup() CMake call or just the conan_set_fpic() one.

Hope that makes sense!

Oops, didn't even see that was bincrafters' doc 馃う

Thanks, I'll try those options out!

Was this page helpful?
0 / 5 - 0 ratings