1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
8 Find JsonCpp includes and library.
13 An :ref:`imported target <Imported targets>` named
14 ``JsonCpp::JsonCpp`` is provided if JsonCpp has been found.
19 This module defines the following variables:
22 True if JsonCpp was found, false otherwise.
23 ``JsonCpp_INCLUDE_DIRS``
24 Include directories needed to include JsonCpp headers.
26 Libraries needed to link to JsonCpp.
27 ``JsonCpp_VERSION_STRING``
28 The version of JsonCpp found.
29 May not be set for JsonCpp versions prior to 1.0.
30 ``JsonCpp_VERSION_MAJOR``
31 The major version of JsonCpp.
32 ``JsonCpp_VERSION_MINOR``
33 The minor version of JsonCpp.
34 ``JsonCpp_VERSION_PATCH``
35 The patch version of JsonCpp.
40 This module uses the following cache variables:
43 The location of the JsonCpp library file.
44 ``JsonCpp_INCLUDE_DIR``
45 The location of the JsonCpp include directory containing ``json/json.h``.
47 The cache variables should not be used by project code.
48 They may be set by end users to point at JsonCpp components.
49 #]=======================================================================]
51 #-----------------------------------------------------------------------------
52 find_library(JsonCpp_LIBRARY
55 mark_as_advanced(JsonCpp_LIBRARY)
57 find_path(JsonCpp_INCLUDE_DIR
61 mark_as_advanced(JsonCpp_INCLUDE_DIR)
63 #-----------------------------------------------------------------------------
64 # Extract version number if possible.
65 set(_JsonCpp_H_REGEX "^#[ \t]*define[ \t]+JSONCPP_VERSION_STRING[ \t]+\"(([0-9]+)\\.([0-9]+)\\.([0-9]+)[^\"]*)\".*$")
66 if(JsonCpp_INCLUDE_DIR AND EXISTS "${JsonCpp_INCLUDE_DIR}/json/version.h")
67 file(STRINGS "${JsonCpp_INCLUDE_DIR}/json/version.h" _JsonCpp_H REGEX "${_JsonCpp_H_REGEX}")
71 if(_JsonCpp_H MATCHES "${_JsonCpp_H_REGEX}")
72 set(JsonCpp_VERSION_STRING "${CMAKE_MATCH_1}")
73 set(JsonCpp_VERSION_MAJOR "${CMAKE_MATCH_2}")
74 set(JsonCpp_VERSION_MINOR "${CMAKE_MATCH_3}")
75 set(JsonCpp_VERSION_PATCH "${CMAKE_MATCH_4}")
77 set(JsonCpp_VERSION_STRING "")
78 set(JsonCpp_VERSION_MAJOR "")
79 set(JsonCpp_VERSION_MINOR "")
80 set(JsonCpp_VERSION_PATCH "")
82 unset(_JsonCpp_H_REGEX)
85 #-----------------------------------------------------------------------------
86 include(${CMAKE_CURRENT_LIST_DIR}/../../Modules/FindPackageHandleStandardArgs.cmake)
87 FIND_PACKAGE_HANDLE_STANDARD_ARGS(JsonCpp
88 FOUND_VAR JsonCpp_FOUND
89 REQUIRED_VARS JsonCpp_LIBRARY JsonCpp_INCLUDE_DIR
90 VERSION_VAR JsonCpp_VERSION_STRING
92 set(JSONCPP_FOUND ${JsonCpp_FOUND})
94 #-----------------------------------------------------------------------------
95 # Provide documented result variables and targets.
97 set(JsonCpp_INCLUDE_DIRS ${JsonCpp_INCLUDE_DIR})
98 set(JsonCpp_LIBRARIES ${JsonCpp_LIBRARY})
99 if(NOT TARGET JsonCpp::JsonCpp)
100 add_library(JsonCpp::JsonCpp UNKNOWN IMPORTED)
101 set_target_properties(JsonCpp::JsonCpp PROPERTIES
102 IMPORTED_LOCATION "${JsonCpp_LIBRARY}"
103 INTERFACE_INCLUDE_DIRECTORIES "${JsonCpp_INCLUDE_DIRS}"
104 IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"