title: Recommended ways to use CMake with icc via configuration options?
body: <p>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</p>
  
  <pre><code>CXX=icpc cmake ../
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>cmake -DMY_COMPILER_OPTION=Intel ..
  </code></pre>
  
  <p>as</p>
  
  <pre><code>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 ()
  </code></pre>
  
  <p>and set <code>CMAKE_CXX_COMPILER</code> together with some compiler flags. This also works, however there is an important "but".</p>
  
  <p>I would also like to use the option <code>-ipo</code> (interprocedural optimization) for my code when compiling with icc plus I need to compile a static library within the build process. For this to work, I need to use Intel's <code>xiar</code> (and also <code>xilink</code> I guess).</p>
  
  <p>cmake actually offers a special property for this</p>
  
  <pre><code>set_property(TARGET mytarget PROPERTY INTERPROCEDURAL_OPTIMIZATION 1)
  </code></pre>
  
  <p>however this only seems to works properly when the compiler has been set via the environment variable (then xiar is used). When setting the compiler via <code>CMAKE_CXX_COMPILER</code>this property is ignored.</p>
  
  <p>Is there another way to do this?. Some recommended way? Or at least a work-around?</p>