From 3baadbaa7eb5961999acc507e82c859da24b864a Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Fri, 16 Oct 2020 19:27:19 +0300 Subject: [PATCH] allow to build library without tests and examples --- CMakeLists.txt | 11 +++++++++-- exporters/memory/CMakeLists.txt | 28 +++++++++++++++------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78ff1b5c89..e9b7cbc24f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,12 +16,17 @@ option(WITH_OTPROTOCOL option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK" OFF) +option(WITH_TESTS "Whether to enable tests" ON) +option(WITH_EXAMPLES "Whether to build examples" ON) + set(WITH_PROTOBUF OFF) if(WITH_OTPROTOCOL) set(WITH_PROTOBUF ON) endif() -include(CTest) +if(WITH_TESTS) + include(CTest) +endif() find_package(Threads) @@ -58,5 +63,7 @@ include_directories(sdk) add_subdirectory(sdk) include_directories(.) add_subdirectory(exporters) -add_subdirectory(examples) +if(WITH_EXAMPLES) + add_subdirectory(examples) +endif() add_subdirectory(ext) diff --git a/exporters/memory/CMakeLists.txt b/exporters/memory/CMakeLists.txt index d8475bce3c..aa8d334bd0 100644 --- a/exporters/memory/CMakeLists.txt +++ b/exporters/memory/CMakeLists.txt @@ -4,19 +4,21 @@ add_library(opentelemetry_exporter_in_memory INTERFACE) target_include_directories(opentelemetry_exporter_in_memory INTERFACE include/) -add_executable(in_memory_span_data_test test/in_memory_span_data_test.cc) -add_executable(in_memory_span_exporter_test - test/in_memory_span_exporter_test.cc) +if(BUILD_TESTING) + add_executable(in_memory_span_data_test test/in_memory_span_data_test.cc) + add_executable(in_memory_span_exporter_test + test/in_memory_span_exporter_test.cc) -target_link_libraries( - in_memory_span_data_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - opentelemetry_exporter_in_memory) + target_link_libraries( + in_memory_span_data_test ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} + opentelemetry_exporter_in_memory) -target_link_libraries( - in_memory_span_exporter_test ${GTEST_BOTH_LIBRARIES} - ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory) + target_link_libraries( + in_memory_span_exporter_test ${GTEST_BOTH_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} opentelemetry_exporter_in_memory) -gtest_add_tests(TARGET in_memory_span_data_test TEST_PREFIX exporter. TEST_LIST - in_memory_span_data_test) -gtest_add_tests(TARGET in_memory_span_exporter_test TEST_PREFIX exporter. - TEST_LIST in_memory_span_exporter_test) + gtest_add_tests(TARGET in_memory_span_data_test TEST_PREFIX exporter. + TEST_LIST in_memory_span_data_test) + gtest_add_tests(TARGET in_memory_span_exporter_test TEST_PREFIX exporter. + TEST_LIST in_memory_span_exporter_test) +endif()