The open source OpenXR runtime
1# Copyright 2019-2022, Collabora, Ltd.
2#
3# SPDX-License-Identifier: BSL-1.0
4#
5# Distributed under the Boost Software License, Version 1.0.
6# (See accompanying file LICENSE_1_0.txt or copy at
7# http://www.boost.org/LICENSE_1_0.txt)
8#
9# Original Author:
10# 2019-2022 Rylie Pavlik <rylie.pavlik@collabora.com> <rylie@ryliepavlik.com>
11
12#.rst:
13# FindcJSON
14# ---------------
15#
16# Find the cJSON lightweight JSON parser
17#
18# Targets
19# ^^^^^^^
20#
21# If successful, the following import target is created.
22#
23# ``cJSON::cJSON``
24#
25# Cache variables
26# ^^^^^^^^^^^^^^^
27#
28# The following cache variable may also be set to assist/control the operation of this module:
29#
30# ``CJSON_ROOT_DIR``
31# The root to search for cJSON.
32
33set(CJSON_ROOT_DIR
34 "${CJSON_ROOT_DIR}"
35 CACHE PATH "Root to search for cJSON")
36
37include(FindPackageHandleStandardArgs)
38
39# Check for CMake config first.
40find_package(cJSON QUIET CONFIG)
41if(cJSON_FOUND AND TARGET cjson)
42 set_target_properties(cjson PROPERTIES IMPORTED_GLOBAL TRUE)
43 # Found config, let's prefer it.
44 find_package_handle_standard_args(cJSON CONFIG_MODE)
45 set(CJSON_LIBRARY cjson)
46
47else()
48 # Manually find
49 find_path(
50 CJSON_INCLUDE_DIR
51 NAMES cjson/cJSON.h
52 PATHS ${CJSON_ROOT_DIR}
53 PATH_SUFFIXES include)
54 find_library(
55 CJSON_LIBRARY
56 NAMES cjson
57 PATHS ${CJSON_ROOT_DIR}
58 PATH_SUFFIXES lib)
59
60 find_package_handle_standard_args(cJSON REQUIRED_VARS CJSON_INCLUDE_DIR
61 CJSON_LIBRARY)
62endif()
63
64if(CJSON_FOUND)
65 set(CJSON_INCLUDE_DIRS "${CJSON_INCLUDE_DIR}")
66 set(CJSON_LIBRARIES "${CJSON_LIBRARY}")
67 if(NOT TARGET cJSON::cJSON)
68 if(TARGET "${CJSON_LIBRARY}")
69 # Alias if we found the config file
70 add_library(cJSON::cJSON ALIAS cjson)
71 else()
72 add_library(cJSON::cJSON UNKNOWN IMPORTED)
73 set_target_properties(
74 cJSON::cJSON PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
75 "${CJSON_INCLUDE_DIR}")
76 set_target_properties(
77 cJSON::cJSON PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
78 IMPORTED_LOCATION "${CJSON_LIBRARY}")
79
80 endif()
81 endif()
82 mark_as_advanced(CJSON_INCLUDE_DIR CJSON_LIBRARY)
83endif()
84
85mark_as_advanced(CJSON_ROOT_DIR)