<div dir="ltr">If you set directory property at the top level CMakeList.txt, before any target definition, all targets will inherit this value.<div><br></div><div>And, because property 'COMPILE_OPTIONS' supports generator expressions (see <a href="https://cmake.org/cmake/help/v3.12/manual/cmake-generator-expressions.7.html">https://cmake.org/cmake/help/v3.12/manual/cmake-generator-expressions.7.html</a>), you can specify:</div><div><br></div><div>add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/MP>")</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">Le mar. 11 sept. 2018 à 19:19, Michael Jackson <<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_1457825294052222216WordSection1"><p class="MsoNormal">Hmm. The idea for the “/MP” flags for those that don’t use Visual Studio is that it will inform the compiler to use all the cores on the system to compile. Much like Ninja does automatically and “make -jN” does for makefiles.<u></u><u></u></p><p class="MsoNormal">Essentially I want to automatically add the “/MP” flag anytime that I configure using Visual Studio (2015/2017) as the generator. I guess I could put the append string fairly high up in the CMake hierarchy. I am not seeing a property (from the first link you sent) that would allow me to do that.<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal"><span style="color:black">--<u></u><u></u></span></p><p class="MsoNormal"><span style="color:black">Michael Jackson | Owner, President<u></u><u></u></span></p><p class="MsoNormal"><span style="color:black"> BlueQuartz Software<u></u><u></u></span></p><p class="MsoNormal"><span style="color:black">[e] <a href="mailto:mike.jackson@bluequartz.net" target="_blank"><span style="color:purple">mike.jackson@bluequartz.net</span></a><u></u><u></u></span></p></div><p class="MsoNormal"><span style="color:black">[w] <a href="http://www.bluequartz.net" target="_blank"><span style="color:#0563c1">www.bluequartz.net</span></a></span><u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">Marc CHEVRIER <<a href="mailto:marc.chevrier@gmail.com" target="_blank">marc.chevrier@gmail.com</a>><br><b>Date: </b>Tuesday, September 11, 2018 at 1:04 PM<br><b>To: </b>Michael Jackson <<a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a>><br><b>Cc: </b>CMake <<a href="mailto:cmake@cmake.org" target="_blank">cmake@cmake.org</a>><br><b>Subject: </b>Re: [CMake] Appending to CMAKE_CXX_FLAGS<u></u><u></u></span></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">The best approach is to use properties (see <a href="https://cmake.org/cmake/help/git-master/manual/cmake-properties.7.html" target="_blank">https://cmake.org/cmake/help/git-master/manual/cmake-properties.7.html</a>).<u></u><u></u></p><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">At directory level and target level you can use property 'COMPILE_OPTIONS'. These properties can be updated using, respectively 'add_compile_options' and 'target_compile_options'.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Be aware that variable 'CMAKE_CXX_FLAGS' is a string so to extend it you have to use:<u></u><u></u></p></div><div><p class="MsoNormal">string(APPEND CMAKE_CXX_FLAGS "flag1 flag2")<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">Le mar. 11 sept. 2018 à 17:58, Michael Jackson <<a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a>> a écrit :<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><div><div><p class="MsoNormal">What is the “modern” way to append to CMAKE_CXX_FLAGS? This is the logic that I would like:<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">If (MSVC)<u></u><u></u></p><p class="MsoNormal"> Set(CMAKE_CXX_FLAGS ${ CMAKE_CXX_FLAGS} “/MP”)<u></u><u></u></p><p class="MsoNormal">Endif()<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I have always heard that appending to the compile flags in this way is “bad”. What is the best practice for doing this?<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Thanks<u></u><u></u></p><p class="MsoNormal"><span style="color:black">--</span><u></u><u></u></p><p class="MsoNormal"><span style="color:black">Michael Jackson | Owner, President</span><u></u><u></u></p><p class="MsoNormal"><span style="color:black"> BlueQuartz Software</span><u></u><u></u></p><p class="MsoNormal"><span style="color:black">[e] <a href="mailto:mike.jackson@bluequartz.net" target="_blank"><span style="color:purple">mike.jackson@bluequartz.net</span></a></span><u></u><u></u></p><p class="MsoNormal"><span style="color:black">[w] <a href="http://www.bluequartz.net" target="_blank"><span style="color:#0563c1">www.bluequartz.net</span></a></span><u></u><u></u></p></div></div><p class="MsoNormal">-- <br><br>Powered by <a href="http://www.kitware.com" 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" 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" target="_blank">http://cmake.org/cmake/help/support.html</a><br>CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" 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" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="https://cmake.org/mailman/listinfo/cmake" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><u></u><u></u></p></blockquote></div></div></div>
</blockquote></div>