MantisBT - CMake
View Issue Details
0008530CMakeModulespublic2009-02-13 04:052010-05-12 16:34
stephan Aiche 
Alex Neundorf 
normaltweakN/A
closedno change required 
CMake-2-6 
 
0008530: make CMAKE_CXX_COMPILER_INIT customizable from CMakeLists.txt
It would be quite useful if there would be a possibility to set the sequence in which CMake determines the c++ compilers. eg prefer g++ instead of c++

currently this is hardcoded in "modules/CMakeDetermineCXXCompiler.cmake" line 45
    SET(CMAKE_CXX_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ CC aCC cl bcc xlC)

i think the same holds for the C compiler
No tags attached.
Issue History
2009-02-13 04:05stephan AicheNew Issue
2009-02-13 09:15Bill HoffmanStatusnew => assigned
2009-02-13 09:15Bill HoffmanAssigned To => Alex Neundorf
2009-03-10 17:43Alex NeundorfNote Added: 0015624
2009-03-10 17:43Alex NeundorfCategoryCMake => Modules
2009-03-11 06:24stephan AicheNote Added: 0015643
2009-09-12 02:22Alex NeundorfSeverityfeature => tweak
2010-05-12 16:34Alex NeundorfNote Added: 0020727
2010-05-12 16:34Alex NeundorfStatusassigned => closed
2010-05-12 16:34Alex NeundorfResolutionopen => no change required

Notes
(0015624)
Alex Neundorf   
2009-03-10 17:43   
If you set the environment variable CXX before running cmake the first time, you can also force cmake to use this compiler and nothing else.

Or you could set CMAKE_CXX_COMPILER when running cmake:
cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++ ...

Does this solve your problem ?

Alex
(0015643)
stephan Aiche   
2009-03-11 06:24   
It is not directly a problem it is more a suggestion for an improvment of CMake. I know that I can specify my compiler by setting CXX or CMAKE_CXX_COMPILER. But this is for those who use the CMakeLists.txt.

What I suggested was a way for those guys who write the CMakeLists.txt to specify their own priority of for the compilers. eg. prefer g++ or intel-compilers ..

Stephan
(0020727)
Alex Neundorf   
2010-05-12 16:34   
You can do the following in your toplevel CMakeLists.txt, before the first call to project():

set(CMAKE_GENERATOR_CC icc gcc)
set(CMAKE_GENERATOR_CXX icpc g++)

project(MyProject)

This is not completely obvious, maybe more like an undocumented internal variable, but it works.
It will make cmake first search for the Intel compilers, then the GNU ones.
After that you can test which one has been found:

if ("${CMAKE_C_COMPILER_ID}" MATCHES Intel)
...
endif().

And you have, as mentioned in my first comment, also the option to just set the compiler directly when invoking cmake.

So I think there is no need for extra changes in cmake.

Alex