From 2be51f5e858eb210ff70c1666854f1bce9c8756f Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 4 Feb 2016 22:21:51 -0500 Subject: cmake: msgpack: Add more thorough version check In 33bc332, version constraints were added to pkg_search_module(), but that only affects the set of directories searched by find_library()/find_path(). Once the header directory is found, parse the version from version_master.h so it can be checked by the find_package() call in the root CMakeLists.txt. --- CMakeLists.txt | 2 +- cmake/FindMsgpack.cmake | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c3f4d927d..e6c1b0a74b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,7 +279,7 @@ include(CheckLibraryExists) find_package(LibUV REQUIRED) include_directories(SYSTEM ${LIBUV_INCLUDE_DIRS}) -find_package(Msgpack REQUIRED) +find_package(Msgpack 1.0.0 REQUIRED) include_directories(SYSTEM ${MSGPACK_INCLUDE_DIRS}) find_package(LuaJit REQUIRED) diff --git a/cmake/FindMsgpack.cmake b/cmake/FindMsgpack.cmake index 60afc88839..a03b095080 100644 --- a/cmake/FindMsgpack.cmake +++ b/cmake/FindMsgpack.cmake @@ -19,10 +19,20 @@ endif() set(MSGPACK_DEFINITIONS ${PC_MSGPACK_CFLAGS_OTHER}) -find_path(MSGPACK_INCLUDE_DIR msgpack.h +find_path(MSGPACK_INCLUDE_DIR msgpack/version_master.h HINTS ${PC_MSGPACK_INCLUDEDIR} ${PC_MSGPACK_INCLUDE_DIRS} ${LIMIT_SEARCH}) +if(MSGPACK_INCLUDE_DIR) + file(READ ${MSGPACK_INCLUDE_DIR}/msgpack/version_master.h msgpack_version_h) + string(REGEX REPLACE ".*MSGPACK_VERSION_MAJOR +([0-9]+).*" "\\1" MSGPACK_VERSION_MAJOR "${msgpack_version_h}") + string(REGEX REPLACE ".*MSGPACK_VERSION_MINOR +([0-9]+).*" "\\1" MSGPACK_VERSION_MINOR "${msgpack_version_h}") + string(REGEX REPLACE ".*MSGPACK_VERSION_REVISION +([0-9]+).*" "\\1" MSGPACK_VERSION_REVISION "${msgpack_version_h}") + set(MSGPACK_VERSION_STRING "${MSGPACK_VERSION_MAJOR}.${MSGPACK_VERSION_MINOR}.${MSGPACK_VERSION_REVISION}") +else() + set(MSGPACK_VERSION_STRING) +endif() + # If we're asked to use static linkage, add libmsgpack{,c}.a as a preferred library name. if(MSGPACK_USE_STATIC) list(APPEND MSGPACK_NAMES @@ -44,6 +54,7 @@ set(MSGPACK_INCLUDE_DIRS ${MSGPACK_INCLUDE_DIR}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set MSGPACK_FOUND to TRUE # if all listed variables are TRUE -find_package_handle_standard_args(Msgpack DEFAULT_MSG - MSGPACK_LIBRARY MSGPACK_INCLUDE_DIR) +find_package_handle_standard_args(Msgpack + REQUIRED_VARS MSGPACK_LIBRARY MSGPACK_INCLUDE_DIR + VERSION_VAR MSGPACK_VERSION_STRING) -- cgit From 79e7c03f914847508d9cc5be36b4a5e40669a99a Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 4 Feb 2016 22:38:45 -0500 Subject: cmake: msgpack: Check all lib names per directory By default, find_library() searches all directories for one possible name and then looks for the next name. To make sure we're building against the same headers and libraries, look for all names in a directory before moving to the next one. --- cmake/FindMsgpack.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/FindMsgpack.cmake b/cmake/FindMsgpack.cmake index a03b095080..3b20644453 100644 --- a/cmake/FindMsgpack.cmake +++ b/cmake/FindMsgpack.cmake @@ -43,6 +43,9 @@ endif() list(APPEND MSGPACK_NAMES msgpackc msgpack) find_library(MSGPACK_LIBRARY NAMES ${MSGPACK_NAMES} + # Check each directory for all names to avoid using headers/libraries from + # different places. + NAMES_PER_DIR HINTS ${PC_MSGPACK_LIBDIR} ${PC_MSGPACK_LIBRARY_DIRS} ${LIMIT_SEARCH}) -- cgit From 1d1574e0aca3cd270e7d4b2656e1aa11861d70af Mon Sep 17 00:00:00 2001 From: James McCoy Date: Fri, 5 Feb 2016 21:23:19 -0500 Subject: cmake: Use find_package(Msgpack)'s version in pkg_search_module Avoid duplicating information by using the Msgpack_FIND_VERSION variable exported by find_package() inside FindMsgpack's pkg_search_module call. --- cmake/FindMsgpack.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/FindMsgpack.cmake b/cmake/FindMsgpack.cmake index 3b20644453..015737d658 100644 --- a/cmake/FindMsgpack.cmake +++ b/cmake/FindMsgpack.cmake @@ -7,7 +7,9 @@ if(NOT MSGPACK_USE_BUNDLED) find_package(PkgConfig) if (PKG_CONFIG_FOUND) - pkg_search_module(PC_MSGPACK QUIET msgpackc>=1.0 msgpack>=1.0) + pkg_search_module(PC_MSGPACK QUIET + msgpackc>=${Msgpack_FIND_VERSION} + msgpack>=${Msgpack_FIND_VERSION}) endif() else() set(PC_MSGPACK_INCLUDEDIR) -- cgit