opentelemetry-cpp-config.cmake 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. # Copyright The OpenTelemetry Authors
  2. # SPDX-License-Identifier: Apache-2.0
  3. #.rst:
  4. # opentelemetry-cpp-config.cmake
  5. # --------
  6. # Finding opentelemetry-cpp in CMake projects
  7. # ========================================
  8. #
  9. # - find_package(opentelemetry-cpp CONFIG REQUIRED) to import all installed targets and dependencies
  10. # - find_package(opentelemetry-cpp CONFIG COMPONENTS ...) to import specific components' targets and dependencies
  11. #
  12. # Example usage
  13. # -------------------
  14. #
  15. # 1. **No Components Specified**
  16. #
  17. # When no components are provided, all components and their targets are imported.
  18. #
  19. # .. code-block:: cmake
  20. #
  21. # find_package(opentelemetry-cpp CONFIG REQUIRED)
  22. #
  23. #
  24. # 2. **Components Specified**
  25. #
  26. # When a component is specified, its third-party dependencies are found;
  27. # then, targets from that component, along with the components on which it depends, are imported.
  28. #
  29. # .. code-block:: cmake
  30. #
  31. # find_package(opentelemetry-cpp CONFIG REQUIRED COMPONENTS exporters_otlp_grpc)
  32. #
  33. #
  34. #.. note::
  35. # To troubleshoot issues with ``find_package(opentelemetry-cpp CONFIG REQUIRED)``, run CMake with debug logging enabled:
  36. #
  37. # .. code-block:: bash
  38. #
  39. # cmake --log-level=DEBUG -S <source_dir> -B <build_dir>
  40. #
  41. # To get more verbose output from CMake’s package search, run CMake with the following flag:
  42. #
  43. # .. code-block:: bash
  44. #
  45. # cmake -DCMAKE_FIND_DEBUG_MODE=ON -S <source_dir> -B <build_dir>
  46. #
  47. #
  48. # CMake Variables Defined
  49. # --------------------
  50. #
  51. # This module defines the following variables:
  52. #
  53. # ::
  54. #
  55. # OPENTELEMETRY_CPP_INCLUDE_DIRS - Include directories of opentelemetry-cpp.
  56. # OPENTELEMETRY_CPP_LIBRARY_DIRS - Link directories of opentelemetry-cpp.
  57. # OPENTELEMETRY_CPP_LIBRARIES - List of libraries when using opentelemetry-cpp.
  58. # OPENTELEMETRY_CPP_FOUND - True if opentelemetry-cpp found.
  59. # OPENTELEMETRY_ABI_VERSION_NO - ABI version of opentelemetry-cpp.
  60. # OPENTELEMETRY_VERSION - Version of opentelemetry-cpp.
  61. # OPENTELEMETRY_CPP_COMPONENTS_INSTALLED - List of components installed.
  62. # opentelemetry-cpp_FOUND - True if opentelemetry-cpp found.
  63. # opentelemetry-cpp_<component>_FOUND - True if the requested component is found.
  64. # ::
  65. #
  66. #
  67. # CMake Components and Targets Supported
  68. # --------------------
  69. # opentelemetry-cpp supports the following components and targets. This install may include a subset.
  70. #
  71. # COMPONENTS
  72. # api
  73. # sdk
  74. # ext_common
  75. # ext_http_curl
  76. # ext_dll
  77. # exporters_in_memory
  78. # exporters_ostream
  79. # exporters_otlp_common
  80. # exporters_otlp_file
  81. # exporters_otlp_grpc
  82. # exporters_otlp_http
  83. # exporters_prometheus
  84. # exporters_elasticsearch
  85. # exporters_etw
  86. # exporters_zipkin
  87. # shims_opentracing
  88. #
  89. # ::
  90. #
  91. # TARGETS
  92. # opentelemetry-cpp::api - Imported target of COMPONENT api
  93. # opentelemetry-cpp::sdk - Imported target of COMPONENT sdk
  94. # opentelemetry-cpp::version - Imported target of COMPONENT sdk
  95. # opentelemetry-cpp::common - Imported target of COMPONENT sdk
  96. # opentelemetry-cpp::resources - Imported target of COMPONENT sdk
  97. # opentelemetry-cpp::trace - Imported target of COMPONENT sdk
  98. # opentelemetry-cpp::metrics - Imported target of COMPONENT sdk
  99. # opentelemetry-cpp::logs - Imported target of COMPONENT sdk
  100. # opentelemetry-cpp::ext - Imported target of COMPONENT ext_common
  101. # opentelemetry-cpp::http_client_curl - Imported target of COMPONENT ext_http_curl
  102. # opentelemetry-cpp::opentelemetry_cpp - Imported target of COMPONENT ext_dll
  103. # opentelemetry-cpp::in_memory_span_exporter - Imported target of COMPONENT exporters_in_memory
  104. # opentelemetry-cpp::in_memory_metric_exporter - Imported target of COMPONENT exporters_in_memory
  105. # opentelemetry-cpp::ostream_log_record_exporter - Imported target of COMPONENT exporters_ostream
  106. # opentelemetry-cpp::ostream_metrics_exporter - Imported target of COMPONENT exporters_ostream
  107. # opentelemetry-cpp::ostream_span_exporter - Imported target of COMPONENT exporters_ostream
  108. # opentelemetry-cpp::proto - Imported target of COMPONENT exporters_otlp_common
  109. # opentelemetry-cpp::otlp_recordable - Imported target of COMPONENT exporters_otlp_common
  110. # opentelemetry-cpp::otlp_file_client - Imported target of COMPONENT exporters_otlp_file
  111. # opentelemetry-cpp::otlp_file_exporter - Imported target of COMPONENT exporters_otlp_file
  112. # opentelemetry-cpp::otlp_file_log_record_exporter - Imported target of COMPONENT exporters_otlp_file
  113. # opentelemetry-cpp::otlp_file_metric_exporter - Imported target of COMPONENT exporters_otlp_file
  114. # opentelemetry-cpp::proto_grpc - Imported target of COMPONENT exporters_otlp_grpc
  115. # opentelemetry-cpp::otlp_grpc_client - Imported target of COMPONENT exporters_otlp_grpc
  116. # opentelemetry-cpp::otlp_grpc_exporter - Imported target of COMPONENT exporters_otlp_grpc
  117. # opentelemetry-cpp::otlp_grpc_log_record_exporter - Imported target of COMPONENT exporters_otlp_grpc
  118. # opentelemetry-cpp::otlp_grpc_metrics_exporter - Imported target of COMPONENT exporters_otlp_grpc
  119. # opentelemetry-cpp::otlp_http_client - Imported target of COMPONENT exporters_otlp_http
  120. # opentelemetry-cpp::otlp_http_exporter - Imported target of COMPONENT exporters_otlp_http
  121. # opentelemetry-cpp::otlp_http_log_record_exporter - Imported target of COMPONENT exporters_otlp_http
  122. # opentelemetry-cpp::otlp_http_metric_exporter - Imported target of COMPONENT exporters_otlp_http
  123. # opentelemetry-cpp::prometheus_exporter - Imported target of COMPONENT exporters_prometheus
  124. # opentelemetry-cpp::elasticsearch_log_record_exporter - Imported target of COMPONENT exporters_elasticsearch
  125. # opentelemetry-cpp::etw_exporter - Imported target of COMPONENT exporters_etw
  126. # opentelemetry-cpp::zipkin_trace_exporter - Imported target of COMPONENT exporters_zipkin
  127. # opentelemetry-cpp::opentracing_shim - Imported target of COMPONENT shims_opentracing
  128. #
  129. # Additional Files Used in Component to Component and Third-Party Dependency Resolution
  130. # --------------------------------------------------------
  131. #
  132. # - **thirdparty-dependency-definitions.cmake**
  133. # This file lists the third-party dependencies supported by opentelemetry-cpp and components that may require them.
  134. # Dependencies are found in the order defined in this file when find_package(opentelemetry-cpp …) is invoked.
  135. #
  136. # **Found using CMake CONFIG search mode:**
  137. #
  138. # - **absl**
  139. # - **nlohmann_json**
  140. # - **Protobuf**
  141. # - **gRPC**
  142. # - **prometheus-cpp**
  143. # - **OpenTracing**
  144. #
  145. # **Found using the CMake MODULE search mode:**
  146. #
  147. # - **Threads**
  148. # - **ZLIB**
  149. # - **CURL**
  150. #
  151. # - **component-definitions.cmake**
  152. # This file defines the available opentelemetry-cpp components, the targets associated with each
  153. # component, and the inter-component dependencies.
  154. #
  155. # =============================================================================
  156. # Copyright The OpenTelemetry Authors
  157. # SPDX-License-Identifier: Apache-2.0
  158. # =============================================================================
  159. set(OPENTELEMETRY_ABI_VERSION_NO
  160. "1"
  161. CACHE STRING "opentelemetry-cpp ABI version" FORCE)
  162. set(OPENTELEMETRY_VERSION
  163. "1.21.0"
  164. CACHE STRING "opentelemetry-cpp version" FORCE)
  165. ####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
  166. ####### Any changes to this file will be overwritten by the next CMake run ####
  167. ####### The input file was opentelemetry-cpp-config.cmake.in ########
  168. get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
  169. macro(set_and_check _var _file)
  170. set(${_var} "${_file}")
  171. if(NOT EXISTS "${_file}")
  172. message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  173. endif()
  174. endmacro()
  175. macro(check_required_components _NAME)
  176. foreach(comp ${${_NAME}_FIND_COMPONENTS})
  177. if(NOT ${_NAME}_${comp}_FOUND)
  178. if(${_NAME}_FIND_REQUIRED_${comp})
  179. set(${_NAME}_FOUND FALSE)
  180. endif()
  181. endif()
  182. endforeach()
  183. endmacro()
  184. ####################################################################################
  185. # Include the opentelemetry-cpp file that includes component defintions, thirdparty definitons and functions to support finding this package and dependencies.
  186. include("${CMAKE_CURRENT_LIST_DIR}/find-package-support-functions.cmake")
  187. set(_INSTALLED_COMPONENTS "")
  188. get_installed_components(_INSTALLED_COMPONENTS)
  189. set(OPENTELEMETRY_CPP_COMPONENTS_INSTALLED ${_INSTALLED_COMPONENTS} CACHE STRING "opentelemetry-cpp components installed" FORCE)
  190. set(_REQUESTED_COMPONENTS "")
  191. get_requested_components(_INSTALLED_COMPONENTS _REQUESTED_COMPONENTS)
  192. find_required_dependencies(_REQUESTED_COMPONENTS)
  193. set_and_check(OPENTELEMETRY_CPP_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include")
  194. set_and_check(OPENTELEMETRY_CPP_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")
  195. # include the target files selected and set the component found flag
  196. foreach(_COMPONENT IN LISTS _REQUESTED_COMPONENTS)
  197. include("${CMAKE_CURRENT_LIST_DIR}/opentelemetry-cpp-${_COMPONENT}-target.cmake")
  198. set(${CMAKE_FIND_PACKAGE_NAME}_${_COMPONENT}_FOUND TRUE
  199. CACHE BOOL "whether ${CMAKE_FIND_PACKAGE_NAME} component ${_COMPONENT} is found" FORCE)
  200. endforeach()
  201. # get installed and requested targets
  202. set(_OPENTELEMETRY_CPP_TARGETS "")
  203. get_targets(_REQUESTED_COMPONENTS _OPENTELEMETRY_CPP_TARGETS)
  204. check_targets_imported(_OPENTELEMETRY_CPP_TARGETS)
  205. # Set OPENTELEMETRY_CPP_* variables
  206. set(OPENTELEMETRY_CPP_LIBRARIES)
  207. set(DLL_TARGET "opentelemetry-cpp::opentelemetry_cpp")
  208. foreach(_TARGET IN LISTS _OPENTELEMETRY_CPP_TARGETS)
  209. if(TARGET "${_TARGET}" AND NOT "${_TARGET}" STREQUAL "${DLL_TARGET}")
  210. list(APPEND OPENTELEMETRY_CPP_LIBRARIES "${_TARGET}")
  211. endif()
  212. endforeach()
  213. # handle the QUIETLY and REQUIRED arguments and set opentelemetry-cpp_FOUND to
  214. # TRUE if all variables listed contain valid results, e.g. valid file paths.
  215. include("FindPackageHandleStandardArgs")
  216. find_package_handle_standard_args(
  217. ${CMAKE_FIND_PACKAGE_NAME}
  218. FOUND_VAR ${CMAKE_FIND_PACKAGE_NAME}_FOUND
  219. REQUIRED_VARS OPENTELEMETRY_CPP_INCLUDE_DIRS OPENTELEMETRY_CPP_LIBRARIES)
  220. if(${CMAKE_FIND_PACKAGE_NAME}_FOUND)
  221. set(OPENTELEMETRY_CPP_FOUND
  222. ${${CMAKE_FIND_PACKAGE_NAME}_FOUND}
  223. CACHE BOOL "whether opentelemetry-cpp is found" FORCE)
  224. else()
  225. unset(OPENTELEMETRY_CPP_FOUND)
  226. unset(OPENTELEMETRY_CPP_FOUND CACHE)
  227. endif()
  228. check_required_components(${CMAKE_FIND_PACKAGE_NAME})