conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.25k stars 980 forks source link

[bug] fPIC automatic handling fails when using cmake_find_package generator #7388

Closed theodelrieu closed 4 years ago

theodelrieu commented 4 years ago

Environment Details (include every applicable attribute)

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.

danimtb commented 4 years ago

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!

theodelrieu commented 4 years ago

Oops, didn't even see that was bincrafters' doc 🤦

Thanks, I'll try those options out!