22# SPDX-License-Identifier: Apache-2.0
33
44#
5- # The dependency on opentelemetry-proto can be provided by order
6- # of decreasing priority, options are:
5+ # The dependency on opentelemetry-proto can be provided by order of decreasing
6+ # priority, options are:
77#
8- # 1 - Fetch from local source directory defined by the OTELCPP_PROTO_PATH variable
8+ # 1 - Fetch from local source directory defined by the OTELCPP_PROTO_PATH
9+ # variable
910#
10- # 2 - Fetch from the opentelemetry-proto git submodule (opentelemetry-cpp/third_party/opentelemetry-proto)
11+ # 2 - Fetch from the opentelemetry-proto git submodule
12+ # (opentelemetry-cpp/third_party/opentelemetry-proto)
1113#
12- # 3 - Fetch from github using the git tag set in opentelemetry-cpp/third_party_release
14+ # 3 - Fetch from github using the git tag set in
15+ # opentelemetry-cpp/third_party_release
1316#
1417
15- set (OPENTELEMETRY_PROTO_SUBMODULE "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentelemetry-proto" )
18+ set (OPENTELEMETRY_PROTO_SUBMODULE
19+ "${opentelemetry-cpp_SOURCE_DIR}/third_party/opentelemetry-proto" )
1620
1721if (OTELCPP_PROTO_PATH)
1822 if (NOT EXISTS
@@ -21,29 +25,32 @@ if(OTELCPP_PROTO_PATH)
2125 FATAL_ERROR
2226 "OTELCPP_PROTO_PATH does not point to a opentelemetry-proto repository" )
2327 endif ()
24- message (STATUS "fetching opentelemetry-proto from OTELCPP_PROTO_PATH=${OTELCPP_PROTO_PATH} " )
25- FetchContent_Declare(
26- opentelemetry-proto
27- SOURCE_DIR ${OTELCPP_PROTO_PATH}
28+ message (
29+ STATUS
30+ "fetching opentelemetry-proto from OTELCPP_PROTO_PATH=${OTELCPP_PROTO_PATH} "
2831 )
32+ FetchContent_Declare(opentelemetry-proto SOURCE_DIR ${OTELCPP_PROTO_PATH} )
2933 set (opentelemetry-proto_PROVIDER "fetch_source" )
30- # If the opentelemetry-proto directory is a general directory then we don't have a good way to determine the version. Set it as unknown.
34+ # If the opentelemetry-proto directory is a general directory then we don't
35+ # have a good way to determine the version. Set it as unknown.
3136 set (opentelemetry-proto_VERSION "unknown" )
3237elseif (EXISTS ${OPENTELEMETRY_PROTO_SUBMODULE} /.git)
33- message (STATUS "fetching opentelemetry-proto from git submodule" )
34- FetchContent_Declare(
35- opentelemetry-proto
36- SOURCE_DIR ${OPENTELEMETRY_PROTO_SUBMODULE}
37- )
38+ message (STATUS "fetching opentelemetry-proto from git submodule" )
39+ FetchContent_Declare(opentelemetry-proto SOURCE_DIR
40+ ${OPENTELEMETRY_PROTO_SUBMODULE} )
3841 set (opentelemetry-proto_PROVIDER "fetch_source" )
39- string (REGEX REPLACE "^v([0-9]+\\ .[0-9]+\\ .[0-9]+)$" "\\ 1" opentelemetry-proto_VERSION "${opentelemetry-proto_GIT_TAG}" )
42+ string (REGEX
43+ REPLACE "^v([0-9]+\\ .[0-9]+\\ .[0-9]+)$" "\\ 1"
44+ opentelemetry-proto_VERSION "${opentelemetry-proto_GIT_TAG}" )
4045else ()
4146 FetchContent_Declare(
42- opentelemetry-proto
43- GIT_REPOSITORY https://github.com/open-telemetry/opentelemetry-proto.git
44- GIT_TAG "${opentelemetry-proto_GIT_TAG}" )
47+ opentelemetry-proto
48+ GIT_REPOSITORY https://github.com/open-telemetry/opentelemetry-proto.git
49+ GIT_TAG "${opentelemetry-proto_GIT_TAG}" )
4550 set (opentelemetry-proto_PROVIDER "fetch_repository" )
46- string (REGEX REPLACE "^v([0-9]+\\ .[0-9]+\\ .[0-9]+)$" "\\ 1" opentelemetry-proto_VERSION "${opentelemetry-proto_GIT_TAG}" )
51+ string (REGEX
52+ REPLACE "^v([0-9]+\\ .[0-9]+\\ .[0-9]+)$" "\\ 1"
53+ opentelemetry-proto_VERSION "${opentelemetry-proto_GIT_TAG}" )
4754endif ()
4855
4956FetchContent_MakeAvailable(opentelemetry-proto)
@@ -174,8 +181,10 @@ foreach(IMPORT_DIR ${PROTOBUF_IMPORT_DIRS})
174181 list (APPEND PROTOBUF_INCLUDE_FLAGS "-I${IMPORT_DIR} " )
175182endforeach ()
176183
177- set (PROTOBUF_COMMON_FLAGS "--proto_path=${PROTO_PATH} "
178- "--cpp_out=${GENERATED_PROTOBUF_PATH} " )
184+ set (PROTOBUF_COMMON_FLAGS
185+ "--proto_path=${PROTO_PATH} "
186+ "--cpp_out=dllexport_decl=OPENTELEMETRY_PROTO_API:${GENERATED_PROTOBUF_PATH} "
187+ )
179188# --experimental_allow_proto3_optional is available from 3.13 and be stable and
180189# enabled by default from 3.16
181190if (Protobuf_VERSION AND Protobuf_VERSION VERSION_LESS "3.16" )
@@ -276,13 +285,13 @@ add_custom_command(
276285 DEPENDS ${PROTOBUF_GENERATE_DEPENDS} )
277286
278287unset (OTELCPP_PROTO_TARGET_OPTIONS)
279- if (CMAKE_SYSTEM_NAME MATCHES "Windows|MinGW|WindowsStore" )
280- list (APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC )
281- elseif ((NOT protobuf_lib_type STREQUAL "STATIC_LIBRARY" )
282- AND (NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS ))
288+ if ((NOT protobuf_lib_type STREQUAL "STATIC_LIBRARY" )
289+ AND (NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS ))
283290 list (APPEND OTELCPP_PROTO_TARGET_OPTIONS SHARED)
291+ set (OTELCPP_PROTO_LIB_TYPE "SHARED_LIBRARY" )
284292else ()
285293 list (APPEND OTELCPP_PROTO_TARGET_OPTIONS STATIC )
294+ set (OTELCPP_PROTO_LIB_TYPE "STATIC_LIBRARY" )
286295endif ()
287296
288297set (OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto)
@@ -299,6 +308,14 @@ add_library(
299308 ${METRICS_SERVICE_PB_CPP_FILE} )
300309set_target_version(opentelemetry_proto)
301310
311+ if (OTELCPP_PROTO_LIB_TYPE STREQUAL "SHARED_LIBRARY" )
312+ project_build_tools_set_shared_library_declaration(OPENTELEMETRY_PROTO_API
313+ opentelemetry_proto)
314+ else ()
315+ project_build_tools_set_static_library_declaration(OPENTELEMETRY_PROTO_API
316+ opentelemetry_proto)
317+ endif ()
318+
302319target_include_directories (
303320 opentelemetry_proto PUBLIC "$<BUILD_INTERFACE:${GENERATED_PROTOBUF_PATH} >"
304321 "$<INSTALL_INTERFACE:include>" )
@@ -323,10 +340,20 @@ if(WITH_OTLP_GRPC)
323340 ${LOGS_SERVICE_GRPC_PB_CPP_FILE} ${METRICS_SERVICE_GRPC_PB_CPP_FILE} )
324341 set_target_version(opentelemetry_proto_grpc)
325342
343+ if (OTELCPP_PROTO_LIB_TYPE STREQUAL "SHARED_LIBRARY" )
344+ if (CMAKE_SYSTEM_NAME MATCHES "Windows|MinGW|WindowsStore" )
345+ set_target_properties (opentelemetry_proto_grpc
346+ PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON )
347+ endif ()
348+ endif ()
349+
326350 # Disable include-what-you-use and clang-tidy on generated code.
327351 set_target_properties (
328- opentelemetry_proto_grpc PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ""
329- CXX_CLANG_TIDY "" )
352+ opentelemetry_proto_grpc
353+ PROPERTIES CXX_INCLUDE_WHAT_YOU_USE ""
354+ CXX_CLANG_TIDY ""
355+ C_VISIBILITY_PRESET "default"
356+ CXX_VISIBILITY_PRESET "default" )
330357
331358 list (APPEND OPENTELEMETRY_PROTO_TARGETS opentelemetry_proto_grpc)
332359 target_link_libraries (opentelemetry_proto_grpc PUBLIC opentelemetry_proto)
0 commit comments