Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add package configuration file to CPP version. #903

Draft
wants to merge 1 commit into
base: cpp_master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

TARGET_LINK_LIBRARIES(${PROJECT_NAME}
INTERFACE
Boost::system
ZLIB::ZLIB
)

# enable regression testing
Expand Down Expand Up @@ -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})
Expand Down
19 changes: 19 additions & 0 deletions cmake/msgpackcxx-config.cmake.in
Original file line number Diff line number Diff line change
@@ -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)