conan-io / conan

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

[feature] AutotoolsToolchain make build_type_flags configurable #15213

Open nicosmd opened 10 months ago

nicosmd commented 10 months ago

What is your suggestion?

Hey, I'm currently investigating how I can set the optimization level generators and build system independent. Therefor, I have set in my profile

[conf]
tools.build:cxxflags += ["-Os", "-DNDEBUG"]

.

In order to override the default Release flags for CMake I've added:

tools.cmake.cmaketoolchain:user_toolchain = ['{{ os.path.join(profile_dir, "cmake_vars.cmake") }}']

to the conf section of that profile and the cmake_vars.cmake basically contains:

set(CMAKE_CXX_FLAGS_RELEASE "")

This works well for CMake in order to transparently set the compiler optimization. For Meson this should also work. But I have noticed that the AutotoolsToolchain has a build_type_flags attribute which is set based on the build_type to hardcoded optimization levels, which is always added to the cxxflags export. I think it would make sense to make this somehow configurable in order to be able to override the optimization level for autotools based packages as well. Unfortunately, we have some plain Makefile based packages, hence just setting the build_type to MinSizeRel would not affect every package successfully.

Maybe the build_type_flags could be deactivated using a new conf entry for the autotoolsToolchain generator.

To make a proposal this could look like:

tools.gnu.autotoolstoolchain:disable_build_type_flags.

Another solution I can imagine would be to check if the tools.build:cxxflags/cflags already contains a optimization level and skip the build_type_flags composition in those cases. But I can imagine it would not be super easy to make this fail safe and it's again a case of "trying to be too smart".

Would this be a meaningful feature? Or do you see some different approaches to achieve this goal?

Thank you very much!

Have you read the CONTRIBUTING guide?

nicosmd commented 9 months ago

Hey @memsharded, I'm sorry to address you so directly but this is a quite important topic for us right now. Do you have some opinions on that or some quick advice how we could workaround this problem? Please let me know if the problem has not become clear.

Thank you very much!