Skip to content

Commit

Permalink
Merge pull request #1924 from ned14/dev
Browse files Browse the repository at this point in the history
Make idiomatic cmake install so third party cmake installers work right.
  • Loading branch information
Cyan4973 authored Dec 10, 2019
2 parents 49c6d49 + 23e9974 commit e839b31
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
38 changes: 30 additions & 8 deletions build/cmake/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ if (ZSTD_BUILD_STATIC)
set_target_properties(
libzstd_static
PROPERTIES
POSITION_INDEPENDENT_CODE On
OUTPUT_NAME ${STATIC_LIBRARY_BASE_NAME})
endif ()

Expand All @@ -146,22 +147,43 @@ endif ()

# install target
install(FILES
${LIBRARY_DIR}/zstd.h
${LIBRARY_DIR}/deprecated/zbuff.h
${LIBRARY_DIR}/dictBuilder/zdict.h
${LIBRARY_DIR}/dictBuilder/cover.h
${LIBRARY_DIR}/common/zstd_errors.h
"${LIBRARY_DIR}/zstd.h"
"${LIBRARY_DIR}/deprecated/zbuff.h"
"${LIBRARY_DIR}/dictBuilder/zdict.h"
"${LIBRARY_DIR}/dictBuilder/cover.h"
"${LIBRARY_DIR}/common/zstd_errors.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

if (ZSTD_BUILD_SHARED)
install(TARGETS libzstd_shared RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
install(TARGETS libzstd_shared EXPORT zstdExports
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
)
endif()
if (ZSTD_BUILD_STATIC)
install(TARGETS libzstd_static ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(TARGETS libzstd_static EXPORT zstdExports
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif ()

# export targets + find config
configure_file(
"config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
@ONLY
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/zstdConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zstd"
)
install(EXPORT zstdExports
NAMESPACE zstd::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zstd"
)

# uninstall target
if (NOT TARGET uninstall)
configure_file(
Expand Down
7 changes: 7 additions & 0 deletions build/cmake/lib/config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include(FindPackageHandleStandardArgs)
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG ${CMAKE_CURRENT_LIST_FILE})
find_package_handle_standard_args(zstd CONFIG_MODE)

if(NOT TARGET zstd::libzstd_shared)
include("${CMAKE_CURRENT_LIST_DIR}/zstdExports.cmake")
endif()

0 comments on commit e839b31

Please sign in to comment.