From 6c18342a1404bc5b960b66baf68dee4d0cce01e4 Mon Sep 17 00:00:00 2001 From: Wouter Nuyts Date: Wed, 22 Jul 2020 21:24:10 +0200 Subject: [PATCH] Add package configuration file to CPP version. Resolves #901. --- CMakeLists.txt | 50 ++++++++++++++++++++++++++++++-- cmake/msgpackcxx-config.cmake.in | 19 ++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 cmake/msgpackcxx-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f7d761aa..bc7490734 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ IF ((CMAKE_VERSION VERSION_GREATER 3.1) OR CMAKE_POLICY(SET CMP0054 NEW) ENDIF () -PROJECT (msgpack CXX) +PROJECT (msgpackcxx CXX) FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/version_master.hpp contents) STRING (REGEX MATCH "#define MSGPACK_VERSION_MAJOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents}) @@ -129,13 +129,19 @@ int main(int argc, char * argv[]) INCLUDE (Files.cmake) -ADD_LIBRARY (msgpackcxx INTERFACE) +ADD_LIBRARY (${PROJECT_NAME} INTERFACE) TARGET_INCLUDE_DIRECTORIES (msgpackcxx INTERFACE $ $ - $ + $ +) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} + INTERFACE + Boost::system + ZLIB::ZLIB ) # enable regression testing @@ -185,6 +191,44 @@ IF (MSGPACK_BUILD_EXAMPLES) ADD_SUBDIRECTORY (example) ENDIF () +INCLUDE(GNUInstallDirs) +SET (CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake") + +SET(CONFIG_FILENAME "${PROJECT_NAME}-config.cmake") +SET(CONFIG_VERSION_FILENAME "${PROJECT_NAME}-config-version.cmake") + +INSTALL ( + TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}_Targets +) + +INCLUDE(CMakePackageConfigHelpers) +WRITE_BASIC_PACKAGE_VERSION_FILE ( + "${CONFIG_VERSION_FILENAME}" + VERSION ${VERSION} + COMPATIBILITY SameMajorVersion +) + +CONFIGURE_PACKAGE_CONFIG_FILE ("${CMAKE_CURRENT_SOURCE_DIR}/cmake/${CONFIG_FILENAME}.in" + "${CONFIG_FILENAME}" + INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" +) + +INSTALL (EXPORT ${PROJECT_NAME}_Targets + FILE + "${PROJECT_NAME}-targets.cmake" + DESTINATION + "${CMAKE_INSTALL_CMAKEDIR}" +) + +INSTALL( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_FILENAME}" + "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_VERSION_FILENAME}" + DESTINATION + "${CMAKE_INSTALL_CMAKEDIR}" +) + FOREACH (file ${msgpackc_HEADERS}) GET_FILENAME_COMPONENT (dir ${file} PATH) INSTALL (FILES ${file} DESTINATION ${CMAKE_INSTALL_PREFIX}/${dir}) diff --git a/cmake/msgpackcxx-config.cmake.in b/cmake/msgpackcxx-config.cmake.in new file mode 100644 index 000000000..a9e2f5d7f --- /dev/null +++ b/cmake/msgpackcxx-config.cmake.in @@ -0,0 +1,19 @@ +#.rst: +# msgpack +# ------- +# +# The following import targets are created +# +# :: +# +# msgpackcppcxx +# + +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +find_dependency(ZLIB) +find_dependency(Boost COMPONENTS system) + +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") +check_required_components(msgpackcxx)