Thank you so much for the hint. Setting the environment variable CXX from within my CMakeLists.txt via<br>SET(ENV{CXX} "icpc")<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"><<a href="mailto:mhertling@online.de">mhertling@online.de</a>></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>
> Hello,<br>
><br>
> this is a question I recently asked on stackoverflow (<br>
> <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>
> but that has not received any response since then. Maybe this mailing list<br>
> is a better place to ask... Here goes<br>
><br>
> I would like to use the Intel compiler icc (or icpc) with a CMake-based<br>
> project (on Linux for what it's worth). I can of course export the CXX<br>
> variable when calling cmake, e.g. like<br>
><br>
> CXX=icpc cmake ../<br>
><br>
> and this works fine. I would however like to make this choice available via<br>
> a custom option. For this I parse custom option, e.g.<br>
><br>
> cmake -DMY_COMPILER_OPTION=Intel ..<br>
><br>
> as<br>
><br>
> IF (MY_COMPILER_OPTION STREQUAL "Intel")<br>
> MESSAGE(STATUS "** Compiling with Intel settings **")<br>
> SET(CMAKE_CXX_COMPILER "icpc")<br>
> SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -w")<br>
> SET(CMAKE_CXX_FLAGS_DEBUG "-g")<br>
> ENDIF ()<br>
><br>
> and set CMAKE_CXX_COMPILER together with some compiler flags. This also<br>
> works, however there is an important "but".<br>
><br>
> I would also like to use the option -ipo (interprocedural optimization) for<br>
> my code when compiling with icc plus I need to compile a static library<br>
> within the build process. For this to work, I need to use Intel's xiar (and<br>
> also xilink I guess).<br>
><br>
> cmake actually offers a special property for this<br>
><br>
> set_property(TARGET mytarget PROPERTY INTERPROCEDURAL_OPTIMIZATION 1)<br>
><br>
> however this only seems to works properly when the compiler has been set<br>
> via the environment variable (then xiar is used). When setting the compiler<br>
> via CMAKE_CXX_COMPILER this property is ignored.<br>
><br>
> Is there another way to do this?. Some recommended way? Or at least a<br>
> 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 "Intel")<br>
MESSAGE(STATUS "** Compiling with Intel settings **")<br>
</div> SET(ENV{CXX} "icpc")<br>
<div class="im"> SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -w")<br>
SET(CMAKE_CXX_FLAGS_DEBUG "-g")<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'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 "Intel")<br>
</div> FIND_PROGRAM(ICPC_PROGRAM icpc ...)<br>
IF(ICPC_PROGRAM)<br>
<div class="im"> MESSAGE(STATUS "** Compiling with Intel settings **")<br>
</div> IF(ENV{CXX})<br>
MESSAGE(WARNING "Overwriting CXX envvar")<br>
ENDIF()<br>
SET(ENV{CXX} "${ICPC_PROGRAM}")<br>
<div class="im"> SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -w")<br>
SET(CMAKE_CXX_FLAGS_DEBUG "-g")<br>
</div> ELSE()<br>
MESSAGE(FATAL_ERROR "Intel compiler not found")<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>