[CMake] Help with Policy CMP0026 (disallow LOCATION target property)

Paul Smith paul at mad-scientist.net
Wed Dec 24 08:04:21 EST 2014


On Tue, 2014-12-23 at 16:59 -0500, David Cole wrote:
> Are you sure there's a problem using TARGET_FILE in your original
> context?

> You should be able to use that in a custom command in your custom
> stage_tgt target...
> 
> You have to give the name of the target for the TARGET_FILE generator
> expression, so it should work for any target that cmake knows about.
> 
> Can you point to a simplified reproducible case where this does not
> work?
> 
> Maybe there's some other complication in your real project that is
> making it seem like it's not working.... but I think it should. Can
> you send us any code?

Thanks for the reply David.

The complication is that the rule I'm trying to create that copies files
uses the destination file as the target, so I'm using the target name in
the OUTPUT section of add_custom_command.  Basically, my current
implementation is like this:

  function(stageobj target dir)
      get_property(targetpath TARGET ${target} PROPERTY LOCATION)
      get_filename_component(targetname ${targetpath} NAME)
      add_custom_command(OUTPUT "${DESTDIR}/${dir}/${targetname}"
          COMMAND "${CMAKE_COMMAND}" -E make_directory "${DESTDIR}/${dir}"
          COMMAND "${CMAKE_COMMAND}" -E copy "${targetpath}" "${DESTDIR}/${dir}"
          DEPENDS ${target}
          COMMENT "Staging ${target} to ${DESTDIR}/${dir}"
          VERBATIM)

      add_custom_target("stage_${target}" ALL DEPENDS "${DESTDIR}/${dir}/${target}")
  endfunction()

This has the very nice feature that it's a real rule, and it only fires
if needed (that is, ${target} has been updated since the last time we
copied it).

But, I can't replace "${targetname}" in the OUTPUT section with a
generator expression, because they don't seem to be allowed there:

  CMake Error at CMake/Stage.cmake:93 (add_custom_command):
    add_custom_command called with OUTPUT containing a "<".  This character is
    not allowed.

Thoughts or alternatives are welcome...



More information about the CMake mailing list