Skip to content

Commit 7e31660

Browse files
authored
Merge branch 'main' into fix_clang_tidy_warnings_part_6
2 parents c01188d + 1ad6674 commit 7e31660

File tree

12 files changed

+222
-236
lines changed

12 files changed

+222
-236
lines changed

.github/workflows/cmake_install.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ jobs:
215215
run: ./ci/do_ci.sh cmake.opentracing_shim.install.test
216216

217217
ubuntu_2404_conan_latest:
218-
name: Ubuntu 24.04 conan latest versions cxx17 (static libs)
218+
name: Ubuntu 24.04 conan latest versions cxx17 (static libs - opentracing shim)
219219
runs-on: ubuntu-24.04
220220
env:
221221
INSTALL_TEST_DIR: '/home/runner/install_test'
@@ -248,6 +248,8 @@ jobs:
248248
run: |
249249
export PKG_CONFIG_PATH=$INSTALL_TEST_DIR/lib/pkgconfig:$PKG_CONFIG_PATH
250250
./ci/verify_packages.sh
251+
- name: Run OpenTracing Shim Test
252+
run: ./ci/do_ci.sh cmake.opentracing_shim.install.test
251253

252254
macos_14_conan_stable:
253255
name: macOS 14 conan stable versions cxx17 (static libs)

CMakeLists.txt

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ project(opentelemetry-cpp)
3636
# Mark variables as used so cmake doesn't complain about them
3737
mark_as_advanced(CMAKE_TOOLCHAIN_FILE)
3838

39-
# Note: CMAKE_FIND_PACKAGE_PREFER_CONFIG requires cmake 3.15. Prefer cmake
40-
# CONFIG search mode to find dependencies. This is important to properly find
41-
# protobuf versions 3.22.0 and above due to the abseil-cpp dependency.
42-
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)
43-
4439
# Don't use customized cmake modules if vcpkg is used to resolve dependence.
4540
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
4641
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/")
@@ -79,10 +74,6 @@ if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
7974
CACHE STRING "")
8075
endif()
8176

82-
if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
83-
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
84-
endif()
85-
8677
option(WITH_ABI_VERSION_1 "ABI version 1" ON)
8778
option(WITH_ABI_VERSION_2 "EXPERIMENTAL: ABI version 2 preview" OFF)
8879

@@ -310,49 +301,7 @@ endif()
310301
include(GNUInstallDirs)
311302

312303
if(WITH_PROMETHEUS)
313-
find_package(prometheus-cpp CONFIG QUIET)
314-
if(NOT prometheus-cpp_FOUND)
315-
message(STATUS "Trying to use local prometheus-cpp from submodule")
316-
if(EXISTS ${PROJECT_SOURCE_DIR}/third_party/prometheus-cpp/.git)
317-
set(SAVED_ENABLE_TESTING ${ENABLE_TESTING})
318-
set(SAVED_CMAKE_CXX_CLANG_TIDY ${CMAKE_CXX_CLANG_TIDY})
319-
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
320-
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
321-
set(ENABLE_TESTING OFF)
322-
set(CMAKE_CXX_CLANG_TIDY "")
323-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
324-
add_subdirectory(third_party/prometheus-cpp)
325-
set(ENABLE_TESTING ${SAVED_ENABLE_TESTING})
326-
set(CMAKE_CXX_CLANG_TIDY ${SAVED_CMAKE_CXX_CLANG_TIDY})
327-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
328-
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
329-
330-
# Get the version of the prometheus-cpp submodule
331-
find_package(Git QUIET)
332-
if(Git_FOUND)
333-
execute_process(
334-
COMMAND ${GIT_EXECUTABLE} describe --tags --always
335-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/third_party/prometheus-cpp
336-
OUTPUT_VARIABLE prometheus-cpp_VERSION
337-
OUTPUT_STRIP_TRAILING_WHITESPACE)
338-
string(REGEX REPLACE "^v" "" prometheus-cpp_VERSION
339-
"${prometheus-cpp_VERSION}")
340-
endif()
341-
342-
message(
343-
STATUS
344-
"Using local prometheus-cpp from submodule. Version = ${prometheus-cpp_VERSION}"
345-
)
346-
else()
347-
message(
348-
FATAL_ERROR
349-
"\nprometheus-cpp package was not found. Please either provide it manually or clone with submodules. "
350-
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
351-
"git submodule update --init --recursive")
352-
endif()
353-
else()
354-
message(STATUS "Using external prometheus-cpp")
355-
endif()
304+
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/prometheus-cpp.cmake")
356305
endif()
357306

