[CMake] Generated files and subdirectories

Tyler Roscoe tyler at cryptio.net
Fri Nov 6 10:09:39 EST 2009


On Fri, Nov 06, 2009 at 09:10:13AM +0100, Micha Renner wrote:
> Unfortunatelly this generates the make error message:
> "There is no rule to generate the target: Name of the generated
> file" (Here tm18.c see below)
> 
> ------------------------------------------
> The CMakeLists.txt files
> 
> In mainDirectory I have the following CMakeLists.txt file
> 
> PROJECT(MainProj)
> 
> ADD_SUBDIRECTORY(src2)
> ADD_SUBDIRECTORY(src)

> In src2 the CMakeLists.txt file looks like this:
>
> ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_BINARY_DIR}/tm18.c
> 		COMMAND ${CMAKE_BINARY_DIR}/generator tm18
> 		DEPENDS ${CMAKE_SOURCE_DIR}/src/tm
> 		COMMENT "...run")
> ADD_CUSTOM_TARGET(targetAdd ALL DEPENDS ${CMAKE_BINARY_DIR}/tm18.c)
> 
> and in src2 I have the following CMakeLists.txt file
> 
> SET(_src CTest.c ${CMAKE_BINARY_DIR}/tm18.c)
> 
> ADD_EXECUTABLE(${_targetname} ${_src})
> 
> SET_SOURCE_FILES_PROPERTIES(${CMAKE_BINARY_DIR}/tm18.c PROPERTIES
> GENERATED 1)

I think the problem is that the custom_command in src2 is in a different
"context" than the add_executable() where you reference tm18.c. I think
there is a bug and/or a discussion from a few months ago about this
topic but I don't remember any specifics unfortunately.

Try moving your custom_command into the CMakeLists for src and see if
that works. If it does, you can try reorganizing things. If it doesn't,
you can hope someone smarter than me has an answer :).

tyler




More information about the CMake mailing list