I think this could work, but if compiler is altered before project() call (but I didn&#39;t check this and suggest set variable only if it&#39;s not already set). Specifying only one variable  in command line looks more user-friendly and robust than several ones.<br>
Anther option is using initial cache.<br><br>Regards,<br>Yuri<br><br><div class="gmail_quote">On Wed, Feb 8, 2012 at 12:59 AM, Alexander Neundorf <span dir="ltr">&lt;<a href="mailto:a.neundorf-work@gmx.net">a.neundorf-work@gmx.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Janitor,<br>
<div class="im"><br>
On Tuesday 07 February 2012, 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-wi" target="_blank">http://stackoverflow.com/questions/9129233/recommended-ways-to-use-cmake-wi</a><br>
&gt; th-icc-via-configuration-options) but that has not received any response<br>
&gt; since then. Maybe this mailing list 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>
<br>
</div>Don&#39;t do that, this is too late in the initialization process.<br>
The recommended way is to set the CXX environment variable. This is only<br>
necessary during the initial cmake run, afterwards this is stored in the cmake<br>
cmake cache.<br>
It should also work to preset the compiler variables:<br>
cmake -DCMAKE_C_COMPILER=icc -DCMAKE_CXX_COMPILER=icpc ....<br>
<br>
(I didn&#39;t check, but it should work).<br>
<br>
Alex<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>