Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Create Hunter-based CMake Config file
Browse files Browse the repository at this point in the history
  • Loading branch information
rbsheth authored and ruslo committed May 23, 2019
1 parent 80865ee commit c56ba6c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
50 changes: 49 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ HunterGate(
SHA1 "5d68bcca78eee347239ca5f4d34f4b6c12683154"
)

PROJECT(libzip C)
PROJECT(libzip
LANGUAGES C
VERSION "1.5.2")

OPTION(ENABLE_COMMONCRYPTO "Enable use of CommonCrypto" ON)
OPTION(ENABLE_GNUTLS "Enable use of GnuTLS" ON)
Expand Down Expand Up @@ -309,6 +311,52 @@ ENDIF()
# Testing
ENABLE_TESTING()

IF(HUNTER_ENABLED)
####
# Installation (https://github.com/forexample/package-example) {

set(CONFIG_INSTALL_DIR "lib/cmake/${PROJECT_NAME}")
set(INCLUDE_INSTALL_DIR "include")

set(GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")

# Configuration
set(VERSION_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}ConfigVersion.cmake")
set(PROJECT_CONFIG "${GENERATED_DIR}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(NAMESPACE "${PROJECT_NAME}::")

# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)

# Note: PROJECT_VERSION is used as a VERSION
write_basic_package_version_file(
"${VERSION_CONFIG}" COMPATIBILITY SameMajorVersion
)

# Use variables:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${PROJECT_CONFIG}"
INSTALL_DESTINATION "${CONFIG_INSTALL_DIR}"
)

install(
FILES "${PROJECT_CONFIG}" "${VERSION_CONFIG}"
DESTINATION "${CONFIG_INSTALL_DIR}"
)

install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${NAMESPACE}"
DESTINATION "${CONFIG_INSTALL_DIR}"
)

# }
ENDIF()

# Targets
ADD_SUBDIRECTORY(lib)

Expand Down
8 changes: 8 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@PACKAGE_INIT@

find_package(ZLIB CONFIG REQUIRED)
find_package(BZip2 CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
5 changes: 4 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ ENDIF()

TARGET_LINK_LIBRARIES(zip PUBLIC ${ZLIB_LIBRARY} ${OPTIONAL_LIBRARY})
INSTALL(TARGETS zip
EXPORT "${TARGETS_EXPORT_NAME}"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION "${INCLUDE_INSTALL_DIR}"
)
#CREATE_LIBTOOL_FILE(zip lib)

0 comments on commit c56ba6c

Please sign in to comment.