question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] Setting `CMAKE_<LANG>_COMPILER` in a toolchain

See original GitHub issue

Problem statement

Right now it is common to use a different compiler for conan install and CMake configure steps which result in an error during project configuration.

Potential solution

From my observation, it is typical to set CXX and CC environment variables in the Conan profile file. In case a user provides them and uses such a profile during conan install step it would be great if CMakeToolchain would set CMAKE_<LANG>_COMPILER cache variables based on those.

Thanks to that we will always end up with consistent builds and users will just have to call:

conan install .. -pr my_profile
cmake .. -toolchain conan_toolchain.cmake

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mpuszcommented, Sep 20, 2022

Please take into account that the paths set through the conf[] parameter should probably be set automatically by Conan as CC and CXX (or CMAKE_<LANG>_COMPILER) environment variables so conan install --build missing works correctly (such build does not include the toolchain file generated in this step). It would be unfortunate to force the user to set the same path twice in a profile file.

1reaction
jwillikerscommented, Dec 12, 2021

@mpusz You can do some more complicated stuff to configure the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER in the generated conan_toolchain.cmake, or provide your own CMake toolchain file to Conan through the related [conf] variables. CMake toolchain files are really meant for that and additional configuration of the toolchain.

But, I completely agree that it’s a very common need, and I’d like it to be simpler. I’m not sure the [env] setting is the best approach, since Conan is trying to move away from the use of [env] variables. Configuring different names and locations for a compiler is useful for any generator and compiler, too. Perhaps a set of dedicated [conf] variables could be added to allow specifying a particular suffix and prefix for the various tools in the toolchain, i.e. gcc / g++ and/or an option to add additional compiler search paths may also be helpful. Or maybe it would be simplest to just provide a single option to configure the full path to the compiler. Whichever makes the most sense. This way any generator could make use of the configuration values to set the appropriate compiler.

Here’s a possible example using a made up configuration value, tools.c_compiler.path, that sets the path of the C compiler.

[settings]
compiler = gcc

[conf]
tools.c_compiler.path = /path/to/my/toolchain/custom-gcc

The CMakeToolchain generator could then use this value to set CMAKE_C_COMPILER in the conan_toolchain.cmake.

set(CMAKE_C_COMPILER /path/to/my/toolchain/custom-gcc)
Read more comments on GitHub >

github_iconTop Results From Across the Web

cmake-toolchains(7) — CMake 3.25.1 Documentation
CMake uses a toolchain of utilities to compile, link libraries and create archives, and other tasks to drive the build. The toolchain utilities...
Read more >
How to set up CMake to cross compile with clang for ARM ...
The simple solution is to specify the full path to cmake on the command line. In my case, I have the GCC cross...
Read more >
CMAKE_ASM_COMPILE_OPTIO...
This issue currently breaks Android's "legacy toolchain file" (as opposed to its newer toolchain file). The legacy file happens to set the CMAKE...
Read more >
How to cross-compile for embedded with CMake like a champ
In this article: How CMake manages compiler; Setting custom toolchain; Structure of the toolchain file; Ready to use toolchain file; Download ...
Read more >
CMake Toolchains Reference - manpages.ubuntu!
CMake uses a toolchain of utilities to compile, link libraries and create archives, and other tasks to drive the build. The toolchain utilities...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found