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

Braden McDaniel braden at endoframe.com
Thu Aug 21 20:15:01 EDT 2014


On Thu, 2014-08-21 at 23:05 +0200, Nils Gladitz wrote:
> On 21.08.2014 22:27, Braden McDaniel wrote:
> > 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.
> >
> 
> Custom commands can only be attached to targets defined in the current 
> directory.

Ah.  Bummer.

Well, as you might have guessed, I'm trying to address an issue where
the LOCATION property of a target (EXPORT_TARGET, in the example above)
was being used.  Is there some way I can get this information about the
target that doesn't involve modifying the CMakeLists.txt in each
subdirectory where a target of interest resides?

-- 
Braden McDaniel <braden at endoframe.com>



More information about the CMake mailing list