FindJsonCpp.cmake 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. find_path(JsonCpp_INCLUDE_DIR "json/json.h"
  2. PATH_SUFFIXES "jsoncpp"
  3. DOC "jsoncpp include directory")
  4. mark_as_advanced(JsonCpp_INCLUDE_DIR)
  5. find_library(JsonCpp_LIBRARY
  6. NAMES jsoncpp
  7. DOC "jsoncpp library")
  8. mark_as_advanced(JsonCpp_LIBRARY)
  9. if (JsonCpp_INCLUDE_DIR AND EXISTS "${JsonCpp_INCLUDE_DIR}/json/version.h")
  10. file(STRINGS "${JsonCpp_INCLUDE_DIR}/json/version.h" _JsonCpp_version_lines
  11. REGEX "JSONCPP_VERSION_[A-Z]+")
  12. string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_MAJOR +([0-9]+).*" "\\1" _JsonCpp_version_major "${_JsonCpp_version_lines}")
  13. string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_MINOR +([0-9]+).*" "\\1" _JsonCpp_version_minor "${_JsonCpp_version_lines}")
  14. string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_PATCH +([0-9]+).*" "\\1" _JsonCpp_version_patch "${_JsonCpp_version_lines}")
  15. set(JsonCpp_VERSION "${_JsonCpp_version_major}.${_JsonCpp_version_minor}.${_JsonCpp_version_patch}")
  16. unset(_JsonCpp_version_major)
  17. unset(_JsonCpp_version_minor)
  18. unset(_JsonCpp_version_patch)
  19. unset(_JsonCpp_version_lines)
  20. endif ()
  21. include(FindPackageHandleStandardArgs)
  22. find_package_handle_standard_args(JsonCpp
  23. REQUIRED_VARS JsonCpp_LIBRARY JsonCpp_INCLUDE_DIR
  24. VERSION_VAR JsonCpp_VERSION)
  25. if (JsonCpp_FOUND)
  26. set(JsonCpp_INCLUDE_DIRS "${JsonCpp_INCLUDE_DIR}")
  27. set(JsonCpp_LIBRARIES "${JsonCpp_LIBRARY}")
  28. if (NOT TARGET JsonCpp::JsonCpp)
  29. include(vtkDetectLibraryType)
  30. vtk_detect_library_type(jsoncpp_library_type
  31. PATH "${JsonCpp_LIBRARY}")
  32. add_library(JsonCpp::JsonCpp "${jsoncpp_library_type}" IMPORTED)
  33. unset(jsoncpp_library_type)
  34. set_target_properties(JsonCpp::JsonCpp PROPERTIES
  35. IMPORTED_LOCATION "${JsonCpp_LIBRARY}"
  36. IMPORTED_IMPLIB "${JsonCpp_LIBRARY}"
  37. INTERFACE_INCLUDE_DIRECTORIES "${JsonCpp_INCLUDE_DIR}")
  38. endif ()
  39. endif ()