<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 14, 2019 at 12:53 PM frodak17 <<a href="mailto:frodak17@gmail.com">frodak17@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"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 14, 2019 at 1:13 AM Paul Smith <<a href="mailto:paul@mad-scientist.net" target="_blank">paul@mad-scientist.net</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">I have a situation where I've created a custom command to generate .cpp<br>
files to be compiled (in my case running bison/flex).<br>
<br>
I'm using CMake 3.13.4<br>
<br>
  set(MyParserOutput<br>
      ${OUT_DIR}/MyParser.tab.cpp<br>
      ${OUT_DIR}/MyParser.tab.hpp)<br>
<br>
  add_custom_target(MyGenParser DEPENDS ${MyParserOutput})<br>
<br>
Then I have two different libraries, both depending on this:<br>
<br>
  add_library(OneLib STATIC ${MyParserOutput} ...)<br>

  add_dependencies(OneLib MyGenparser)<br>
<br>
<br>
  add_library(TwoLib STATIC ${MyParserOutput} ...)<br>

  add_dependencies(TwoLib MyGenparser)<br>
<br>
<br></blockquote><div>From add_custom_command() <br></div><div>Do not list the output in more than one independent target that
may build in parallel or the two instances of the rule may conflict
(instead use the <span class="gmail-m_4849148754294519081gmail-target" id="gmail-m_4849148754294519081gmail-index-0-command:add_custom_target"></span><a class="gmail-m_4849148754294519081gmail-reference gmail-m_4849148754294519081gmail-internal" href="https://cmake.org/cmake/help/v3.14/command/add_custom_target.html#command:add_custom_target" title="add_custom_target" target="_blank"><code class="gmail-m_4849148754294519081gmail-xref gmail-m_4849148754294519081gmail-cmake gmail-m_4849148754294519081gmail-cmake-command gmail-m_4849148754294519081gmail-docutils gmail-m_4849148754294519081gmail-literal gmail-m_4849148754294519081gmail-notranslate"><span class="gmail-m_4849148754294519081gmail-pre">add_custom_target()</span></code></a> command to drive the
command and make the other targets depend on that one)</div><div><br></div><div>Removing ${MyParserOutput} from both add_library() should fix the issue.</div><div><br></div><div>Best regards,</div><div>F<br></div></div></div></blockquote><div><br></div><div>Sorry, It didn't register at first that about the cpp file that needs to get compiled into the library.<br></div><div><br></div><div>That makes it a little more complicated.</div><div><br></div><div>In that case you need to keep ${MyParserOutput} and set the GENERATED properties for the files.</div><div><br></div><div>Also the building the custom target needs to be done in a separate directory as the add_custom_commands() need to be in a different CMakeLists.txt file from the libraries.  Otherwise the rules get pulled into the libraries and cause the commands to be run multiple times. <br></div><div><br></div><div><br></div><div><br></div></div></div>