[CMake] Generated files and subdirectories

Micha Renner Micha.Renner at t-online.de
Fri Nov 6 03:10:13 EST 2009


In the F&Q Setction there is a excellent example how to handle generated
files in a subdirectory.

The structure is:
	mainDirectory (CMakeLists.txt)
	+---- ADD_SUBDIRECTORY(src1) (generates the file)
	|
	+---- Process the file

This works also for this structure
	mainDirectory (CMakeLists.txt)
	+---- generate the file
	|
	+---- ADD_SUBDIRECTORY(src1) process the file

>From this I concluded the following structure should be possible

	mainDirectory(CMakeLists.txt)
	+---- ADD_SUBDIRETCORY(src2) generate the file
	|
	+---- ADD_SUBDIRECTORY(src1) process the file

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)

So really logical is this not.

Greetings
Micha


------------------------------------------
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:

PROJECT(T)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
CMAKE_POLICY(VERSION 2.6)

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

PROJECT(Tm2)
SET(_targetname ULS)
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)

TARGET_LINK_LIBRARIES(${_targetname} ${GLIB_LIBRARY})
ADD_DEPENDENCIES(${_targetname} targetAdd)





More information about the CMake mailing list