|
1 |
| -if("${nlohmann-json}" STREQUAL "") |
2 |
| - set(nlohmann-json "develop") |
3 |
| -endif() |
4 |
| -include(ExternalProject) |
5 |
| -ExternalProject_Add(nlohmann_json_download |
6 |
| - PREFIX third_party |
7 |
| - GIT_REPOSITORY https://github.com/nlohmann/json.git |
8 |
| - GIT_TAG |
9 |
| - "${nlohmann-json}" |
10 |
| - UPDATE_COMMAND "" |
11 |
| - CMAKE_ARGS |
12 |
| - -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} |
13 |
| - -DJSON_BuildTests=OFF |
14 |
| - -DJSON_Install=ON |
15 |
| - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} |
16 |
| - TEST_AFTER_INSTALL |
17 |
| - 0 |
18 |
| - DOWNLOAD_NO_PROGRESS |
19 |
| - 1 |
20 |
| - LOG_CONFIGURE |
21 |
| - 1 |
22 |
| - LOG_BUILD |
23 |
| - 1 |
24 |
| - LOG_INSTALL |
25 |
| - 1 |
26 |
| -) |
| 1 | +# Copyright The OpenTelemetry Authors |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +# |
| 5 | +# The dependency on nlohmann_json can be provided different ways. |
| 6 | +# By order of decreasing priority, options are: |
| 7 | +# |
| 8 | +# 1 - Search for a nlohmann_json package |
| 9 | +# |
| 10 | +# Packages installed on the local machine are used if found. |
| 11 | +# |
| 12 | +# The nlohmann_json dependency is not installed, |
| 13 | +# as it already is. |
| 14 | +# |
| 15 | +# 2 - Search for a nlohmann_json git submodule |
| 16 | +# |
| 17 | +# When git submodule is used, |
| 18 | +# the nlohmann_json code is located in: |
| 19 | +# third_party/nlohmann-json |
| 20 | +# |
| 21 | +# The nlohmann_json dependency is installed, |
| 22 | +# by building the sub directory with JSON_Install=ON |
| 23 | +# |
| 24 | +# 3 - Download nlohmann_json from github |
| 25 | +# |
| 26 | +# Code from the development branch is used, |
| 27 | +# unless a specific release tag is provided |
| 28 | +# in variable ${nlohmann-json} |
| 29 | +# |
| 30 | +# The nlohmann_json dependency is installed, |
| 31 | +# by building the downloaded code with JSON_Install=ON |
| 32 | +# |
| 33 | + |
27 | 34 |
|
28 |
| -ExternalProject_Get_Property(nlohmann_json_download INSTALL_DIR) |
29 |
| -SET(NLOHMANN_JSON_INCLUDE_DIR ${INSTALL_DIR}/src/nlohmann_json_download/single_include) |
30 |
| -add_library(nlohmann_json_ INTERFACE) |
31 |
| -target_include_directories(nlohmann_json_ INTERFACE |
32 |
| - "$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_DIR}>" |
33 |
| - "$<INSTALL_INTERFACE:include>") |
34 |
| -add_dependencies(nlohmann_json_ nlohmann_json_download) |
35 |
| -add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json_) |
| 35 | +# nlohmann_json package is required for most SDK build configurations |
| 36 | +find_package(nlohmann_json QUIET) |
| 37 | +set(nlohmann_json_clone FALSE) |
| 38 | +if(nlohmann_json_FOUND) |
| 39 | + message(STATUS "nlohmann::json dependency satisfied by: package") |
| 40 | +elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git |
| 41 | + AND EXISTS |
| 42 | + ${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt) |
| 43 | + message(STATUS "nlohmann::json dependency satisfied by: git submodule") |
| 44 | + set(JSON_BuildTests |
| 45 | + OFF |
| 46 | + CACHE INTERNAL "") |
| 47 | + set(JSON_Install |
| 48 | + ON |
| 49 | + CACHE INTERNAL "") |
| 50 | + # This option allows to link nlohmann_json::nlohmann_json target |
| 51 | + add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/nlohmann-json) |
| 52 | + # This option allows to add header to include directories |
| 53 | + include_directories( |
| 54 | + ${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include) |
| 55 | +else() |
| 56 | + if("${nlohmann-json}" STREQUAL "") |
| 57 | + set(nlohmann-json "develop") |
| 58 | + endif() |
| 59 | + message(STATUS "nlohmann::json dependency satisfied by: github download") |
| 60 | + set(nlohmann_json_clone TRUE) |
| 61 | + include(ExternalProject) |
| 62 | + ExternalProject_Add(nlohmann_json_download |
| 63 | + PREFIX third_party |
| 64 | + GIT_REPOSITORY https://github.com/nlohmann/json.git |
| 65 | + GIT_TAG |
| 66 | + "${nlohmann-json}" |
| 67 | + UPDATE_COMMAND "" |
| 68 | + CMAKE_ARGS |
| 69 | + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} |
| 70 | + -DJSON_BuildTests=OFF |
| 71 | + -DJSON_Install=ON |
| 72 | + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} |
| 73 | + TEST_AFTER_INSTALL |
| 74 | + 0 |
| 75 | + DOWNLOAD_NO_PROGRESS |
| 76 | + 1 |
| 77 | + LOG_CONFIGURE |
| 78 | + 1 |
| 79 | + LOG_BUILD |
| 80 | + 1 |
| 81 | + LOG_INSTALL |
| 82 | + 1 |
| 83 | + ) |
36 | 84 |
|
37 |
| -install( |
38 |
| - TARGETS nlohmann_json_ |
39 |
| - EXPORT "${PROJECT_NAME}-target" |
40 |
| - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
41 |
| - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
42 |
| - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 85 | + ExternalProject_Get_Property(nlohmann_json_download INSTALL_DIR) |
| 86 | + SET(NLOHMANN_JSON_INCLUDE_DIR ${INSTALL_DIR}/src/nlohmann_json_download/single_include) |
| 87 | + add_library(nlohmann_json_ INTERFACE) |
| 88 | + target_include_directories(nlohmann_json_ INTERFACE |
| 89 | + "$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_DIR}>" |
| 90 | + "$<INSTALL_INTERFACE:include>") |
| 91 | + add_dependencies(nlohmann_json_ nlohmann_json_download) |
| 92 | + add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json_) |
| 93 | + |
| 94 | + install( |
| 95 | + TARGETS nlohmann_json_ |
| 96 | + EXPORT "${PROJECT_NAME}-target" |
| 97 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
| 98 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 99 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) |
| 100 | +endif() |
0 commit comments