Skip to content

Commit 6e249fd

Browse files
authored
build release tarball when nlohmann-json not installed (#1074)
1 parent 97fbdaa commit 6e249fd

File tree

6 files changed

+77
-29
lines changed

6 files changed

+77
-29
lines changed

CMakeLists.txt

100644100755
Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -278,34 +278,28 @@ if((NOT WITH_API_ONLY)
278278
OR WITH_ETW)
279279
# nlohmann_json package is required for most SDK build configurations
280280
find_package(nlohmann_json QUIET)
281-
if(NOT nlohmann_json_FOUND)
282-
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
283-
message("Trying to use local nlohmann::json from submodule")
284-
set(JSON_BuildTests
285-
OFF
286-
CACHE INTERNAL "")
287-
set(JSON_Install
288-
ON
289-
CACHE INTERNAL "")
290-
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt)
291-
# This option allows to link nlohmann_json::nlohmann_json target
292-
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/nlohmann-json)
293-
# This option allows to add header to include directories
294-
include_directories(
295-
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
296-
else()
297-
message(
298-
FATAL_ERROR
299-
"\nnlohmann_json package was not found. Please either provide it manually or clone with submodules. "
300-
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
301-
"git submodule update --init --recursive")
302-
endif()
303-
else()
304-
# Let's fail with default find_package error
305-
find_package(nlohmann_json REQUIRED)
306-
endif()
307-
else()
281+
set(nlohmann_json_clone FALSE)
282+
if(nlohmann_json_FOUND)
308283
message("Using external nlohmann::json")
284+
elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git
285+
AND EXISTS
286+
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt)
287+
message("Trying to use local nlohmann::json from submodule")
288+
set(JSON_BuildTests
289+
OFF
290+
CACHE INTERNAL "")
291+
set(JSON_Install
292+
ON
293+
CACHE INTERNAL "")
294+
# This option allows to link nlohmann_json::nlohmann_json target
295+
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/nlohmann-json)
296+
# This option allows to add header to include directories
297+
include_directories(
298+
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
299+
else()
300+
set(nlohmann_json_clone TRUE)
301+
include(cmake/nlohmann-json.cmake)
302+
message("\nnlohmann_json package was not found. Cloning from github")
309303
endif()
310304
endif()
311305

cmake/nlohmann-json.cmake

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
)
27+
28+
ExternalProject_Get_Property(nlohmann_json_download INSTALL_DIR)
29+
SET(NLOHMANN_JSON_INCLUDE_DIR ${INSTALL_DIR}/third_party/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_)
36+
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})

exporters/etw/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ set_target_properties(opentelemetry_exporter_etw PROPERTIES EXPORT_NAME
1010

1111
target_link_libraries(opentelemetry_exporter_etw
1212
INTERFACE nlohmann_json::nlohmann_json)
13+
if(nlohmann_json_clone)
14+
add_dependencies(opentelemetry_exporter_etw nlohmann_json::nlohmann_json)
15+
endif()
1316

1417
install(
1518
TARGETS opentelemetry_exporter_etw

exporters/otlp/CMakeLists.txt

100644100755
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ if(WITH_OTLP_HTTP)
4848
opentelemetry_exporter_otlp_http_client
4949
PUBLIC opentelemetry_sdk opentelemetry_proto http_client_curl
5050
nlohmann_json::nlohmann_json)
51+
if(nlohmann_json_clone)
52+
add_dependencies(opentelemetry_exporter_otlp_http_client
53+
nlohmann_json::nlohmann_json)
54+
endif()
5155
target_include_directories(
5256
opentelemetry_exporter_otlp_http_client
5357
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"

exporters/zipkin/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ add_definitions(-DWITH_CURL)
1818
add_library(opentelemetry_exporter_zipkin_trace src/zipkin_exporter.cc
1919
src/recordable.cc)
2020

21-
target_link_libraries(opentelemetry_exporter_zipkin_trace
22-
PUBLIC opentelemetry_trace http_client_curl)
21+
target_link_libraries(
22+
opentelemetry_exporter_zipkin_trace
23+
PUBLIC opentelemetry_trace http_client_curl nlohmann_json::nlohmann_json)
2324

2425
install(
2526
TARGETS opentelemetry_exporter_zipkin_trace

ext/test/w3c_tracecontext_test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ else()
1010
PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace http_client_curl
1111
opentelemetry_exporter_ostream_span ${CURL_LIBRARIES}
1212
nlohmann_json::nlohmann_json)
13+
if(nlohmann_json_clone)
14+
add_dependencies(w3c_tracecontext_test nlohmann_json::nlohmann_json)
15+
endif()
16+
1317
endif()

0 commit comments

Comments
 (0)