<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Am 19.11.19 um 22:51 schrieb Craig
      Scott:<br>
    </div>
    <blockquote type="cite"
cite="mid:CA+dygYkgGQvRFVQ2x4cP4LrcC+JAZYffNW6R98=vg_fpCB8fqA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr"><br>
        </div>
        <br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">On Tue, Nov 19, 2019 at
            10:36 PM Eric Doenges <<a href="mailto:doenges@mvtec.com"
              moz-do-not-send="true">doenges@mvtec.com</a>> wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
            <div bgcolor="#FFFFFF">
              <div>Am 19.11.19 um 12:09 schrieb Stéphane Ancelot:<br>
              </div>
              <blockquote type="cite">
                <p>Hi,</p>
                <p>I have a particular target (using swig / jni) that
                  must not have -O3 -NDEBUG flags from Relase build type</p>
                <p>How can I overload this target flags ?</p>
              </blockquote>
              Since CMAKE_<lang>_FLAGS_RELEASE does not map to a
              user-visible target property, you cannot override it
              directly (anything added to the COMPILE_FLAGS property is
              appended to the command line and does not replace any of
              the compiler flags CMake sets by itself). However, you can
              redefine this variable before you create your special
              target(s), and then restore it so that other targets are
              not affected:<br>
              <p>set(_CMAKE_CXX_FLAGS_RELEASE_SAVE
                ${CMAKE_CXX_FLAGS_RELEASE})<br>
                set(CMAKE_CXX_FLAGS_RELEASE)<br>
                < add your target(s) here ><br>
                set(CMAKE_CXX_FLAGS_RELEASE
                ${_CMAKE_CXX_FLAGS_RELEASE_SAVE})<br>
              </p>
              <p>This assumes your target is C++; if it is C, simply
                replace the _CXX_ with _C_.</p>
            </div>
          </blockquote>
        </div>
        <div><br>
        </div>
        <div>Actually, no, that's not how it works. This is actually a
          great example of why projects shouldn't generally try to avoid
          manipulating CMAKE_CXX_FLAGS and should instead prefer to
          modify target or directory properties instead (not possible
          here for the original problem, but worth highlighting
          nonetheless). The (often surprising) behavior at play in the
          proposed example above is that it is not the value of the
          CMAKE_CXX_FLAGS_RELEASE variable at the time the target is
          created that matters, it's the variable's value <i>at the end
            of the directory scope</i>. You can change the variable's
          value as much as you like along the way before or after
          creating targets, but only the final value at the end of the
          scope will actually be used in the build command lines for
          targets created in that directory scope. This is rarely what
          developers expect, but that's how it works, for better or
          worse. When you start adding in calls to add_subdirectory(),
          it can get really confusing what value is getting used where,
          so take great care if your project really must modify these
          variables.</div>
      </div>
    </blockquote>
    <p>Very interesting, thanks for pointing that out. In our case
      things work because all the actual targets are in fact created in
      subdirectories. I think CMake really needs some straightforward
      way to allow you to override flags on a per-target and per-file
      basis (in our case, we need to be able to reduce the optimization
      level for individual source files to work around bugs in the Intel
      compiler's optimizer).<br>
    </p>
    <div class="moz-signature">-- <br>
      <div style="width:480px; text-align: left; font-family: Arial,
        Helvetica, sans-serif;">
        <p style="color: #062d64; font-size: 14px; text-align: left;
          font-family: Arial, Helvetica, sans-serif;">
          <b>Dr. Eric Dönges</b>
          <br>
          Senior Software Engineer
        </p>
        <p style="color: #062d64; font-size: 12px; text-align: left;
          font-family: Arial, Helvetica, sans-serif;">MVTec Software
          GmbH | Arnulfstr. 205 | 80634 Munich | Germany
          <br>
          <a style="font-size: 12px; font-family: Arial, Helvetica,
            sans-serif; color: #062d64;"
            href="mailto:mustermann@mvtec.com">doenges@mvtec.com</a> |
          Tel: +49 89 457 695-0 | <a style="font-size: 12px;
            font-family: Arial, Helvetica, sans-serif; color: #062d64;"
            href="http://www.mvtec.com">www.mvtec.com</a>
          <br>
        </p>
        <p>
          <span style="font-size: 12px; font-family: Arial, Helvetica,
            sans-serif; color: #062d64;">Find our privacy policy <a
              style="font-size: 12px; font-family: Arial, Helvetica,
              sans-serif; color: #062d64;"
              href="https://www.mvtec.com/imprint">here</a>.</span> </p>
        <p style="color: #062d64; font-size: 12px; text-align: left;
          font-family: Arial, Helvetica, sans-serif;"><img
src="https://mvtec.com/fileadmin/Redaktion/newsletter/mail-signature/newsletter-icon.png"
            valign="bottom" width="16" height="16"> <a style="font-size:
            12px; font-family: Arial, Helvetica, sans-serif; color:
            #062d64; font-weight: bold;"
            href="https://www.mvtec.com/newsletter">Sign up</a> for our
          MVTec Newsletter!</p>
        <p style="margin: 0px; color: #666; font-size: 12px; text-align:
          left; font-family: Arial, Helvetica, sans-serif;">Geschäftsführer:
          Dr. Wolfgang Eckstein, Dr. Olaf Munkelt<br>
          Amtsgericht München HRB 114695</p>
        <p style="margin: 0px; color: #666; font-size: 12px; text-align:
          left; font-family: Arial, Helvetica, sans-serif;"> </p>
        <img
src="https://www.mvtec.com/fileadmin/Redaktion/newsletter/mail-signature/mvtec-logo-line.png"
          alt="MVTec Software GmbH Logo"></div>
    </div>
  </body>
</html>