Can we change/set the export target name

Hello,

Is it possible to change a package export target’s name?

For example, if foo is my target to create a library I understand that

    install(TARGETS foo EXPORT foo_targets ...)

Will cause files:

  1. fooTargets.cmake
  2. fooTargets-<CONFIG>.cmake

to be generated.

This causes logic inside these files such as:

fooTargets.cmake:add_library(foo STATIC IMPORTED)

The problem is, we’ve us the target property OUTPUT_NAME on foo. So while foo is the target, the generated library would be bar.lib, etc.

My team wants their package searches to be for bar since that’s the library name, and there are reasons that the target cannot simply be bar.

What can you teach me for resolving this problem?

Thank you.

You can rename on export with the EXPORT_NAME target property. If you use a namespace (e.g., foo::) you can then make it show up as foo::bar with an EXPORT_NAME bar setting.

1 Like

Thank you @ben.boeckel !

I was able to follow your advice:

    set_target_properties(foo PROPERTIES EXPORT_NAME bar)
    install(TARGETS foo EXPORT foo_targets ...)

And this caused the autogenerated files to have the desired target of bar.

Thank you!