forked from open-telemetry/opentelemetry-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnlohmann-json.cmake
93 lines (89 loc) · 3.19 KB
/
nlohmann-json.cmake
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
#
# The dependency on nlohmann_json can be provided different ways. By order of
# decreasing priority, options are:
#
# 1 - Search for a nlohmann_json package
#
# Packages installed on the local machine are used if found.
#
# The nlohmann_json dependency is not installed, as it already is.
#
# 2 - Search for a nlohmann_json git submodule
#
# When git submodule is used, the nlohmann_json code is located in:
# third_party/nlohmann-json
#
# The nlohmann_json dependency is installed, by building the sub directory with
# JSON_Install=ON
#
# 3 - Download nlohmann_json from github
#
# Code from the development branch is used, unless a specific release tag is
# provided in variable ${nlohmann-json}
#
# The nlohmann_json dependency is installed, by building the downloaded code
# with JSON_Install=ON
#
# nlohmann_json package is required for most SDK build configurations
find_package(nlohmann_json QUIET)
set(nlohmann_json_clone FALSE)
if(nlohmann_json_FOUND)
message(STATUS "nlohmann::json dependency satisfied by: package")
elseif(TARGET nlohmann_json)
message(STATUS "nlohmann::json is already added as a CMake target!")
elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git
AND EXISTS
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt)
message(STATUS "nlohmann::json dependency satisfied by: git submodule")
set(JSON_BuildTests
OFF
CACHE INTERNAL "")
set(JSON_Install
ON
CACHE INTERNAL "")
# This option allows to link nlohmann_json::nlohmann_json target
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/nlohmann-json)
# This option allows to add header to include directories
include_directories(
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
else()
if("${nlohmann-json}" STREQUAL "")
set(nlohmann-json "develop")
endif()
message(STATUS "nlohmann::json dependency satisfied by: github download")
set(nlohmann_json_clone TRUE)
include(ExternalProject)
ExternalProject_Add(
nlohmann_json_download
PREFIX third_party
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG "${nlohmann-json}"
UPDATE_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DJSON_BuildTests=OFF -DJSON_Install=ON
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
TEST_AFTER_INSTALL 0
DOWNLOAD_NO_PROGRESS 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1)
ExternalProject_Get_Property(nlohmann_json_download INSTALL_DIR)
set(NLOHMANN_JSON_INCLUDE_DIR
${INSTALL_DIR}/src/nlohmann_json_download/single_include)
add_library(nlohmann_json_ INTERFACE)
target_include_directories(
nlohmann_json_ INTERFACE "$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_DIR}>"
"$<INSTALL_INTERFACE:include>")
add_dependencies(nlohmann_json_ nlohmann_json_download)
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json_)
if(OPENTELEMETRY_INSTALL)
install(
TARGETS nlohmann_json_
EXPORT "${PROJECT_NAME}-target"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
endif()