358307
if(WITH_OTLP_GRPC
@@ -497,6 +446,14 @@ if((NOT WITH_API_ONLY) AND USE_NLOHMANN_JSON)
497446
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/nlohmann-json.cmake")
498447
endif()
499448

449+
#
450+
# Do we need OpenTracing ?
451+
#
452+
453+
if(WITH_OPENTRACING)
454+
include("${opentelemetry-cpp_SOURCE_DIR}/cmake/opentracing-cpp.cmake")
455+
endif()
456+
500457
if(OTELCPP_MAINTAINER_MODE)
501458
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
502459
message(STATUS "Building with gcc in maintainer mode.")
@@ -696,10 +653,18 @@ if(ZLIB_FOUND)
696653
message(STATUS "ZLIB: ${ZLIB_VERSION}")
697654
endif()
698655
if(USE_NLOHMANN_JSON)
699-
message(STATUS "nlohmann-json: ${nlohmann_json_VERSION}")
656+
message(
657+
STATUS "nlohmann-json: ${nlohmann_json_VERSION} (${nlohmann_json_PROVIDER})"
658+
)
659+
endif()
660+
if(WITH_PROMETHEUS)
661+
message(
662+
STATUS
663+
"prometheus-cpp: ${prometheus-cpp_VERSION} (${prometheus-cpp_PROVIDER})")
700664
endif()
701-
if(prometheus-cpp_FOUND)
702-
message(STATUS "prometheus-cpp: ${prometheus-cpp_VERSION}")
665+
if(WITH_OPENTRACING)
666+
message(
667+
STATUS "opentracing-cpp: ${OpenTracing_VERSION} (${OpenTracing_PROVIDER})")
703668
endif()
704669
message(STATUS "---------------------------------------------")
705670

@@ -724,30 +689,6 @@ endif()
724689
add_subdirectory(api)
725690

726691
if(WITH_OPENTRACING)
727-
find_package(OpenTracing CONFIG QUIET)
728-
if(NOT OpenTracing_FOUND)
729-
set(OPENTRACING_DIR "third_party/opentracing-cpp")
730-
message(STATUS "Trying to use local ${OPENTRACING_DIR} from submodule")
731-
if(EXISTS "${PROJECT_SOURCE_DIR}/${OPENTRACING_DIR}/.git")
732-
set(SAVED_BUILD_TESTING ${BUILD_TESTING})
733-
set(BUILD_TESTING OFF)
734-
set(SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
735-
${CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
736-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "")
737-
add_subdirectory(${OPENTRACING_DIR})
738-
set(BUILD_TESTING ${SAVED_BUILD_TESTING})
739-
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
740-
${SAVED_CMAKE_CXX_INCLUDE_WHAT_YOU_USE})
741-
else()
742-
message(
743-
FATAL_ERROR
744-
"\nopentracing-cpp package was not found. Please either provide it manually or clone with submodules. "
745-
"To initialize, fetch and checkout any nested submodules, you can use the following command:\n"
746-
"git submodule update --init --recursive")
747-
endif()
748-
else()
749-
message(STATUS "Using external opentracing-cpp")
750-
endif()
751692
add_subdirectory(opentracing-shim)
752693
endif()
753694

cmake/nlohmann-json.cmake

Lines changed: 39 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,48 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
#
5-
# The dependency on nlohmann_json can be provided different ways. By order of
6-
# 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, as it already is.
13-
#
14-
# 2 - Search for a nlohmann_json git submodule
15-
#
16-
# When git submodule is used, the nlohmann_json code is located in:
17-
# third_party/nlohmann-json
18-
#
19-
# The nlohmann_json dependency is installed, by building the sub directory with
20-
# JSON_Install=ON
21-
#
22-
# 3 - Download nlohmann_json from github
23-
#
24-
# Code from the development branch is used, unless a specific release tag is
25-
# provided in variable ${nlohmann-json}
26-
#
27-
# The nlohmann_json dependency is installed, by building the downloaded code
28-
# with JSON_Install=ON
29-
#
4+
# Import nlohmann_json target (nlohmann_json::nlohmann_json).
5+
# 1. Find an installed nlohmann-json package
6+
# 2. Use FetchContent to build nlohmann-json from a git submodule
7+
# 3. Use FetchContent to fetch and build nlohmann-json from GitHub
308

31-
# nlohmann_json package is required for most SDK build configurations
32-
find_package(nlohmann_json QUIET)
33-
set(nlohmann_json_clone FALSE)
34-
if(nlohmann_json_FOUND)
35-
message(STATUS "nlohmann::json dependency satisfied by: package")
36-
elseif(TARGET nlohmann_json)
37-
message(STATUS "nlohmann::json is already added as a CMake target!")
38-
elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git
39-
AND EXISTS
40-
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/CMakeLists.txt)
41-
message(STATUS "nlohmann::json dependency satisfied by: git submodule")
42-
set(JSON_BuildTests
43-
OFF
44-
CACHE INTERNAL "")
45-
set(JSON_Install
46-
ON
47-
CACHE INTERNAL "")
48-
# This option allows to link nlohmann_json::nlohmann_json target
49-
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/nlohmann-json)
50-
# This option allows to add header to include directories
51-
include_directories(
52-
${PROJECT_SOURCE_DIR}/third_party/nlohmann-json/single_include)
53-
else()
54-
if("${nlohmann-json}" STREQUAL "")
55-
set(nlohmann-json "develop")
9+
find_package(nlohmann_json CONFIG QUIET)
10+
set(nlohmann_json_PROVIDER "find_package")
11+
12+
if(NOT nlohmann_json_FOUND)
13+
set(_NLOHMANN_JSON_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/nlohmann-json")
14+
if(EXISTS "${_NLOHMANN_JSON_SUBMODULE_DIR}/.git")
15+
FetchContent_Declare(
16+
"nlohmann_json"
17+
SOURCE_DIR "${_NLOHMANN_JSON_SUBMODULE_DIR}"
18+
)
19+
set(nlohmann_json_PROVIDER "fetch_source")
20+
else()
21+
FetchContent_Declare(
22+
"nlohmann_json"
23+
GIT_REPOSITORY "https://github.com/nlohmann/json.git"
24+
GIT_TAG "${nlohmann-json_GIT_TAG}"
25+
)
26+
set(nlohmann_json_PROVIDER "fetch_repository")
5627
endif()
57-
message(STATUS "nlohmann::json dependency satisfied by: github download")
58-
set(nlohmann_json_clone TRUE)
59-
include(ExternalProject)
60-
ExternalProject_Add(
61-
nlohmann_json_download
62-
PREFIX third_party
63-
GIT_REPOSITORY https://github.com/nlohmann/json.git
64-
GIT_TAG "${nlohmann-json_GIT_TAG}"
65-
UPDATE_COMMAND ""
66-
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
67-
-DJSON_BuildTests=OFF -DJSON_Install=ON
68-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
69-
TEST_AFTER_INSTALL 0
70-
DOWNLOAD_NO_PROGRESS 1
71-
LOG_CONFIGURE 1
72-
LOG_BUILD 1
73-
LOG_INSTALL 1)
7428

75-
ExternalProject_Get_Property(nlohmann_json_download INSTALL_DIR)
76-
set(NLOHMANN_JSON_INCLUDE_DIR
77-
${INSTALL_DIR}/src/nlohmann_json_download/single_include)
78-
add_library(nlohmann_json_ INTERFACE)
79-
target_include_directories(
80-
nlohmann_json_ INTERFACE "$<BUILD_INTERFACE:${NLOHMANN_JSON_INCLUDE_DIR}>"
81-
"$<INSTALL_INTERFACE:include>")
82-
add_dependencies(nlohmann_json_ nlohmann_json_download)
83-
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json_)
29+
set(JSON_BuildTests OFF CACHE BOOL "" FORCE)
30+
set(JSON_Install ${OPENTELEMETRY_INSTALL} CACHE BOOL "" FORCE)
31+
set(JSON_MultipleHeaders OFF CACHE BOOL "" FORCE)
32+
33+
FetchContent_MakeAvailable(nlohmann_json)
34+
35+
# Set the nlohmann_json_VERSION variable from the git tag.
36+
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" nlohmann_json_VERSION "${nlohmann-json_GIT_TAG}")
8437

