Behavior of CMake installed export files with multiple configurations

I have a C project which depends on a set of various other components. These components also use CMake for their build system and have installation directives similar to the following:

add_library(libfoo STATIC)
# ... stuff defining properties and sources for libfoo ...
install(TARGETS libfoo EXPORT libfooTargets FILE_SET HEADERS)
install(EXPORT libfooTargets FILE "libfooTargets.cmake" NAMESPACE foo:: DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libfoo")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/libfooConfig.cmake" "include(\"$\{CMAKE_CURRENT_LIST_DIR\}/libfooTargets.cmake\")\n\n")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libfooConfig.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libfoo")

This permits me to construct a superbuild or manually install each dependency prior to building the main project which finds the components using find_package(). However, there are a few things which I don’t understand and would like feedback on:

  1. When I build and install multiple configurations of “libfoo”, it will create target files “libfooTargets-{config}.cmake” for each installed configuration. The libfooTargets.cmake effectively globs all these in and each sets properties on the libfoo imported library target including the IMPORTED_LOCATION_{config} property. But, by default, the output name property of the target is the same for all configurations. This means that if I build and install a debug version of libfoo, it will install the library and “libfooTargets-debug.cmake”; then if I build and install a release version, it will overwrite the installed library and install “libfooTargets-release.cmake”. Both of the metadata files will point to the same library. This can be rectified by adding something like the following:
set_target_properties(libfoo PROPERTIES OUTPUT_NAME "libfoo$<$<NOT:$<CONFIG:Release>>:_$<LOWER_CASE:$<CONFIG>>>")

But it seems a bit strange that I have to add that? Have I misunderstood something?

  1. Even though CMake supports writing different target files for different configurations, from what I can tell, you cannot select what configuration you want to use. find_package() mentions a CONFIGS argument, but this expects filenames - not configurations. From what I can tell, the preferred configuration of the package found using find_package() will be the configuration of the project being built if it is supported. This makes complete sense given how find_package() actually constructs the imported target as mentioned in (1) via the IMPORTED_LOCATION_XYZ properties.

    So this implies that if I wanted to build a debug version of my project with a release version of a dependency, the only way I can achieve this is by ensuring that only a release version of the dependency is installed in the prefix path. If a debug is installed, it will be used.

  2. I think all of this boils down to: why does CMake support installing multiple configurations of the same library into the system? How is this functionality expected to be used?

Thanks for any insights!