conan-io / conan

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

[question] How to disable the stdlib flag set by CMakeToolchain? #17044

Open Adnn opened 2 weeks ago

Adnn commented 2 weeks ago

Hi!

We are building a macOS project where we compile a custom c++ standard library (derived from libc++). The path to this custom libc++ is provided as an explicit linker argument (edit: along the -nostdinc++ flag).

Sadly, this conflicts with the conan_toolchain.cmake generated by CMakeToolchain generator. This file contains: string(APPEND CONAN_CXX_FLAGS " -stdlib=libc++") With XCode 15, this flag is tagged as an "unused argument" at link time (which fails the compilation when enabling warnings as errors).

Since compiler.libcxx setting is mandatory on apple-clang compiler, how can we prevent the toolchain file from adding this flag?

memsharded commented 2 weeks ago

Hi @Adnn

Thanks for your question.

There are 2 different aspects here. The first one is the possibility of modeling a custom libcxx, something discussed in https://github.com/conan-io/conan/issues/15620, if you want to track that ticket.

Then, you comment that it is mandatory to define libcxx in apple-clang. Have you considered adding the null possibility in the settings.yml file?

libcxx: [null, libstdc++, libc++]

I think this would allow to let the libcxx undefined and the flag will not be added.

If we are talking about disabling the respective CMakeToolchain block that sets that flag, it should be possible with::

Please let us know if this helps.

Adnn commented 2 weeks ago

Hi @memsharded,

Thank you for your detailed response. For the moment I am really looking at the second aspect: I would like to prevent the linker flag to be appended, so our custom stdlib is picked-up without generating any warning.

A follow-up question regarding modification of settings.yml: is it intended to be user edited? (I never really thought about that). Is it distributed with conan config install command? (If we were to go this way, the same version of settings would need to be distributed to all developers and to CI machines).

memsharded commented 2 weeks ago

A follow-up question regarding modification of settings.yml: is it intended to be user edited? (I never really thought about that). Is it distributed with conan config install command? (If we were to go this way, the same version of settings would need to be distributed to all developers and to CI machines).

In Conan 2 there is even a settings_user.yml that is intended to add new values to existing ones, making easier the maintenance when Conan new versions add something to the settings.yml. Yes, it is quite a common practice, so we made this possibility and documented it in https://docs.conan.io/2/reference/config_files/settings.html#customizing-settings for general customization and in https://docs.conan.io/2/examples/config_files/settings/settings_user.html for settings_user.yml specifically.

Yes, both the settings.yml and the settings_user.yml can be distributed with conan config install or conan config install-pkg, and that would be indeed the recommended approach for custom settings.