add_library(foo SHARED foo.h foo.cpp)
install(TARGETS foo EXPORT FooTargets DESTINATION
RUNTIME DESTINATION bin LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
DESTINATION cmake RENAME FooConfig.cmake)
install(EXPORT FooTargets DESTINATION cmake)
FooConfig.cmake which is generated with
Foo package provides IMPORTED library target
foo, which is used by
Bar for link with.
CMake has a notion about "Map from project configuration to IMPORTED target’s configuration.", which is determined by properties MAP_IMPORTED_CONFIG_<CONFIG>:
Set this to the list of configurations of an imported target that may be used for the current project’s configuration. Targets imported from another project may not provide the same set of configuration names available in the current project. Setting this property tells CMake what imported configurations are suitable for use when building the <CONFIG> configuration. The first configuration in the list found to be provided by the imported target is selected. If this property is set and no matching configurations are available, then the imported target is considered to be not found.
You may add to the end of script
FooConfig.cmake.in something like
set_target_property(foo PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO "prohibited")
so it will be impossible to link with
foo in RelWithDebInfo configuration (because
foo target doesn't provide configuration named "prohibited").