MantisBT - CMake
View Issue Details
0014899CMakeCMakepublic2014-04-28 08:222014-11-03 08:38
Kiron 
Stephen Kelly 
normalminoralways
closedfixed 
Windows7
CMake 2.8.12.2 
CMake 3.1CMake 3.1 
0014899: $<TARGET_PROPERTY:prop> with add_custom_target does not work
When using the $<TARGET_PROPERTY:FOO> generator expression inside an add_custom_target command the following error is produced:

CMake Error at CMakeLists.txt:6 (add_custom_target):
  Error evaluating generator expression:

    $<TARGET_PROPERTY:FOO>

  $<TARGET_PROPERTY:prop> may only be used with targets. It may not be used
  with add_custom_command. Specify the target to read a property from using
  the $<TARGET_PROPERTY:tgt,prop> signature instead.

I would expect that with add_custom_target command the short hand form should work (like error message says already, ... may only be used with targets).
Save this as a CMakeLists.txt and run cmake:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(Foo NONE)

add_custom_target(foo
    COMMAND ${CMAKE_COMMAND} -E echo $<TARGET_PROPERTY:FOO>
)

set_property(TARGET foo PROPERTY FOO "foobar")
Problem exists with cmake version 2.8.12.1, 3.0.20140422-g9f9532, and 3.0.20140424-gb4aa99
No tags attached.
Issue History
2014-04-28 08:22KironNew Issue
2014-04-29 10:46Brad KingNote Added: 0035802
2014-04-29 17:08Stephen KellyNote Added: 0035806
2014-04-30 04:12KironNote Added: 0035807
2014-04-30 08:34Brad KingAssigned To => Stephen Kelly
2014-04-30 08:34Brad KingStatusnew => assigned
2014-04-30 08:34Brad KingTarget Version => CMake 3.1
2014-05-28 17:06Stephen KellyNote Added: 0035961
2014-05-28 17:06Stephen KellyStatusassigned => resolved
2014-05-28 17:06Stephen KellyFixed in Version => CMake 3.1
2014-05-28 17:06Stephen KellyResolutionopen => fixed
2014-11-03 08:38Robert MaynardNote Added: 0037150
2014-11-03 08:38Robert MaynardStatusresolved => closed

Notes
(0035802)
Brad King   
2014-04-29 10:46   
The wording of the error message is not precise enough. Currently this expression does not work for custom commands at all, even those that are commands in add_custom_target.

I do not think the implicit form $<TARGET_PROPERTY> with no target name makes sense but the expression with an explicit target name as in the example could be made to work. Steve, is there a reason context->HeadTarget is needed when an explicit target name is available? Is that so that the lookup can occur in the right context? Isn't having the current cmMakefile enough?
(0035806)
Stephen Kelly   
2014-04-29 17:08   
The long form with the explicit target name does currently work, afaik.
(0035807)
Kiron   
2014-04-30 04:12   
The long form does work indeed. The documentation/error message is confusing, because it says it works only with targets. The add_custom_target command has target it its name. So I expected that the short form work as well.

This is just a minor issue, but I think the error message / documentation should be updated that the short form works with all targets except of targets created by add_custom_target.
(0035961)
Stephen Kelly   
2014-05-28 17:06   
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=a1d758e9 [^]
(0037150)
Robert Maynard   
2014-11-03 08:38   
Closing resolved issues that have not been updated in more than 4 months.