[CMake] CMAKE_FORCE_CXX_COMPILER question

Alexander Neundorf a.neundorf-work at gmx.net
Thu Feb 18 15:29:32 EST 2010


On Thursday 18 February 2010, Buonopane, Robert wrote:
> Hi:
> Running CMAKE 2.6
> In my project level CMakeList.txt file I have:
>    INCLUDE (CMakeForceCompiler)
>    CMAKE_FORCE_CXX_COMPILER(g++ GNU)
>
> When I build on my Linux platform it compiles and links with g++ which is
> what I want. When I build on my Solaris10 platform it compiles with g++ BUT
> links with gcc.

I think you don't need the force_compiler() macro.
It is intended only for very weird compilers/platforms, usually cross 
compiling, where the tools (compiler, linker) are behaving very different 
from the standard compilers (like needing a lot of switches for a basic 
hello-world).

Why do you think you need it ?

To tell cmake which compiler you want, set the CC and CXX environment 
variables before the initial cmake run to point to these compilers.

If you want to make sure in your CMakeLists.txt you got the right compilers, 
you may check the compiler id:

if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
   message(FATAL_ERROR "I want g++ !")
endif()

Alex


More information about the CMake mailing list