[CMake] add_custom_command doesn't know about target; but get_target_property does

Braden McDaniel braden at endoframe.com
Thu Aug 21 16:27:36 EDT 2014


I have the following code that executes in a top-level CMakeLists.txt 
*after* having recursed into subdirectories:

	get_target_property(TARGET_NAME ${EXPORT_TARGET} NAME)
	message(STATUS "${EXPORT_TARGET} NAME = ${TARGET_NAME}")
	add_custom_command(
		TARGET ${EXPORT_TARGET} POST_BUILD
		COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_FILE> > 
${CMAKE_BINARY_DIR}/${LIB_PATHS}/${EXPORT_TARGET}_$<CONFIG>
	)

EXPORT_TARGET is a library target defined in a subdirectory.  This 
results in the following output from CMake:

my_target NAME = my_target
CMake Warning (dev) at CMakeLists.txt:965 (add_custom_command):
   Policy CMP0040 is not set: The target in the TARGET signature of
   add_custom_command() must exist.  Run "cmake --help-policy CMP0040" 
for
   policy details.  Use the cmake_policy command to set the policy and
   suppress this warning.

   The target name "my_target" is unknown in this context.

How come get_target_property knows about the target but 
add_custom_command does not?

I am using CMake 3.0.1.

-- 
Braden McDaniel
<braden at endoframe.com>


More information about the CMake mailing list