FindMsgpack.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # - Try to find msgpack
  2. # Once done this will define
  3. # MSGPACK_FOUND - System has msgpack
  4. # MSGPACK_INCLUDE_DIRS - The msgpack include directories
  5. # MSGPACK_LIBRARIES - The libraries needed to use msgpack
  6. find_package(PkgConfig)
  7. if (PKG_CONFIG_FOUND)
  8. pkg_search_module(PC_MSGPACK QUIET
  9. msgpackc>=${Msgpack_FIND_VERSION}
  10. msgpack>=${Msgpack_FIND_VERSION})
  11. endif()
  12. set(MSGPACK_DEFINITIONS ${PC_MSGPACK_CFLAGS_OTHER})
  13. find_path(MSGPACK_INCLUDE_DIR msgpack/version_master.h
  14. HINTS ${PC_MSGPACK_INCLUDEDIR} ${PC_MSGPACK_INCLUDE_DIRS})
  15. if(MSGPACK_INCLUDE_DIR)
  16. file(READ ${MSGPACK_INCLUDE_DIR}/msgpack/version_master.h msgpack_version_h)
  17. string(REGEX REPLACE ".*MSGPACK_VERSION_MAJOR +([0-9]+).*" "\\1" MSGPACK_VERSION_MAJOR "${msgpack_version_h}")
  18. string(REGEX REPLACE ".*MSGPACK_VERSION_MINOR +([0-9]+).*" "\\1" MSGPACK_VERSION_MINOR "${msgpack_version_h}")
  19. string(REGEX REPLACE ".*MSGPACK_VERSION_REVISION +([0-9]+).*" "\\1" MSGPACK_VERSION_REVISION "${msgpack_version_h}")
  20. set(MSGPACK_VERSION_STRING "${MSGPACK_VERSION_MAJOR}.${MSGPACK_VERSION_MINOR}.${MSGPACK_VERSION_REVISION}")
  21. else()
  22. set(MSGPACK_VERSION_STRING)
  23. endif()
  24. if(MSVC)
  25. # The import library for the msgpack DLL has a different name
  26. list(APPEND MSGPACK_NAMES msgpackc_import)
  27. else()
  28. list(APPEND MSGPACK_NAMES msgpackc msgpack)
  29. endif()
  30. find_library(MSGPACK_LIBRARY NAMES ${MSGPACK_NAMES}
  31. # Check each directory for all names to avoid using headers/libraries from
  32. # different places.
  33. NAMES_PER_DIR
  34. HINTS ${PC_MSGPACK_LIBDIR} ${PC_MSGPACK_LIBRARY_DIRS})
  35. mark_as_advanced(MSGPACK_INCLUDE_DIR MSGPACK_LIBRARY)
  36. set(MSGPACK_LIBRARIES ${MSGPACK_LIBRARY})
  37. set(MSGPACK_INCLUDE_DIRS ${MSGPACK_INCLUDE_DIR})
  38. include(FindPackageHandleStandardArgs)
  39. # handle the QUIETLY and REQUIRED arguments and set MSGPACK_FOUND to TRUE
  40. # if all listed variables are TRUE
  41. find_package_handle_standard_args(Msgpack
  42. REQUIRED_VARS MSGPACK_LIBRARY MSGPACK_INCLUDE_DIR
  43. VERSION_VAR MSGPACK_VERSION_STRING)