[CMake] Retrieving target's sources and libraries

Rodolfo Lima rodolfo at rodsoft.org
Fri Dec 14 07:26:54 EST 2007


Hi, I'd like to mention bug #6137 in bug tracker, where I've written a
patch to cmake (both 2.4 and 2.5-cvs) where I add a target property
(SOURCES) to get the sources assigned to a target. As I say there, I'm
using it to properly implement header precompilation because I need to
add the precompiled header as a dependency of each target's source file.

Currently there's no way (that I know of) to do that without specifying
again all sources. What I do (with SOURCES property) is:

GET_TARGET_PROPERTY(_sources ${_target} SOURCES)
FOREACH(_src ${_sources})
	SET_SOURCE_FILES_PROPERTIES(${_src} PROPERTIES OBJECT_DEPENDS
${_pch_output})
ENDFOREACH()

Is there any other way to do that? I've already considered creating a
new target for each precompiled header, then using add_dependencies to
associate this with the main target, but this gets ugly because we end
up with a lot of targets in the project. The visual studio project
panel, for instance, gets too cluttered.

Another option would be to associate the output of a add_custom_command
(where I generate the precompiled header) to the main target using
add_dependencies, but this function only accepts targets, not files, as
one would correctly presume.

Regards,
rod



More information about the CMake mailing list