[cmake-developers] target-LOCATION-policy topic

Brad King brad.king at kitware.com
Fri Oct 11 15:27:39 EDT 2013


On 10/11/2013 03:21 PM, Stephen Kelly wrote:
> Brad King wrote:
>> Can the policy NEW behavior instead be to return the LOCATION
>> as a $<TARGET_FILE:...> generator expression?
> 
> I don't know. That seems like a lot of magic and bound to break existing 
> code.
> 
>  get_property(loc TARGET myexe PROPERTY LOCATION)
>  file(WRITE "some_script.bat" "./${loc}")

Yes, but that code will get the policy warning until someone
reads the policy documentation, sets it to NEW, and then
takes responsibility for using the new behavior properly.

OTOH, there is too much danger of setting it in one place
and having that silence the warning in other places instead
of generating an error on them.

Instead projects can do

  if(NOT CMAKE_VERSION VERSION_LESS 2.8.4)
    # use $<TARGET_FILE:...>
  else()
    # use LOCATION property
  endif()

to support all versions regardless of the policy setting.
It is more verbose but more explicit, and projects can
potentially switch to this approach right now even before
the policy is introduced.

-Brad



More information about the cmake-developers mailing list