<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div>Hi TCW,<br><br></div>A typical approach for this is in the top level CMakeLists.txt to have:<br><br></div><span style="font-family:monospace,monospace">include(CompilerFlags)</span><br><br></div>And then you can isolate the detection and specialization logic in a separate CompilerFlags.cmake:<br><br></div><span style="font-family:monospace,monospace">if(CMAKE_COMPILER_IS_GNUC)<br></span></div><span style="font-family:monospace,monospace">  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS" -extra --gcc-options")<br></span></div><span 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")<br></span></div><span style="font-family:monospace,monospace">elseif(MSVC)<br></span></div><span style="font-family:monospace,monospace">  if(MSVC_VERSION GREATER_THAN 1700)<br>    ...<br></span></div><span style="font-family:monospace,monospace">  elseif(...)<br>    ...<br></span></div><span style="font-family:monospace,monospace">  endif()<br></span></div><span style="font-family:monospace,monospace">endif()</span><br><br></div>And then similarly for C++.<br><div><div><div><div><div><div><div><div>  <br></div></div></div></div></div></div></div></div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr">- Chuck<br></div></div></div>
<br><div class="gmail_quote">On Tue, May 17, 2016 at 1:49 AM, TCW via CMake <span dir="ltr"><<a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hello all,</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" target="_blank">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" target="_blank">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><span><font color="#888888"><div>tcw</div></font></span><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br></blockquote></div><br></div></div>