<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>We do what Chuck showed inside our CMakeLists for different flags for each compiler.
<br>
</p>
<p><br>
</p>
<p>To answer your other question, I prefer to use the shorter form:</p>
<p><br>
</p>
<p>> CC=icc FC=ifort CXX=icpc cmake /path/to/source</p>
<p><br>
</p>
<p>which sets the CC, FC and CXX environment variables only for that ccmake command without changing them in my global environment (using bash shell, it may work in others also). Once CMake has set the compilers, it doesn't change them so future calls can just
 be</p>
<p><br>
</p>
<p>> cmake ./</p>
<p><br>
</p>
<p>Usually when I have to do a lot of compiler jockeying, I set up the module system (common on HPC's to handle different software stacks) so I can just do something like:</p>
<p><br>
</p>
<p>> module load intel-compilers</p>
<p>> cmake /path/to/source</p>
<p><br>
</p>
<p>> module swap intel-compilers gnu-compilers</p>
<p>> cmake /path/to/source<br>
</p>
<p><br>
</p>
<p>and so on.</p>
<p><br>
</p>
<p>Tim</p>
<p><br>
</p>
<br>
<br>
<div style="color: rgb(49, 55, 57);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> CMake <cmake-bounces@cmake.org> on behalf of TCW via CMake <cmake@cmake.org><br>
<b>Sent:</b> Tuesday, May 17, 2016 1:21 PM<br>
<b>To:</b> Chuck Atkins<br>
<b>Cc:</b> cmake@cmake.org<br>
<b>Subject:</b> Re: [CMake] Idomatic cmake: Supporting gcc, icc, and clang with custom flags for each?</font>
<div> </div>
</div>
<div>
<div>Hi Chuck,<br>
</div>
<div><br>
</div>
<div>Interesting. The flat list is not so bad i guess.  (As an include.)  I was thinking that cmake might support some kind of hierarchical platform definition system like Qt's qmake. (Not that it's without foibles either.)  <br>
</div>
<div><br>
</div>
<div>On the compiler selection question I'm still wondering if normative cmake usage really is, for example:<br>
</div>
<div><br>
</div>
<div>cmake -D CMAKE_C_COMPILER=/opt/path/to/icc  -D CMAKE_CXX_COMPILER=/opt/path/to/icpc ../path/to/src<br>
</div>
<div><br>
</div>
<div>That is would be as opposed to the much shorter (but purely imagineary):<br>
</div>
<div><span class="colour" style="color:rgb(34,34,34)"><span class="font" style="font-family:Arial,'Helvetica Neue',Helvetica,sans-serif"><span class="size" style="font-size:14px">cmake --tools=intel_16.0 ../path/to/src</span></span></span><br>
</div>
<div>or, <span class="colour" style="color:rgb(34,34,34)"><span class="font" style="font-family:Arial,'Helvetica Neue',Helvetica,sans-serif"><span class="size" style="font-size:14px">cmake --tools=gcc_5.3 ../path/to/src</span></span></span><br>
</div>
<div><span class="colour" style="color:rgb(34,34,34)"><span class="font" style="font-family:Arial,'Helvetica Neue',Helvetica,sans-serif"><span class="size" style="font-size:14px">or, </span></span></span><span class="colour" style="color:rgb(34,34,34)"><span class="font" style="font-family:Arial,'Helvetica Neue',Helvetica,sans-serif"><span class="size" style="font-size:14px"><span class="font" style="font-family:Arial,'Helvetica Neue',Helvetica,sans-serif"><span class="size" style="font-size:14px">cmake
 --tools=gcc_6.1 ../path/to/src</span></span></span></span></span><br>
</div>
<div><br>
</div>
<div>Where "<span class="colour" style="color:rgb(34,34,34)"><span class="font" style="font-family:Arial,'Helvetica Neue',Helvetica,sans-serif"><span class="size" style="font-size:14px">intel_16.0" and the like map to some locally defined path (and perhaps
 also flag) definitions.</span></span></span></div>
