conan-io / conan

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

[question] How does one set toolchain-specific profile configurations #12903

Open System-Arch opened 1 year ago

System-Arch commented 1 year ago

What is your question?

I'm trying to set up generic build policies for things like reproducibility and portability. To this end, I'd like to set -ffile-prefix-map for Linux builds. I've used Jinja to create a Linux-specific profile, but when I try to follow the recommendation in https://blog.conan.io/2019/09/02/Deterministic-builds-with-C-C++.html by adding:

tools.build:cflags=['-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.' ]

it works correctly for CMake recipes but blows up for others (e.g., OpenSSL) that don't use CMake. It feels like Conan may need to support finer-grained configuration settings, i.e., something like:

tools.cmake.build:cflags=['-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.' ]

I'm also looking for an analogous way to implement this setting for autotools builds. As above, the challenge is having an appropriate way to specify the source directory in an abstract manner that can be passed as part of a build flag. Perhaps something like this could be made to work:

tools.build:cflags=[f'-ffile-prefix-map={conanfile.source_folder}=.' ]

Next, I would like to specify -Wl,-rpath=\$ORIGIN as a linker option. While the following should theoretically work:

tools.build:sharedlinkflags=['-Wl,-rpath=\$ORIGIN'] tools.build:exelinkflags=['-Wl,-rpath=\$ORIGIN']

I don't see these statements having the desired effect in a CMake context, however, unlike the documentation (see conans/model/conf.py) that says these only affect CMake variables, they do seem to be picked up by autotools and other tool chains as well, which seems should be documented.

For CMake, I am guessing these flags should really be set via CMAKE_INSTALL_RPATH as discussed here [https://docs.conan.io/en/latest/howtos/manage_shared_libraries/rpaths.html], but it is not obvious (to me) how to set the value of this CMake variable in a profile. Thus it might be helpful if there was a CMake variable dictionary analogous to tools.microsoft.msbuildtoolchain:compile_options that would permit something like:

tools.cmake:variables={ "CMAKE_INSTALL_RPATH": "-Wl,-rpath=\$ORIGIN" }

Thanks for any insights or suggestions

Have you read the CONTRIBUTING guide?

System-Arch commented 1 year ago

Hi @memsharded. Any thoughts on this question/use case? Thanks