85-
if(OPENTELEMETRY_INSTALL)
86-
install(
87-
TARGETS nlohmann_json_
88-
EXPORT "${PROJECT_NAME}-third_party_nlohmann_json_target"
89-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
90-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
91-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
92-
COMPONENT third_party_nlohmann_json)
38+
#Disable iwyu and clang-tidy
39+
if(TARGET nlohmann_json)
40+
set_target_properties(nlohmann_json PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ""
41+
CXX_CLANG_TIDY "")
9342
endif()
9443
endif()
44+
45+
if(NOT TARGET nlohmann_json::nlohmann_json)
46+
message(FATAL_ERROR "A required nlohmann_json target (nlohmann_json::nlohmann_json) was not imported")
47+
endif()
48+

cmake/opentracing-cpp.cmake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
find_package(OpenTracing CONFIG QUIET)
5+
set(OpenTracing_PROVIDER "find_package")
6+
7+
if(NOT OpenTracing_FOUND)
8+
set(_OPENTRACING_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentracing-cpp")
9+
if(EXISTS "${_OPENTRACING_SUBMODULE_DIR}/.git")
10+
FetchContent_Declare(
11+
"opentracing"
12+
SOURCE_DIR "${_OPENTRACING_SUBMODULE_DIR}"
13+
)
14+
set(OpenTracing_PROVIDER "fetch_source")
15+
else()
16+
FetchContent_Declare(
17+
"opentracing"
18+
GIT_REPOSITORY "https://github.com/opentracing/opentracing-cpp.git"
19+
GIT_TAG "${opentracing-cpp_GIT_TAG}"
20+
)
21+
set(OpenTracing_PROVIDER "fetch_repository")
22+
endif()
23+
24+
# OpenTracing uses the BUILD_TESTING variable directly and we must force the cached value to OFF.
25+
# save the current state of BUILD_TESTING
26+
if(DEFINED BUILD_TESTING)
27+
set(_SAVED_BUILD_TESTING ${BUILD_TESTING})
28+
endif()
29+
30+
# Set the cache variables for the opentracing build
31+
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
32+
set(BUILD_MOCKTRACER OFF CACHE BOOL "" FORCE)
33+
34+
FetchContent_MakeAvailable(opentracing)
35+
36+
# Restore the saved state of BUILD_TESTING
37+
if(DEFINED _SAVED_BUILD_TESTING)
38+
set(BUILD_TESTING ${_SAVED_BUILD_TESTING} CACHE BOOL "" FORCE)
39+
else()
40+
unset(BUILD_TESTING CACHE)
41+
endif()
42+
43+
# Patch the opentracing targets to set missing includes, add namespaced alias targets, disable iwyu and clang-tidy.
44+
foreach(_target opentracing opentracing-static)
45+
if(TARGET ${_target})
46+
# Add missing include directories
47+
target_include_directories(${_target} PUBLIC
48+
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/include>"
49+
"$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/3rd_party/include>"
50+
"$<BUILD_INTERFACE:${opentracing_BINARY_DIR}/include>"
51+
)
52+
# Disable CXX_INCLUDE_WHAT_YOU_USE and CXX_CLANG_TIDY
53+
set_target_properties(${_target}
54+
PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" CXX_CLANG_TIDY "")
55+
# Create alias targets
56+
if(NOT TARGET OpenTracing::${_target})
57+
add_library(OpenTracing::${_target} ALIAS ${_target})
58+
endif()
59+
endif()
60+
endforeach()
61+
62+
# Set the OpenTracing_VERSION variable from the git tag.
63+
string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" OpenTracing_VERSION "${opentracing-cpp_GIT_TAG}")
64+
endif(NOT OpenTracing_FOUND)
65+
66+
if(NOT TARGET OpenTracing::opentracing AND NOT TARGET OpenTracing::opentracing-static)
67+
message(FATAL_ERROR "No OpenTracing targets (OpenTracing::opentracing or OpenTracing::opentracing-static) were imported")
68+
endif()

0 commit comments

Comments
 (0)