<div dir="ltr">Ok,<div><br></div><div>I reproduced your issue and I can then confirm it.</div><div>I tried several thing including:</div><div>   - generating the file is the buildtree</div><div>   - refering to the same file with another target in the same dir</div><div>   - using absolute path in the sub2/add_executable</div><div><br></div><div>nothing works.</div><div>it looks like a generated file cannot be referred outside the directory where the custom command generates it ???</div><div><br></div><div>Here comes an archive with an example similar to the one descrived by J. Decker.<br></div><div>If you build it without option it wokrs (because I used an intermediate object lib)</div><div>If you (try to) build it with</div><div><br></div><div>cmake -DBROKEN=1 </div><div><br></div><div>then it'll fails with "Cannot find source file..."</div><div><br></div><div>This is definitely weird and I never encountered this after +10 years of CMake usage!!</div><div>So I guess I have always used generated file locally to build exe or lib and then refer to the lib.</div><div>If this is the intended behaviour then it should be documented more explicitely.</div><div><br></div><div>Now re-reading the doc of add_custom_command:</div><div><br></div><div>"This defines a command to generate specified ``OUTPUT`` file(s).</div><div>A target created in the same directory (``CMakeLists.txt`` file)</div><div>that specifies any output of the custom command as a source file</div><div>is given a rule to generate the file using the command at build time."</div><div><br></div><div>So the "same directory" should be underlined!! Or may be another sentence</div><div>saying that in fact you CANNOT refer to outputed files outside the directory...</div><div><br></div><div>In fact it is possible to have cross-directory reference to generated file but this is </div><div>more like a workaround. You'll have to:</div><div><br></div><div>define your custom_command and an associated custom target in dir1</div><div>define your exe/lib in dir2 and explicitely:</div><div>   - flag the referred cross-dir generated source as GENERATED</div><div>   - make your exe/lib depend on the cross-dir custom target in order to trigger the file generation.</div><div><br></div><div><br></div><div>The second zip implement that workaround. This is nasty, I wouldn't do that.</div><div>Shall we open a bug for this misleading behavior or shall we open a bug for doc update?</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-02 10:20 GMT+02:00 J Decker <span dir="ltr"><<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">It is not generated; because it is generated during a the build phase not the generate phase.  So only the logical idea of the file exists.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 2, 2017 at 12:12 AM, Eric Noulard <span dir="ltr"><<a href="mailto:eric.noulard@gmail.com" target="_blank">eric.noulard@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Needless to say that your example should work but somehow CMake does not see that the referred file is GENERATED.</div><div class="m_-2265684568344764062HOEnZb"><div class="m_-2265684568344764062h5"><div class="gmail_extra"><br><div class="gmail_quote">Le 2 juil. 2017 09:11, "Eric Noulard" <<a href="mailto:eric.noulard@gmail.com" target="_blank">eric.noulard@gmail.com</a>> a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Is the referred file created?</div><div dir="auto">Does your actual command creating the file doing it in the source tree and not in the build tree?</div><div dir="auto">Are you building in-source or out of source?</div><div dir="auto"><br></div><div dir="auto">Could you give us us a toy example which shows the issue?<br><div class="gmail_extra" dir="auto"><br><div class="gmail_quote">Le 2 juil. 2017 04:32, "J Decker" <<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>> a écrit :<br type="attribution"><blockquote class="m_-2265684568344764062m_6779824273821889637m_-2123762806676511881quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Known issue?  Or just doesn't require a response?  </div><div class="m_-2265684568344764062m_6779824273821889637m_-2123762806676511881elided-text"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 28, 2017 at 6:05 AM, J Decker <span dir="ltr"><<a href="mailto:d3ck0r@gmail.com" target="_blank">d3ck0r@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have this chain of makefiles.  It adds a custom rule to build a source file, and then a subdirectory cannot reference that file.<br><div><br></div><div>The first is added custom rule for M:/tmp/cmake-chain/sub/src<wbr>/sack.c </div><div>and then later cannot find M:/tmp/cmake-chain/sub/sr<wbr>c/sack.c</div><div>though it's really referencing it as M:/tmp/cmake-chain/sub/sub2<wbr>/../src/sack.c</div><div><br></div><div>tested with 3.6.0-rc4 and 3.9.0-rc5</div><div><br></div><div>if the add_custom_rule and add_executable are in the same makefile even if there's a added path to make it not exactly the same source as the 'referencing source' message logs; it works.  </div><div><br></div><div><br></div><div>--- CMakeLists.txt ---</div><div><div><div>cmake_minimum_required(VERSION 2.8)</div></div><div><br></div><div>message( "Adding custom rule for ${CMAKE_CURRENT_SOURCE_DIR}/sr<wbr>c/sack.c" )</div><div>  add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/sr<wbr>c/sack.c</div><div>  <span class="m_-2265684568344764062m_6779824273821889637m_-2123762806676511881m_2891761761258300072m_-6886915258924704504gmail-Apple-tab-span" style="white-space:pre-wrap">                        </span>COMMAND cmake -E echo do something to make src/sack.c</div><div>  )                                   </div><div>add_subdirectory( sub2 )</div></div><div>------------------------------<wbr>-------<br></div><div><br></div><div>--- sub2/CmakeLists.txt ---</div><div><div>message( "referencing source ${CMAKE_CURRENT_SOURCE_DIR}/..<wbr>/src/sack.c" )</div><div>add_executable( something ${CMAKE_CURRENT_SOURCE_DIR}/..<wbr>/src/sack.c )</div></div><div><br></div><div>------------------------------<wbr>-------</div><div><br></div><div>--- Truncated output log ------</div><div><div>Adding custom rule for M:/tmp/cmake-chain/sub/src/sac<wbr>k.c</div><div>referencing source M:/tmp/cmake-chain/sub/sub2/..<wbr>/src/sack.c</div><div>-- Configuring done</div><div>CMake Error at sub2/CMakeLists.txt:3 (add_executable):</div><div>  Cannot find source file:</div><div><br></div><div>    M:/tmp/cmake-chain/sub/src/sac<wbr>k.c</div><div><br></div><div>  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp</div><div>  .hxx .in .txx</div></div><div>------------------------------<wbr>--------</div><div><br></div><div><br></div><div>------ Flat CmakeLists.txt which works ---------------</div><div><div>cmake_minimum_required(VERSION 2.8)</div><div><br></div><div>message( "Adding custom rule for ${CMAKE_CURRENT_SOURCE_DIR}/sr<wbr>c/sack.c" )</div><div>  add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/sr<wbr>c/sack.c</div><div><span class="m_-2265684568344764062m_6779824273821889637m_-2123762806676511881m_2891761761258300072m_-6886915258924704504gmail-Apple-tab-span" style="white-space:pre-wrap">           </span>COMMAND cmake -e echo make file.</div><div>  )                                   </div><div><br></div><div>message( "referencing source ${CMAKE_CURRENT_SOURCE_DIR}/sr<wbr>c/sack.c" )</div><div>add_executable( something ${CMAKE_CURRENT_SOURCE_DIR}/su<wbr>b2/../src/sack.c )</div></div><div><div>------------------------------<wbr>--------</div></div><div><br></div><div>----- flat cmakelists output.... -----------</div><div><div><div>Adding custom rule for M:/tmp/cmake-chain-flat/src/sa<wbr>ck.c</div><div>referencing source M:/tmp/cmake-chain-flat/sub2/.<wbr>./src/sack.c</div><div>-- Configuring done</div></div></div><div><div>------------------------------<wbr>--------</div></div><div><br></div></div>
</blockquote></div><br></div>
</div><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMak<wbr>e_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/su<wbr>pport.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/co<wbr>nsulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/tr<wbr>aining.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/cmake</a><br></blockquote></div><br></div></div></div>
</blockquote></div></div>
</div></div></blockquote></div><br></div>
</div></div><br>--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/<wbr>CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/<wbr>training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/<wbr>opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/cmake</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Eric<br></div></div></div></div></div>
</div>