[CMake] How to use CMake with icc via configuration options when needing interprocedural optimization?

Alexander Neundorf a.neundorf-work at gmx.net
Tue Feb 7 15:59:52 EST 2012


Hi Janitor,

On Tuesday 07 February 2012, janitor 048 wrote:
> Hello,
> 
> this is a question I recently asked on stackoverflow (
> http://stackoverflow.com/questions/9129233/recommended-ways-to-use-cmake-wi
> th-icc-via-configuration-options) but that has not received any response
> since then. Maybe this mailing list is a better place to ask... Here goes
> 
> I would like to use the Intel compiler icc (or icpc) with a CMake-based
> project (on Linux for what it's worth). I can of course export the CXX
> variable when calling cmake, e.g. like
> 
> CXX=icpc cmake ../
> 
> and this works fine. I would however like to make this choice available via
> a custom option. For this I parse custom option, e.g.
> 
> cmake -DMY_COMPILER_OPTION=Intel ..
> 
> as
> 
> IF (MY_COMPILER_OPTION STREQUAL "Intel")
>   MESSAGE(STATUS "** Compiling with Intel settings **")
>   SET(CMAKE_CXX_COMPILER "icpc")
>   SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -w")
>   SET(CMAKE_CXX_FLAGS_DEBUG "-g")
> ENDIF ()

Don't do that, this is too late in the initialization process.
The recommended way is to set the CXX environment variable. This is only 
necessary during the initial cmake run, afterwards this is stored in the cmake 
cmake cache.
It should also work to preset the compiler variables:
cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc ....

(I didn't check, but it should work).

Alex


More information about the CMake mailing list