FindMsgpack.cmake 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. if(NOT USE_BUNDLED_MSGPACK)
  7. find_package(PkgConfig)
  8. if (PKG_CONFIG_FOUND)
  9. pkg_search_module(PC_MSGPACK QUIET
  10. msgpackc>=${Msgpack_FIND_VERSION}
  11. msgpack>=${Msgpack_FIND_VERSION})
  12. endif()
  13. else()
  14. set(PC_MSGPACK_INCLUDEDIR)
  15. set(PC_MSGPACK_INCLUDE_DIRS)
  16. set(PC_MSGPACK_LIBDIR)
  17. set(PC_MSGPACK_LIBRARY_DIRS)
  18. set(LIMIT_SEARCH NO_DEFAULT_PATH)
  19. endif()
  20. set(MSGPACK_DEFINITIONS ${PC_MSGPACK_CFLAGS_OTHER})
  21. find_path(MSGPACK_INCLUDE_DIR msgpack/version_master.h
  22. HINTS ${PC_MSGPACK_INCLUDEDIR} ${PC_MSGPACK_INCLUDE_DIRS}
  23. ${LIMIT_SEARCH})
  24. if(MSGPACK_INCLUDE_DIR)
  25. file(READ ${MSGPACK_INCLUDE_DIR}/msgpack/version_master.h msgpack_version_h)
  26. string(REGEX REPLACE ".*MSGPACK_VERSION_MAJOR +([0-9]+).*" "\\1" MSGPACK_VERSION_MAJOR "${msgpack_version_h}")
  27. string(REGEX REPLACE ".*MSGPACK_VERSION_MINOR +([0-9]+).*" "\\1" MSGPACK_VERSION_MINOR "${msgpack_version_h}")
  28. string(REGEX REPLACE ".*MSGPACK_VERSION_REVISION +([0-9]+).*" "\\1" MSGPACK_VERSION_REVISION "${msgpack_version_h}")
  29. set(MSGPACK_VERSION_STRING "${MSGPACK_VERSION_MAJOR}.${MSGPACK_VERSION_MINOR}.${MSGPACK_VERSION_REVISION}")
  30. else()
  31. set(MSGPACK_VERSION_STRING)
  32. endif()
  33. # If we're asked to use static linkage, add libmsgpack{,c}.a as a preferred library name.
  34. if(MSGPACK_USE_STATIC)
  35. list(APPEND MSGPACK_NAMES
  36. "${CMAKE_STATIC_LIBRARY_PREFIX}msgpackc${CMAKE_STATIC_LIBRARY_SUFFIX}"
  37. "${CMAKE_STATIC_LIBRARY_PREFIX}msgpack${CMAKE_STATIC_LIBRARY_SUFFIX}")
  38. endif()
  39. if(MSVC)
  40. # The import library for the msgpack DLL has a different name
  41. list(APPEND MSGPACK_NAMES msgpackc_import)
  42. else()
  43. list(APPEND MSGPACK_NAMES msgpackc msgpack)
  44. endif()
  45. find_library(MSGPACK_LIBRARY NAMES ${MSGPACK_NAMES}
  46. # Check each directory for all names to avoid using headers/libraries from
  47. # different places.
  48. NAMES_PER_DIR
  49. HINTS ${PC_MSGPACK_LIBDIR} ${PC_MSGPACK_LIBRARY_DIRS}
  50. ${LIMIT_SEARCH})
  51. mark_as_advanced(MSGPACK_INCLUDE_DIR MSGPACK_LIBRARY)
  52. set(MSGPACK_LIBRARIES ${MSGPACK_LIBRARY})
  53. set(MSGPACK_INCLUDE_DIRS ${MSGPACK_INCLUDE_DIR})
  54. include(FindPackageHandleStandardArgs)
  55. # handle the QUIETLY and REQUIRED arguments and set MSGPACK_FOUND to TRUE
  56. # if all listed variables are TRUE
  57. find_package_handle_standard_args(Msgpack
  58. REQUIRED_VARS MSGPACK_LIBRARY MSGPACK_INCLUDE_DIR
  59. VERSION_VAR MSGPACK_VERSION_STRING)