<div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 14, 2019 at 1:09 PM Kim Walisch <<a href="mailto:kim.walisch@gmail.com">kim.walisch@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Based on feedback from Craig Scott I now use the following code:<br><br>if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.9)<br> get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)<br>elseif(CMAKE_CONFIGURATION_TYPES)<br> set(isMultiConfig TRUE)<br>endif()<br><br>if(NOT isMultiConfig AND NOT CMAKE_BUILD_TYPE)<br> set(CMAKE_BUILD_TYPE Release CACHE STRING<br><div> "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)<br>endif()</div><div><br></div><div>This code sets CMAKE_BUILD_TYPE only for single configuration generators (like GNU make or Ninja) because multi configuration generators (like Xcode or Visual Studio) generally ignore CMAKE_BUILD_TYPE. For an in depth explanation please refer to chapter 13 of Scott's excellent "Professional CMake" book (<a href="https://crascit.com/professional-cmake" target="_blank">https://crascit.com/professional-cmake</a>).<br></div><div><br></div><div>Regards,</div><div>Kim</div></div></div><br></blockquote><div><br></div><div></div><div>There is nothing particularly wrong with setting
CMAKE_BUILD_TYPE to Release in a CMakeLists.txt except that then you can't use the default settings of when it is not set.<br></div><div><br></div><div>In general a CMakeLists.txt that supports Multi-configuration generators will use the generator expressions to determine the configuration type. In those cases
CMAKE_BUILD_TYPE is not used and doesn't show up in any script.</div><div><br></div><div>Other scripts may check if
CMAKE_BUILD_TYPE is set to enable additional flags or add in special files and those scripts won't usually work as expected with a multi-configuration generator because Debug / Release can be chosen at build time.<br></div><div><br></div><div>If you have to work around something that is going to break because it expects
CMAKE_BUILD_TYPE to never be set then it won't work for single configuration generators when the user sets CMAKE_BUILD_TYPE
to Release.<br></div><div><br></div><div>Both types of generators are available for use when working with clang on windows.<br></div></div><div class="gmail_quote"><br></div><div class="gmail_quote">You never mentioned what part didn't work or what generator you are using, but if only setting
CMAKE_BUILD_TYPE when a single configuration generator is used gets you past the problem then that works too.<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Regards,</div><div class="gmail_quote">F<br></div><div class="gmail_quote"><br></div></div></div>