<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 style="color:rgb(34, 34, 34)" class="colour"><span style="font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif" class="font"><span style="font-size:14px" class="size">cmake --tools=intel_16.0 ../path/to/src</span></span></span><br></div><div>or, <span style="color:rgb(34, 34, 34)" class="colour"><span style="font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif" class="font"><span style="font-size:14px" class="size">cmake --tools=gcc_5.3 ../path/to/src</span></span></span><br></div><div><span style="color:rgb(34, 34, 34)" class="colour"><span style="font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif" class="font"><span style="font-size:14px" class="size">or, </span></span></span><span style="color:rgb(34, 34, 34)" class="colour"><span style="font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif" class="font"><span style="font-size:14px" class="size"><span style="font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif" class="font"><span style="font-size:14px" class="size">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 style="font-family:monospace, monospace" class="font">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 style="font-family:monospace, monospace" class="font">if(CMAKE_COMPILER_IS_GNUC)</span><br></div></div><div><span style="font-family:monospace, monospace" class="font"> set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS" -extra --gcc-options")</span><br></div></div><div><span style="font-family:monospace, monospace" class="font">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 style="font-family:monospace, monospace" class="font">elseif(MSVC)</span><br></div></div><div><span style="font-family:monospace, monospace" class="font"> if(MSVC_VERSION GREATER_THAN 1700)<br> ...</span></div></div><div><span style="font-family:monospace, monospace" class="font"> elseif(...)<br> ...</span></div></div><div><span style="font-family:monospace, monospace" class="font"> endif()</span><br></div></div><div><span style="font-family:monospace, monospace" class="font">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 style="color:rgb(136, 136, 136)" class="colour"><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>