File: opentracing-cpp.cmake

package info (click to toggle)
opentelemetry-cpp 1.23.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,368 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 38; python: 31
file content (80 lines) | stat: -rw-r--r-- 3,085 bytes parent folder | download
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
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

find_package(OpenTracing CONFIG QUIET)
set(OpenTracing_PROVIDER "find_package")

if(NOT OpenTracing_FOUND)
  set(_OPENTRACING_SUBMODULE_DIR "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentracing-cpp")
  if(EXISTS "${_OPENTRACING_SUBMODULE_DIR}/.git")
    FetchContent_Declare(
       "opentracing"
       SOURCE_DIR "${_OPENTRACING_SUBMODULE_DIR}"
       )
    set(OpenTracing_PROVIDER "fetch_source")
  else()
    FetchContent_Declare(
      "opentracing"
      GIT_REPOSITORY  "https://github.com/opentracing/opentracing-cpp.git"
      GIT_TAG "${opentracing-cpp_GIT_TAG}"
      )
    set(OpenTracing_PROVIDER "fetch_repository")
  endif()

  # OpenTracing uses the BUILD_TESTING variable directly and we must force the cached value to OFF.
  # save the current state of BUILD_TESTING
  if(DEFINED BUILD_TESTING)
    set(_SAVED_BUILD_TESTING ${BUILD_TESTING})
  endif()

  if(DEFINED CMAKE_POLICY_VERSION_MINIMUM)
    set(_SAVED_CMAKE_POLICY_VERSION_MINIMUM ${CMAKE_POLICY_VERSION_MINIMUM})
  endif()

  # Set the cache variables for the opentracing build
  set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
  set(BUILD_MOCKTRACER OFF CACHE BOOL "" FORCE)
  set(CMAKE_POLICY_VERSION_MINIMUM "3.5" CACHE STRING "" FORCE)

  FetchContent_MakeAvailable(opentracing)

  # Restore the saved state of BUILD_TESTING
  if(DEFINED _SAVED_BUILD_TESTING)
    set(BUILD_TESTING ${_SAVED_BUILD_TESTING} CACHE BOOL "" FORCE)
  else()
    unset(BUILD_TESTING CACHE)
  endif()

  # Restore the saved state of CMAKE_POLICY_VERSION_MINIMUM
  if(DEFINED _SAVED_CMAKE_POLICY_VERSION_MINIMUM)
    set(CMAKE_POLICY_VERSION_MINIMUM ${_SAVED_CMAKE_POLICY_VERSION_MINIMUM} CACHE STRING "" FORCE)
  else()
    unset(CMAKE_POLICY_VERSION_MINIMUM CACHE)
  endif()

  # Patch the opentracing targets to set missing includes, add namespaced alias targets, disable iwyu and clang-tidy.
  foreach(_target opentracing opentracing-static)
    if(TARGET ${_target})
      # Add missing include directories
      target_include_directories(${_target} PUBLIC
        "$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/include>"
        "$<BUILD_INTERFACE:${opentracing_SOURCE_DIR}/3rd_party/include>"
        "$<BUILD_INTERFACE:${opentracing_BINARY_DIR}/include>"
        )
      # Disable CXX_INCLUDE_WHAT_YOU_USE and CXX_CLANG_TIDY
      set_target_properties(${_target}
                          PROPERTIES CXX_INCLUDE_WHAT_YOU_USE "" CXX_CLANG_TIDY "")
      # Create alias targets
      if(NOT TARGET OpenTracing::${_target})
        add_library(OpenTracing::${_target} ALIAS ${_target})
      endif()
    endif()
  endforeach()

  # Set the OpenTracing_VERSION variable from the git tag.
  string(REGEX REPLACE "^v([0-9]+\\.[0-9]+\\.[0-9]+)$" "\\1" OpenTracing_VERSION "${opentracing-cpp_GIT_TAG}")
endif(NOT OpenTracing_FOUND)

if(NOT TARGET OpenTracing::opentracing AND NOT TARGET OpenTracing::opentracing-static)
  message(FATAL_ERROR "No OpenTracing targets (OpenTracing::opentracing or OpenTracing::opentracing-static) were imported")
endif()