[feature] Setting `CMAKE_<LANG>_COMPILER` in a toolchain
See original GitHub issueProblem 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
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please take into account that the paths set through the
conf[]
parameter should probably be set automatically by Conan asCC
andCXX
(orCMAKE_<LANG>_COMPILER
) environment variables soconan 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.@mpusz You can do some more complicated stuff to configure the
CMAKE_C_COMPILER
andCMAKE_CXX_COMPILER
in the generatedconan_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.The
CMakeToolchain
generator could then use this value to setCMAKE_C_COMPILER
in theconan_toolchain.cmake
.