Exporting renamed/multiple-named configs

I would hand-code the OldName package to do forwarding. Something like this logic is used in VTK for deprecated components and deprecating VTK_USE_FILE. So, basically:

  • if there’s no minimum version requested, make deprecation warnings about the changes
  • if a version before the change is requested, stay quiet (because they need to do that in order to keep their minimum there); an AUTHOR_WARNING may be appropriate to let the developers know that things are afoot though
  • if a version with the new stuff is requested, error so that they migrate to the new names

Then I would provide targets under the old name:

find_package(NewName) # Forward arguments like `QUIET`, components, and/or version requests too
if (NOT NewName_FOUND)
  set(OldName_FOUND 0)
  set(OldName_NOT_FOUND_MESSAGE "NewName not found: ${NewName_NOT_FOUND_MESSAGE}")
  return ()
endif ()

if (NOT TARGET OldName::OldTarget AND TARGET NewName::NewTarget)
  add_library(OldName::OldTarget IMPORTED INTERFACE)
  set_target_properties(OldName::OldTarget PROPERTIES INTERFACE_LINK_LIBRARIES "NewName::NewTarget")
endif ()
1 Like