FindJsoncpp.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Find jsoncpp
  2. #
  3. # Find the jsoncpp includes and library
  4. #
  5. # if you nee to add a custom library search path, do it via via
  6. # CMAKE_PREFIX_PATH
  7. #
  8. # This module defines JSONCPP_INCLUDE_DIRS, where to find header, etc.
  9. # JSONCPP_LIBRARIES, the libraries needed to use jsoncpp. JSONCPP_FOUND, If
  10. # false, do not try to use jsoncpp.
  11. # Jsoncpp_lib - The imported target library.
  12. # only look in default directories
  13. find_path(JSONCPP_INCLUDE_DIRS
  14. NAMES json/json.h
  15. DOC "jsoncpp include dir"
  16. PATH_SUFFIXES jsoncpp)
  17. find_library(JSONCPP_LIBRARIES NAMES jsoncpp DOC "jsoncpp library")
  18. # debug library on windows same naming convention as in qt (appending debug
  19. # library with d) boost is using the same "hack" as us with "optimized" and
  20. # "debug" if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  21. # find_library(JSONCPP_LIBRARIES_DEBUG NAMES jsoncppd DOC "jsoncpp debug
  22. # library") if("${JSONCPP_LIBRARIES_DEBUG}" STREQUAL "JSONCPP_LIBRARIES_DEBUG-
  23. # NOTFOUND") set(JSONCPP_LIBRARIES_DEBUG ${JSONCPP_LIBRARIES}) endif()
  24. # set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug
  25. # ${JSONCPP_LIBRARIES_DEBUG})
  26. # endif()
  27. # handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE if all
  28. # listed variables are TRUE, hide their existence from configuration view
  29. include(FindPackageHandleStandardArgs)
  30. find_package_handle_standard_args(Jsoncpp
  31. DEFAULT_MSG
  32. JSONCPP_INCLUDE_DIRS
  33. JSONCPP_LIBRARIES)
  34. mark_as_advanced(JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES)
  35. if(Jsoncpp_FOUND)
  36. if(NOT EXISTS ${JSONCPP_INCLUDE_DIRS}/json/version.h)
  37. message(FATAL_ERROR "Error: jsoncpp lib is too old.....stop")
  38. endif()
  39. if(NOT WIN32)
  40. exec_program(
  41. cat
  42. ARGS
  43. "${JSONCPP_INCLUDE_DIRS}/json/version.h |grep JSONCPP_VERSION_STRING|sed s'/.*define/define/'|awk '{printf $3}'|sed s'/\"//g'"
  44. OUTPUT_VARIABLE
  45. jsoncpp_ver)
  46. message(STATUS "jsoncpp verson:" ${jsoncpp_ver})
  47. if(jsoncpp_ver LESS 1.7)
  48. message(
  49. FATAL_ERROR
  50. "jsoncpp lib is too old, please get new version from https://github.com/open-source-parsers/jsoncpp"
  51. )
  52. endif(jsoncpp_ver LESS 1.7)
  53. endif()
  54. if (NOT TARGET Jsoncpp_lib)
  55. add_library(Jsoncpp_lib INTERFACE IMPORTED)
  56. endif()
  57. set_target_properties(Jsoncpp_lib
  58. PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
  59. "${JSONCPP_INCLUDE_DIRS}"
  60. INTERFACE_LINK_LIBRARIES
  61. "${JSONCPP_LIBRARIES}")
  62. endif(Jsoncpp_FOUND)