[CMake] CmakeLists chain cannot find source added with add_custom_command

J Decker d3ck0r at gmail.com
Sat Jul 1 22:31:47 EDT 2017


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
> --------------------------------------
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20170701/a8f9db14/attachment.html>


More information about the CMake mailing list