Skip to content

Commit

Permalink
Merge pull request #3811 from teo-tsirpanis/unified-target
Browse files Browse the repository at this point in the history
Export a `zstd::libzstd` CMake target if only static or dynamic linkage is specified.
  • Loading branch information
Cyan4973 committed Mar 3, 2024
2 parents a58b48e + b27d163 commit 063d9f2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
11 changes: 6 additions & 5 deletions build/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ export(EXPORT zstdExports
FILE "${CMAKE_CURRENT_BINARY_DIR}/zstdTargets.cmake"
NAMESPACE zstd::
)
configure_file(zstdConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
COPYONLY
)

# A Package Config file that works from the installation directory
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/zstd)
Expand All @@ -192,8 +188,13 @@ install(EXPORT zstdExports
NAMESPACE zstd::
DESTINATION ${ConfigPackageLocation}
)
configure_package_config_file(
zstdConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
INSTALL_DESTINATION ${ConfigPackageLocation}
)
install(FILES
zstdConfig.cmake
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfigVersion.cmake"
DESTINATION ${ConfigPackageLocation}
)
10 changes: 10 additions & 0 deletions build/cmake/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ if (ZSTD_BUILD_STATIC)
add_definition(libzstd_static ZSTDLIB_STATIC_API)
add_definition(libzstd_static ZDICTLIB_STATIC_API)
endif ()
if (ZSTD_BUILD_SHARED AND NOT ZSTD_BUILD_STATIC)
add_library(libzstd INTERFACE)
target_link_libraries(libzstd INTERFACE libzstd_shared)
list(APPEND library_targets libzstd)
endif ()
if (ZSTD_BUILD_STATIC AND NOT ZSTD_BUILD_SHARED)
add_library(libzstd INTERFACE)
target_link_libraries(libzstd INTERFACE libzstd_static)
list(APPEND library_targets libzstd)
endif ()

# Add specific compile definitions for MSVC project
if (MSVC)
Expand Down
1 change: 0 additions & 1 deletion build/cmake/zstdConfig.cmake

This file was deleted.

10 changes: 10 additions & 0 deletions build/cmake/zstdConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
if(@ZSTD_MULTITHREAD_SUPPORT@ AND "@UNIX@")
find_dependency(Threads)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/zstdTargets.cmake")

check_required_components("zstd")

0 comments on commit 063d9f2

Please sign in to comment.