[CMake] Alternate compiler specific options - how to specify?

Miller Henry MillerHenry at JohnDeere.com
Thu Sep 12 09:43:19 EDT 2013


Let me restate the problem: we support several compilers.   When using one particular compiler we need to add an option specific to that compiler.  How do I make sure that all 200 developer get this option specified right everytime?

I got a great answer for -mtune=atom (seems obvious in hindsight), but I'm not clear on how to disable warnings - I'm going to assume that in some other compiler this warning exists, but it doesn't product the false positives we see.  (I haven't investigated this particular case, I'm assuming the option is because of false positives)

-----Original Message-----
From: Игорь Пашев [mailto:pashev.igor at gmail.com] 
Sent: Wednesday, September 11, 2013 11:31 PM
To: Miller Henry
Cc: cmake at cmake.org
Subject: Re: [CMake] Alternate compiler specific options - how to specify?

2013/9/11 Miller Henry <MillerHenry at johndeere.com>:
> We are using cmake 2.8.11 for out project.
>
> Our local compiler is gcc-4.4.3.  There is desire to use a newer 
> compiler, but we are not yet ready to commit to anything yet.  In the 
> mean time we have installed binaries gcc-4.7 and gcc-4.8.  We can 
> specify the alternate compiler with –DCMAKE_C_COMPILER=gcc-4.7, but we want to go a step farther:
> one (believed important) advantage of gcc-4.7 is the option 
> -mtune=atom since that is are target system. We want to force this 
> option when using the newer compiler, but the older version of gcc doesn’t accept it.
>
> Toolchain files are not an option, when you use a toolchain file cmake 
> sets CMAKE_CROSSCOMPILING meaning parts of our system that depend on 
> running on
> x86 will not run.  (it is up to a different team to make a build for 
> other processors – they are nowhere close to done but that variable is 
> used in a few places to disable things that my team needs).
>
> Here is what we come up with, which both feels icky, and seems like a 
> bad
> compromise:
>
> IF("4.8.0" STREQUAL ${CMAKE_CXX_COMPILER_VERSION} OR "4.8.1" STREQUAL 
> ${CMAKE_CXX_COMPILER_VERSION} OR "4.8" STREQUAL ${USE_GCC_VERSION})
>   SET(CMAKE_CXX_COMPILER "g++-4.8")
> SET(CMAKE_C_COMPILER "gcc-4.8")
>   SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11")
>     SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-local-typedefs"
> CACHE STRING "" FORCE)
> ELSEIF("4.7.1" STREQUAL ${CMAKE_CXX_COMPILER_VERSION} OR "4.7.2" 
> STREQUAL ${CMAKE_CXX_COMPILER_VERSION} OR "4.7" STREQUAL ${USE_GCC_VERSION})
>   SET(CMAKE_CXX_COMPILER "g++-4.7")
>   SET(CMAKE_C_COMPILER "gcc-4.7")
> ENDIF("4.8.0" STREQUAL ${CMAKE_CXX_COMPILER_VERSION} OR "4.8.1" 
> STREQUAL ${CMAKE_CXX_COMPILER_VERSION} OR "4.8" STREQUAL 
> ${USE_GCC_VERSION})
>

As for me coding any compiler options into CMake files is an urgly idea.


More information about the CMake mailing list