Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] Handling redundant settings due to cmaketoolchain:user_toolchain #15582

Closed
1 task done
sykhro opened this issue Feb 2, 2024 · 6 comments · Fixed by #15654
Closed
1 task done

[question] Handling redundant settings due to cmaketoolchain:user_toolchain #15582

sykhro opened this issue Feb 2, 2024 · 6 comments · Fixed by #15654
Assignees
Milestone

Comments

@sykhro
Copy link

sykhro commented Feb 2, 2024

What is your question?

I have a profile for Release-mode clang-cl:

[settings]
os=Windows
arch=x86_64
build_type=Release

[...]

the profile uses a CMake user toolchain and also specifies C(XX)FLAGS for projects that use other build systems:

tools.cmake.cmaketoolchain:user_toolchain = {{ [llvm_dir ~ "/windows-x64-clang.cmake"] }}

tools.build:cflags = ["-fuse-ld=lld", "-flto=thin", "/EHsc", "/MT"]
tools.build:cxxflags = ["-fuse-ld=lld", "-flto=thin", "/EHsc", "/MT"]
tools.build:exelinkflags = ["/MANIFEST:NO", "/NODEFAULTLIB:libucrt.lib", "/DEFAULTLIB:ucrt.lib"]
tools.build:sharedlinkflags = ["/MANIFEST:NO", "/NODEFAULTLIB:libucrt.lib", "/DEFAULTLIB:ucrt.lib"]

This, however, causes build failures with CMake.
The user toolchain file sets the link flags as follows:

string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT_DEBUG " /NODEFAULTLIB:libucrtd.lib /DEFAULTLIB:ucrtd.lib")
string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT_RELEASE " /NODEFAULTLIB:libucrt.lib /DEFAULTLIB:crtd.lib")

while conan generates the following code for conan_toolchain.cmake:

string(APPEND CONAN_SHARED_LINKER_FLAGS " /MANIFEST:NO")
string(APPEND CONAN_EXE_LINKER_FLAGS " /MANIFEST:NO")

but during the compiler checks, CMake defaults to Debug mode (I'm using a multi-config generator).
So, the linker line becomes a mix of Debug and Release flags.

My question is: how can I disable the CMakeToolchain cmake_flags_init block directly from the profile?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded memsharded self-assigned this Feb 2, 2024
@memsharded
Copy link
Member

Hi @sykhro

Thanks for your detailed report.

This is a known issue, I think it is the same as #13920. I have been trying to address it for a while, but so far we haven't got enough time to do it, even if I started the effort and I have something in a branch.

I'll try to give it another push, thanks for raising the isue!

@sykhro
Copy link
Author

sykhro commented Feb 2, 2024

Yes, it's indeed the same issue, I had trouble wording it. I'd be happy to contribute if you have any pointers

@memsharded
Copy link
Member

Thanks for checking. I think we can close this ticket and follow up on the other one.
As I had a branch somewhere to attempt this, let me have a look first, I will let you know if possible to contribute, thanks for the offer!

@sykhro
Copy link
Author

sykhro commented Feb 2, 2024

To be more precise, the root cause is the same but it would probably still be nice to be able to toggle which CMakeToolchain blocks to enable/disable from the profile itself, so that the repetition of variables can be avoided completely

@memsharded
Copy link
Member

I am submitting #15654 to fix this, hopefully for next 2.1, feedback welcome! (the PR might close this ticket when merged)

The feature to enable/disable individual blocks is a bit more unlikely, it would need a separate, dedicated issue to discuss it.

@memsharded
Copy link
Member

Merged #15654 for next 2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants