[CMake] CmakeLists chain cannot find source added with add_custom_command

Eric Noulard eric.noulard at gmail.com
Sun Jul 2 03:12:33 EDT 2017


Needless to say that your example should work but somehow CMake does not
see that the referred file is GENERATED.

Le 2 juil. 2017 09:11, "Eric Noulard" <eric.noulard at gmail.com> a écrit :

> Is the referred file created?
> Does your actual command creating the file doing it in the source tree and
> not in the build tree?
> Are you building in-source or out of source?
>
> Could you give us us a toy example which shows the issue?
>
> Le 2 juil. 2017 04:32, "J Decker" <d3ck0r at gmail.com> a écrit :
>
> Known issue?  Or just doesn't require a response?
>
> On Wed, Jun 28, 2017 at 6:05 AM, J Decker <d3ck0r at gmail.com> wrote:
>
>> I have this chain of makefiles.  It adds a custom rule to build a source
>> file, and then a subdirectory cannot reference that file.
>>
>> The first is added custom rule for M:/tmp/cmake-chain/sub/src/sack.c
>> and then later cannot find M:/tmp/cmake-chain/sub/src/sack.c
>> though it's really referencing it as M:/tmp/cmake-chain/sub/sub2
>> /../src/sack.c
>>
>> tested with 3.6.0-rc4 and 3.9.0-rc5
>>
>> 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.
>>
>>
>> --- CMakeLists.txt ---
>> cmake_minimum_required(VERSION 2.8)
>>
>> message( "Adding custom rule for ${CMAKE_CURRENT_SOURCE_DIR}/src/sack.c"
>> )
>>   add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/sack.c
>>   COMMAND cmake -E echo do something to make src/sack.c
>>   )
>> add_subdirectory( sub2 )
>> -------------------------------------
>>
>> --- sub2/CmakeLists.txt ---
>> message( "referencing source ${CMAKE_CURRENT_SOURCE_DIR}/../src/sack.c" )
>> add_executable( something ${CMAKE_CURRENT_SOURCE_DIR}/../src/sack.c )
>>
>> -------------------------------------
>>
>> --- Truncated output log ------
>> Adding custom rule for M:/tmp/cmake-chain/sub/src/sack.c
>> referencing source M:/tmp/cmake-chain/sub/sub2/../src/sack.c
>> -- Configuring done
>> CMake Error at sub2/CMakeLists.txt:3 (add_executable):
>>   Cannot find source file:
>>
>>     M:/tmp/cmake-chain/sub/src/sack.c
>>
>>   Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
>>   .hxx .in .txx
>> --------------------------------------
>>
>>
>> ------ Flat CmakeLists.txt which works ---------------
>> cmake_minimum_required(VERSION 2.8)
>>
>> message( "Adding custom rule for ${CMAKE_CURRENT_SOURCE_DIR}/src/sack.c"
>> )
>>   add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/sack.c
>> COMMAND cmake -e echo make file.
>>   )
>>
>> message( "referencing source ${CMAKE_CURRENT_SOURCE_DIR}/src/sack.c" )
>> add_executable( something ${CMAKE_CURRENT_SOURCE_DIR}/sub2/../src/sack.c
>> )
>> --------------------------------------
>>
>> ----- flat cmakelists output.... -----------
>> Adding custom rule for M:/tmp/cmake-chain-flat/src/sack.c
>> referencing source M:/tmp/cmake-chain-flat/sub2/../src/sack.c
>> -- Configuring done
>> --------------------------------------
>>
>>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensou
> rce/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170702/b87490e9/attachment-0001.html>


More information about the CMake mailing list