Thank you so much for the hint. Setting the environment variable CXX from within my CMakeLists.txt via<br>SET(ENV{CXX} &quot;icpc&quot;)<br>but before any call to project() or enable_language() seems indeed to do the trick.<br>
<br>Setting CMAKE_CXX_FLAGS_RELEASE or CMAKE_CXX_FLAGS_DEBUG at this stage however does not work. This apparently needs to go after the project() statement.<br>I could of course set the environment cxx-flags in the same way as above. This would somewhat sacrifice the nice RELEASE / DEBUG distinction but maybe this can be done by some if-statements (there certainly is a way to query the CMAKE_BUILD_TYPE variable, right?).<br>
<br>Cheers,<br>Oliver<br><br><br><div class="gmail_quote">2012/2/9 Michael Hertling <span dir="ltr">&lt;<a href="mailto:mhertling@online.de">mhertling@online.de</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 02/07/2012 02:43 PM, janitor 048 wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt; this is a question I recently asked on stackoverflow (<br>
&gt; <a href="http://stackoverflow.com/questions/9129233/recommended-ways-to-use-cmake-with-icc-via-configuration-options" target="_blank">http://stackoverflow.com/questions/9129233/recommended-ways-to-use-cmake-with-icc-via-configuration-options</a>)<br>

&gt; but that has not received any response since then. Maybe this mailing list<br>
&gt; is a better place to ask... Here goes<br>
&gt;<br>
&gt; I would like to use the Intel compiler icc (or icpc) with a CMake-based<br>
&gt; project (on Linux for what it&#39;s worth). I can of course export the CXX<br>
&gt; variable when calling cmake, e.g. like<br>
&gt;<br>
&gt; CXX=icpc cmake ../<br>
&gt;<br>
&gt; and this works fine. I would however like to make this choice available via<br>
&gt; a custom option. For this I parse custom option, e.g.<br>
&gt;<br>
&gt; cmake -DMY_COMPILER_OPTION=Intel ..<br>
&gt;<br>
&gt; as<br>
&gt;<br>
&gt; IF (MY_COMPILER_OPTION STREQUAL &quot;Intel&quot;)<br>
&gt;   MESSAGE(STATUS &quot;** Compiling with Intel settings **&quot;)<br>
&gt;   SET(CMAKE_CXX_COMPILER &quot;icpc&quot;)<br>
&gt;   SET(CMAKE_CXX_FLAGS_RELEASE &quot;-O3 -w&quot;)<br>
&gt;   SET(CMAKE_CXX_FLAGS_DEBUG &quot;-g&quot;)<br>
&gt; ENDIF ()<br>
&gt;<br>
&gt; and set CMAKE_CXX_COMPILER together with some compiler flags. This also<br>
&gt; works, however there is an important &quot;but&quot;.<br>
&gt;<br>
&gt; I would also like to use the option -ipo (interprocedural optimization) for<br>
&gt; my code when compiling with icc plus I need to compile a static library<br>
&gt; within the build process. For this to work, I need to use Intel&#39;s xiar (and<br>
&gt; also xilink I guess).<br>
&gt;<br>
&gt; cmake actually offers a special property for this<br>
&gt;<br>
&gt; set_property(TARGET mytarget PROPERTY INTERPROCEDURAL_OPTIMIZATION 1)<br>
&gt;<br>
&gt; however this only seems to works properly when the compiler has been set<br>
&gt; via the environment variable (then xiar is used). When setting the compiler<br>
&gt; via CMAKE_CXX_COMPILER this property is ignored.<br>
&gt;<br>
&gt; Is there another way to do this?. Some recommended way? Or at least a<br>
&gt; work-around?<br>
<br>
</div></div>If it actually works well when the compiler is specified via the<br>
respective environment variable, you might try the following:<br>
<div class="im"><br>
IF (MY_COMPILER_OPTION STREQUAL &quot;Intel&quot;)<br>
  MESSAGE(STATUS &quot;** Compiling with Intel settings **&quot;)<br>
</div>  SET(ENV{CXX} &quot;icpc&quot;)<br>
<div class="im">  SET(CMAKE_CXX_FLAGS_RELEASE &quot;-O3 -w&quot;)<br>
  SET(CMAKE_CXX_FLAGS_DEBUG &quot;-g&quot;)<br>
ENDIF ()<br>
<br>
</div>However, note that you must do this *before* the language is enabled,<br>
i.e. before the PROJECT() or ENABLE_LANGUAGE() commands. Note further<br>
that this can be done only for the *initial* configuration of a build<br>
tree; afterwards, the compiler can&#39;t be changed anymore. In order to<br>
make that approach more robust, you might consider some refinements:<br>
<div class="im"><br>
IF (MY_COMPILER_OPTION STREQUAL &quot;Intel&quot;)<br>
</div>  FIND_PROGRAM(ICPC_PROGRAM icpc ...)<br>
  IF(ICPC_PROGRAM)<br>
<div class="im">    MESSAGE(STATUS &quot;** Compiling with Intel settings **&quot;)<br>
</div>    IF(ENV{CXX})<br>
      MESSAGE(WARNING &quot;Overwriting CXX envvar&quot;)<br>
    ENDIF()<br>
    SET(ENV{CXX} &quot;${ICPC_PROGRAM}&quot;)<br>
<div class="im">    SET(CMAKE_CXX_FLAGS_RELEASE &quot;-O3 -w&quot;)<br>
    SET(CMAKE_CXX_FLAGS_DEBUG &quot;-g&quot;)<br>
</div>  ELSE()<br>
    MESSAGE(FATAL_ERROR &quot;Intel compiler not found&quot;)<br>
  ENDIF()<br>
ENDIF ()<br>
<br>
Regards,<br>
<br>
Michael<br>
<div class="HOEnZb"><div class="h5">--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br>