<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <div class="moz-cite-prefix">Am 10.02.20 um 14:23 schrieb Kyle
      Edwards via CMake:<br>
    </div>
    <blockquote type="cite"
      cite="mid:1581341028.31213.1.camel@kitware.com">
      <pre class="moz-quote-pre" wrap="">On Mon, 2020-02-10 at 12:49 +0000, hex wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">hello,

My build step is not thread-safe (the instruction in the COMMAND
part). Every build step depends on one source file:

add_custom_command(
        DEPENDS on_source.file
        OUTPUT
                object_file_for_source_file
        COMMAND not-thread-safe-compiler --build on_source.file
        COMMENT
                "Building Source object"
)

add_custom_target DEPENDS on OUTPUT from all custom command's, but in
order to prevent parallel execution when cmake is called:

cmake --build . --target all -j30

I need to build each step in any order, but still not as a dependency
as this would trigger unnecessary recompilation. Using
MAIN_DEPENDENCY defines hierarchical dependency, but this won't help
in this situation.

I cannot figure out how to prevent parallel execution of COMMAND in
CMake. The only option I see is a single command

add_custom_target(tgt
        DEPENDS on_all_source.files
        COMMAND not-thread-safe-compiler --build on_source1.file
        COMMAND not-thread-safe-compiler --build on_source2.file
        COMMAND not-thread-safe-compiler --build on_source3.file
        . . .
        COMMENT
                "Building target"
)

this would rebuild every source, though.

How do I set this up?

thank you
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
It sounds like you want order-only dependencies: dependencies the
command waits for before building, but whose changes do not actually
trigger a rebuild. As far as I know, add_custom_command() doesn't have
support for this - perhaps it could be added.</pre>
    </blockquote>
    <p>Actually, I think it kind of does, at least with the Ninja
      generator. If you do something like</p>
    <p>add_custom_output(OUTPUT fileA COMMAND ...)<br>
      add_custom_target(fileA_target DEPENDS fileA)</p>
    <p>add_custom_output(OUTPUT fileB DEPENDS fileA COMMAND ...)<br>
      add_custom_output(OUTPUT fileC DEPENDS fileA_target COMMAND ...)</p>
    <p>then both fileB and fileC will depend on fileA existing, but
      fileC will not be rebuilt if fileA changes, while fileB will be.<br>
    </p>
    <p>Disclaimer - I couldn't find this behavior described in the
      documentation, but it is what I've observed after spending
      extensive amounts of time messing about with add_custom_command()
      and add_custom_target() to build the documentation to our product
      with CMake 3.16. Also, I've only tested this with the Ninja
      generator, so it may behave differently with other generators.</p>
    <p>With kind regards,<br>
      Eric Dönges<br>
    </p>
    <blockquote type="cite"
      cite="mid:1581341028.31213.1.camel@kitware.com">
    </blockquote>
    <div class="moz-signature">
      <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:doenges@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. 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>