title: CMake: Compiler flags for each MSVC project type
body: <p>I am developing an C++ project that need to set specific compiler flags for each Visual Studio (MSVC) project configurations. We know that the configurations that CMake creates by default are these: <strong>Debug</strong>, <strong>RelWithDebInfo</strong>, <strong>Release</strong> and <strong>MinSizeRel</strong>.</p>
  <p>In my CMakeLists.txt I am trying to do something like this:</p>
  <pre><code># For each one Visual Studio configuration
  # Some specifics compiler flags for MSVC
  
  # For all RELEASE based configurations (Debug and RelWithDebInfo)
  set(MSVC_FLAGS_REL STRING &quot;/Ox /Ob2 /Oi /Ot /GF /Zc:wchar_t /MT&quot;)
  
  # For all DEBUG based configurations (Release and MinSizeRel)
  set(MSVC_FLAGS_DBG STRING &quot;/MTd /Od /Zi /RTC1 /Zc:wchar_t /GS&quot;)
  add_compile_options($&lt;$&lt;CONFIG:Debug&gt;:${MSVC_FLAGS_DBG}&gt;$&lt;$&lt;CONFIG:RelWithDebInfo&gt;:${MSVC_FLAGS_DBG}&gt;$&lt;$&lt;CONFIG:Release&gt;:${MSVC_FLAGS_REL}&gt;$&lt;$&lt;CONFIG:MinSizeRel&gt;:${MSVC_FLAGS_REL}&gt;)
  </code></pre>
  <p>However, I try to build each one configurations I noticed that the compiler flags are not been successfully set. Also, I noticed a few posts that the Generator Expressions are sometimes inadvisable in some situations.</p>
  <p>How should I properly set the compiler variables for Debug and Release based configurations?</p>