From 7d4291fa91dee4cf7de9f9a1763f803af36598fd Mon Sep 17 00:00:00 2001 From: Tobias Mayer Date: Sat, 12 Oct 2024 09:30:26 +0200 Subject: [PATCH] Add a CMake option to disable shared libs This option is useful to support platforms that do not support dynamic libraries and `dlopen`. --- CMakeLists.txt | 4 ++++ api/test/singleton/CMakeLists.txt | 4 ++++ examples/plugin/plugin/CMakeLists.txt | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd41fa7148..98695e8918 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,10 @@ option(WITH_ASYNC_EXPORT_PREVIEW "Whether to enable async export" OFF) option(WITH_METRICS_EXEMPLAR_PREVIEW "Whether to enable exemplar within metrics" OFF) +option(OPENTELEMETRY_STATIC_ONLY + "Whether to build test libraries that are always linked as shared libs" + OFF) + # # Verify options dependencies # diff --git a/api/test/singleton/CMakeLists.txt b/api/test/singleton/CMakeLists.txt index 450308cd82..056ad4a77e 100644 --- a/api/test/singleton/CMakeLists.txt +++ b/api/test/singleton/CMakeLists.txt @@ -1,6 +1,10 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(OPENTELEMETRY_STATIC_ONLY) + return() +endif() + include(GoogleTest) # Header only singletons are not available in windows yet. diff --git a/examples/plugin/plugin/CMakeLists.txt b/examples/plugin/plugin/CMakeLists.txt index 50b247e4b0..f07061cf66 100644 --- a/examples/plugin/plugin/CMakeLists.txt +++ b/examples/plugin/plugin/CMakeLists.txt @@ -1,5 +1,9 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +if(OPENTELEMETRY_STATIC_ONLY) + return() +endif() + add_library(example_plugin SHARED tracer.cc factory_impl.cc) target_link_libraries(example_plugin opentelemetry_api)