Split lib target types in their own export groups

This allows for the non-primary library to be missing in the Config.cmake file, e.g. if the devel files have a separate static-devel package

Signed-off-by: Cristian Le <git@lecris.dev>
This commit is contained in:
Cristian Le
2025-09-23 10:29:44 +02:00
parent ee9b5f4371
commit eb062bc339
3 changed files with 32 additions and 29 deletions
+15 -12
View File
@@ -11,21 +11,24 @@ write_basic_package_version_file(
COMPATIBILITY SameMajorVersion
)
# Export targets for build directory
export(EXPORT zstdExports
FILE "${CMAKE_CURRENT_BINARY_DIR}/zstdTargets.cmake"
NAMESPACE zstd::
)
# Configure package for installation
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/zstd)
# Install exported targets
install(EXPORT zstdExports
FILE zstdTargets.cmake
NAMESPACE zstd::
DESTINATION ${ConfigPackageLocation}
)
foreach(target_suffix IN ITEMS "_shared" "_static" "")
if(TARGET "libzstd${target_suffix}")
# Export targets for build directory
export(EXPORT "zstdExports${target_suffix}"
FILE "${CMAKE_CURRENT_BINARY_DIR}/zstdTargets${target_suffix}.cmake"
NAMESPACE zstd::
)
# Install exported targets
install(EXPORT "zstdExports${target_suffix}"
FILE "zstdTargets${target_suffix}.cmake"
NAMESPACE zstd::
DESTINATION ${ConfigPackageLocation}
)
endif()
endforeach()
# Configure and install package config file
configure_package_config_file(