[CMake] Outputs from add_custom_command not global?

Tyler Roscoe tyler at cryptio.net
Sat Mar 28 14:21:59 EDT 2009


On Sat, Mar 28, 2009 at 12:16:21AM -0600, James Bigler wrote:
> I have an add_custom_command in a subdirectory, and I'm trying to use
> that output as a dependency in a parent directory.
> 
> Unfortunately, the parent directory doesn't see that I made a rule
> (add_custom_command) for the file in the subdirectory.
> 
> 
> top level CMakeLists.txt:
> ...
> add_subdirectory(sub1)
> 
> add_custom_target(generate ALL
>   DEPENDS ${CMAKE_BINARY_DIR}/myfile.txt
>   )
> 
> sub1/CMakeLists.txt:
> add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/myfile.txt
>   COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/genmyfile.cmake
>   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
>   )

I would just do the add_custom_target in the same CMakeLists where you
do the add_custom_command. That target will still be available from your
top-level CMakeLists. I use this approach all over the place.

tyler


More information about the CMake mailing list