<div><br>
</div>
<div>Do folks really use the long form above? (perhaps wrapping it in a shell script or the like?)
<br>
</div>
<div><br>
</div>
<div>As someone very to to cmake, I wonder if I'm missing some key insight in to normal cmake workflow, or if this kind of compiler selection is, in fact, rare enough to not be cleanly supported.<br>
</div>
<div><br>
</div>
<div>Thank you,<br>
</div>
<div>Waffle</div>
<div><br>
</div>
<div><br>
</div>
<blockquote type="cite" class="protonmail_quote">
<div>-------- Original Message --------<br>
</div>
<div>Subject: Re: [CMake] Idomatic cmake: Supporting gcc, icc, and clang with custom flags for each?<br>
</div>
<div>Local Time: May 17, 2016 9:47 AM<br>
</div>
<div>UTC Time: May 17, 2016 1:47 PM<br>
</div>
<div>From: chuck.atkins@kitware.com<br>
</div>
<div>To: wafflecode@protonmail.com<br>
</div>
<div>CC: cmake@cmake.org<br>
</div>
<div><br>
</div>
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>Hi TCW,<br>
</div>
</div>
<div>A typical approach for this is in the top level CMakeLists.txt to have:<br>
</div>
<div><br>
</div>
</div>
<div><span class="font" style="font-family:monospace,monospace">include(CompilerFlags)</span><br>
</div>
<div><br>
</div>
</div>
<div>And then you can isolate the detection and specialization logic in a separate CompilerFlags.cmake:<br>
</div>
<div><br>
</div>
</div>
<div><span class="font" style="font-family:monospace,monospace">if(CMAKE_COMPILER_IS_GNUC)</span><br>
</div>
</div>
<div><span class="font" style="font-family:monospace,monospace">  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS" -extra --gcc-options")</span><br>
</div>
</div>
<div><span class="font" style="font-family:monospace,monospace">elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")<br>
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS" -extra --icc-options")<br>
elseif(CMAKE_C_COMPILER_ID MATCHES "PGI)<br>
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS" -extra --pgcc-options")</span></div>
</div>
<div><span class="font" style="font-family:monospace,monospace">elseif(MSVC)</span><br>
</div>
</div>
<div><span class="font" style="font-family:monospace,monospace">  if(MSVC_VERSION GREATER_THAN 1700)<br>
    ...</span></div>
</div>
<div><span class="font" style="font-family:monospace,monospace">  elseif(...)<br>
    ...</span></div>
</div>
<div><span class="font" style="font-family:monospace,monospace">  endif()</span><br>
</div>
</div>
<div><span class="font" style="font-family:monospace,monospace">endif()</span><br>
</div>
<div><br>
</div>
</div>
<div>And then similarly for C++.<br>
</div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>  <br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="gmail_extra">
<div><br>
</div>
<div>
<div>
<div dir="ltr">- Chuck<br>
</div>
</div>
</div>
<div><br>
</div>
<div class="gmail_quote">
<div>On Tue, May 17, 2016 at 1:49 AM, TCW via CMake <span dir="ltr"><<a href="mailto:cmake@cmake.org">cmake@cmake.org</a>></span> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>Hello all,<br>
</div>
<div><br>
</div>
<div>On linux, what's the correct way to support building with several different C compilers, each with some extra compiler-specifc flags for Debug and Release modes?  (Eventually I'll need to add Visual Studio on Windows too. )<br>
</div>
<div><br>
</div>
<div>For now, I'm following what's mentioned in the cmake FAQ and using CXX=/blah cmake, etc.
<br>
</div>
<div><br>
</div>
<div>(From: <a href="https://cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F">
https://cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F</a>) <br>
</div>
<div><br>
</div>
<div>But this is getting quite cumbersome as I'm experimenting with different flags for each compiler, and I'd rather avoid polluting my fairly clean CMakeLists file with a bunch of if/else branches to set flags.
<br>
</div>
<div><br>
</div>
<div>In the cmake manual I see reference to a -DCMAKE_TOOLCHAIN_FILE option, but this seems designed for embedded cross-compile scenarios.  (Is that right?)<br>
</div>
<div><br>
</div>
<div>(From: <a href="https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html">
https://cmake.org/cmake/help/v3.0/manual/cmake-toolchains.7.html</a>) <br>
</div>
<div><br>
</div>
<div>Basically, I'd like to succinctly choose among a set of (slightly) customized compiler choices.<br>
</div>
<div><br>
</div>
<div>For modern cmake usage what is the correct method?  Can anybody point me to a well done example for a simple case like this?
<br>
</div>
<div><br>
</div>
<div>Thank you! <br>
</div>
<div><span><span class="colour" style="color:rgb(136,136,136)">
<div>tcw<br>
</div>
</span></span><br>
</div>
<div>--<br>
</div>
<div><br>
</div>
<div>Powered by <a href="http://www.kitware.com" rel="noreferrer">www.kitware.com</a><br>
</div>
<div><br>
</div>
<div>Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer">
http://www.cmake.org/Wiki/CMake_FAQ</a><br>
</div>
<div><br>
</div>
<div>Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
</div>
<div><br>
</div>
<div>CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer">
http://cmake.org/cmake/help/support.html</a><br>
</div>
<div>CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer">
http://cmake.org/cmake/help/consulting.html</a><br>
</div>
<div>CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer">
http://cmake.org/cmake/help/training.html</a><br>
</div>
<div><br>
</div>
<div>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer">
http://www.kitware.com/opensource/opensource.html</a><br>
</div>
<div><br>
</div>
<div>Follow this link to subscribe/unsubscribe:<br>
</div>
<div><a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
</div>
</div>
</div>
</body>
</html>