summaryrefslogtreecommitdiff
path: root/dev-libs/protobuf/files/FindJsonCpp.cmake
blob: 8fff5336ce46ed0532c8c0fbe00fb9b55d618e8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
find_path(JsonCpp_INCLUDE_DIR "json/json.h"
  PATH_SUFFIXES "jsoncpp"
  DOC "jsoncpp include directory")
mark_as_advanced(JsonCpp_INCLUDE_DIR)

find_library(JsonCpp_LIBRARY
  NAMES jsoncpp
  DOC "jsoncpp library")
mark_as_advanced(JsonCpp_LIBRARY)

if (JsonCpp_INCLUDE_DIR AND EXISTS "${JsonCpp_INCLUDE_DIR}/json/version.h")
  file(STRINGS "${JsonCpp_INCLUDE_DIR}/json/version.h" _JsonCpp_version_lines
    REGEX "JSONCPP_VERSION_[A-Z]+")
  string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_MAJOR +([0-9]+).*" "\\1" _JsonCpp_version_major "${_JsonCpp_version_lines}")
  string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_MINOR +([0-9]+).*" "\\1" _JsonCpp_version_minor "${_JsonCpp_version_lines}")
  string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_PATCH +([0-9]+).*" "\\1" _JsonCpp_version_patch "${_JsonCpp_version_lines}")
  set(JsonCpp_VERSION "${_JsonCpp_version_major}.${_JsonCpp_version_minor}.${_JsonCpp_version_patch}")
  unset(_JsonCpp_version_major)
  unset(_JsonCpp_version_minor)
  unset(_JsonCpp_version_patch)
  unset(_JsonCpp_version_lines)
endif ()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(JsonCpp
  REQUIRED_VARS JsonCpp_LIBRARY JsonCpp_INCLUDE_DIR
  VERSION_VAR JsonCpp_VERSION)

if (JsonCpp_FOUND)
  set(JsonCpp_INCLUDE_DIRS "${JsonCpp_INCLUDE_DIR}")
  set(JsonCpp_LIBRARIES "${JsonCpp_LIBRARY}")

  if (NOT TARGET JsonCpp::JsonCpp)
    add_library(JsonCpp::JsonCpp SHARED IMPORTED)
    set_target_properties(JsonCpp::JsonCpp PROPERTIES
      IMPORTED_LOCATION "${JsonCpp_LIBRARY}"
      IMPORTED_IMPLIB "${JsonCpp_LIBRARY}"
      INTERFACE_INCLUDE_DIRECTORIES "${JsonCpp_INCLUDE_DIR}")
  endif ()
endif ()