[CMake] add_custom_command doesn't know about target; but get_target_property does
Nils Gladitz
nilsgladitz at gmail.com
Thu Aug 21 17:05:00 EDT 2014
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.
Nils
More information about the CMake
mailing list