How to retrieve a target's relative runtime destination directory?

632 Views Asked by At

Let's suppose I create a target as follows:

add_executable(app main.c)
install(TARGETS app
    RUNTIME DESTINATION some/path}
)

How do I retrieve some/path with a generator expression?

  • $<TARGET_FILE:tgt> returns the full absolute path with the installation prefix
  • $<TARGET_FILE_DIR:tgt> does the same thing and includes the filename
  • $<TARGET_FILE_NAME:tgt> only returns the filename, not the path

What am I missing? Is there a property that contains this information?

1

There are 1 best solutions below

0
On

There are neither generator expressions nor properties reflected installation path of particular target. All generator expressions you list reflect information about build location of the target.

There is $<INSTALL_PREFIX> generator expression, but it is available only when target is exported (install(EXPORT)) and only within this command invocation.

So, if you need destination directory of some target, you should manually write it. Or store it in some target's property and use $<TARGET_PROPERTY:tgt,prop> generator expression. [Note, that if your property reflects relative path, such generator expression cannot be used with install command, because this commands accepts only generator expressions which contain absolute path.]