<div dir="ltr">OK right.<div>I missed the proper FAQ entry, thanks Nicholas for pointing it out.</div><div><br></div><div>Eric</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-05 12:10 GMT+02:00 Nicholas Devenish <span dir="ltr"><<a href="mailto:ndevenish@gmail.com" target="_blank">ndevenish@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
It looks like this is the issue covered in<br>
<a href="https://cmake.org/Wiki/CMake_FAQ#How_can_I_add_a_dependency_to_a_source_file_which_is_generated_in_a_subdirectory.3F" rel="noreferrer" target="_blank">https://cmake.org/Wiki/CMake_<wbr>FAQ#How_can_I_add_a_<wbr>dependency_to_a_source_file_<wbr>which_is_generated_in_a_<wbr>subdirectory.3F</a><br>
and bug <a href="https://gitlab.kitware.com/cmake/cmake/issues/14633" rel="noreferrer" target="_blank">https://gitlab.kitware.com/<wbr>cmake/cmake/issues/14633</a> ? I<br>
suppose if you are writing your own systems from scratch it's easy not<br>
to run into this, but a lot easier when converting existing<br>
complicated build systems.<br>
<br>
I kind of agree that it's easy to miss this constraint reading the<br>
documentation, but there doesn't seem to be a better suggested<br>
solution yet.<br>
<br>
Nick<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Sun, Jul 2, 2017 at 11:57 AM, Eric Noulard <<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a>> wrote:<br>
> Ok,<br>
><br>
> I reproduced your issue and I can then confirm it.<br>
> I tried several thing including:<br>
>    - generating the file is the buildtree<br>
>    - refering to the same file with another target in the same dir<br>
>    - using absolute path in the sub2/add_executable<br>
><br>
> nothing works.<br>
> it looks like a generated file cannot be referred outside the directory<br>
> where the custom command generates it ???<br>
><br>
> Here comes an archive with an example similar to the one descrived by J.<br>
> Decker.<br>
> If you build it without option it wokrs (because I used an intermediate<br>
> object lib)<br>
> If you (try to) build it with<br>
><br>
> cmake -DBROKEN=1<br>
><br>
> then it'll fails with "Cannot find source file..."<br>
><br>
> This is definitely weird and I never encountered this after +10 years of<br>
> CMake usage!!<br>
> So I guess I have always used generated file locally to build exe or lib and<br>
> then refer to the lib.<br>
> If this is the intended behaviour then it should be documented more<br>
> explicitely.<br>
><br>
> Now re-reading the doc of add_custom_command:<br>
><br>
> "This defines a command to generate specified ``OUTPUT`` file(s).<br>
> A target created in the same directory (``CMakeLists.txt`` file)<br>
> that specifies any output of the custom command as a source file<br>
> is given a rule to generate the file using the command at build time."<br>
><br>
> So the "same directory" should be underlined!! Or may be another sentence<br>
> saying that in fact you CANNOT refer to outputed files outside the<br>
> directory...<br>
><br>
> In fact it is possible to have cross-directory reference to generated file<br>
> but this is<br>
> more like a workaround. You'll have to:<br>
><br>
> define your custom_command and an associated custom target in dir1<br>
> define your exe/lib in dir2 and explicitely:<br>
>    - flag the referred cross-dir generated source as GENERATED<br>
>    - make your exe/lib depend on the cross-dir custom target in order to<br>
> trigger the file generation.<br>
><br>
><br>
> The second zip implement that workaround. This is nasty, I wouldn't do that.<br>
> Shall we open a bug for this misleading behavior or shall we open a bug for<br>
> doc update?<br>
><br>
><br>
><br>
> 2017-07-02 10:20 GMT+02:00 J Decker <<a href="mailto:d3ck0r@gmail.com">d3ck0r@gmail.com</a>>:<br>
>><br>
>> It is not generated; because it is generated during a the build phase not<br>
>> the generate phase.  So only the logical idea of the file exists.<br>
>><br>
>> On Sun, Jul 2, 2017 at 12:12 AM, Eric Noulard <<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Needless to say that your example should work but somehow CMake does not<br>
>>> see that the referred file is GENERATED.<br>
>>><br>
>>> Le 2 juil. 2017 09:11, "Eric Noulard" <<a href="mailto:eric.noulard@gmail.com">eric.noulard@gmail.com</a>> a écrit :<br>
>>>><br>
>>>> Is the referred file created?<br>
>>>> Does your actual command creating the file doing it in the source tree<br>
>>>> and not in the build tree?<br>
>>>> Are you building in-source or out of source?<br>
>>>><br>
>>>> Could you give us us a toy example which shows the issue?<br>
>>>><br>
>>>> Le 2 juil. 2017 04:32, "J Decker" <<a href="mailto:d3ck0r@gmail.com">d3ck0r@gmail.com</a>> a écrit :<br>
>>>><br>
>>>> Known issue?  Or just doesn't require a response?<br>
>>>><br>
>>>> On Wed, Jun 28, 2017 at 6:05 AM, J Decker <<a href="mailto:d3ck0r@gmail.com">d3ck0r@gmail.com</a>> wrote:<br>
>>>>><br>
>>>>> I have this chain of makefiles.  It adds a custom rule to build a<br>
>>>>> source file, and then a subdirectory cannot reference that file.<br>
>>>>><br>
>>>>> The first is added custom rule for M:/tmp/cmake-chain/sub/src/<wbr>sack.c<br>
>>>>> and then later cannot find M:/tmp/cmake-chain/sub/src/<wbr>sack.c<br>
>>>>> though it's really referencing it as<br>
>>>>> M:/tmp/cmake-chain/sub/sub2/..<wbr>/src/sack.c<br>
>>>>><br>
>>>>> tested with 3.6.0-rc4 and 3.9.0-rc5<br>
>>>>><br>
>>>>> if the add_custom_rule and add_executable are in the same makefile even<br>
>>>>> if there's a added path to make it not exactly the same source as the<br>
>>>>> 'referencing source' message logs; it works.<br>
>>>>><br>
>>>>><br>
>>>>> --- CMakeLists.txt ---<br>
>>>>> cmake_minimum_required(VERSION 2.8)<br>
>>>>><br>
>>>>> message( "Adding custom rule for<br>
>>>>> ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>src/sack.c" )<br>
>>>>>   add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>src/sack.c<br>
>>>>>   COMMAND cmake -E echo do something to make src/sack.c<br>
>>>>>   )<br>
>>>>> add_subdirectory( sub2 )<br>
>>>>> ------------------------------<wbr>-------<br>
>>>>><br>
>>>>> --- sub2/CmakeLists.txt ---<br>
>>>>> message( "referencing source ${CMAKE_CURRENT_SOURCE_DIR}/..<wbr>/src/sack.c"<br>
>>>>> )<br>
>>>>> add_executable( something ${CMAKE_CURRENT_SOURCE_DIR}/..<wbr>/src/sack.c )<br>
>>>>><br>
>>>>> ------------------------------<wbr>-------<br>
>>>>><br>
>>>>> --- Truncated output log ------<br>
>>>>> Adding custom rule for M:/tmp/cmake-chain/sub/src/<wbr>sack.c<br>
>>>>> referencing source M:/tmp/cmake-chain/sub/sub2/..<wbr>/src/sack.c<br>
>>>>> -- Configuring done<br>
>>>>> CMake Error at sub2/CMakeLists.txt:3 (add_executable):<br>
>>>>>   Cannot find source file:<br>
>>>>><br>
>>>>>     M:/tmp/cmake-chain/sub/src/<wbr>sack.c<br>
>>>>><br>
>>>>>   Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm<br>
>>>>> .hpp<br>
>>>>>   .hxx .in .txx<br>
>>>>> ------------------------------<wbr>--------<br>
>>>>><br>
>>>>><br>
>>>>> ------ Flat CmakeLists.txt which works ---------------<br>
>>>>> cmake_minimum_required(VERSION 2.8)<br>
>>>>><br>
>>>>> message( "Adding custom rule for<br>
>>>>> ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>src/sack.c" )<br>
>>>>>   add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>src/sack.c<br>
>>>>> COMMAND cmake -e echo make file.<br>
>>>>>   )<br>
>>>>><br>
>>>>> message( "referencing source ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>src/sack.c" )<br>
>>>>> add_executable( something<br>
>>>>> ${CMAKE_CURRENT_SOURCE_DIR}/<wbr>sub2/../src/sack.c )<br>
>>>>> ------------------------------<wbr>--------<br>
>>>>><br>
>>>>> ----- flat cmakelists output.... -----------<br>
>>>>> Adding custom rule for M:/tmp/cmake-chain-flat/src/<wbr>sack.c<br>
>>>>> referencing source M:/tmp/cmake-chain-flat/sub2/.<wbr>./src/sack.c<br>
>>>>> -- Configuring done<br>
>>>>> ------------------------------<wbr>--------<br>
>>>>><br>
>>>><br>
>>>><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:<br>
>>>> <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<br>
>>>> 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<br>
>>>> <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>
>>>><br>
>>>><br>
>><br>
>><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:<br>
>> <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<br>
>> 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<br>
>> <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>
><br>
><br>
><br>
><br>
> --<br>
> Eric<br>
><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:<br>
> <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<br>
> 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<br>
> <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>
</div></div></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>