diff --git a/CHANGELOG.md b/CHANGELOG.md index ee58553c3d..f8365c3da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,34 @@ Increment the: to enable Bazel 6.0.0 compatibility [#1873](https://github.com/open-telemetry/opentelemetry-cpp/pull/1873) * [BUILD] Cleanup CMake makefiles for nlohmann_json [#1912](https://github.com/open-telemetry/opentelemetry-cpp/pull/1912) +* [BUILD] Cleanup CMake makefiles for CURL usage + [#1916](https://github.com/open-telemetry/opentelemetry-cpp/pull/1916) + +Important changes: + +* [BUILD] Cleanup CMake makefiles for CURL usage + [#1916](https://github.com/open-telemetry/opentelemetry-cpp/pull/1916) + * CMake option `WITH_OTLP_HTTP` + * Before this change, the CMake option `WITH_OTLP_HTTP` was unpredictable, + sometime set to ON and sometime set to OFF by default, + depending on whether a CURL package was found or not. + The option `WITH_OTLP_HTTP` was sometime not displayed in the ccmake + UI, making it impossible to even discover there is an option of that name. + * With this change, CMake option `WITH_OTLP_HTTP` is always OFF by + default. WITH_OTLP_HTTP MUST be set to ON explicitly to build the + OTLP HTTP exporter. The option is always visible in the ccmake UI. + * CMake option `BUILD_W3CTRACECONTEXT_TEST` + * Before this change, the W3C trace context tests were built, or + not, in an unpredictable way, depending on the presence, or not, of a + CURL package. In particular, the build could ignore the W3C trace + context tests even when BUILD_W3CTRACECONTEXT_TEST=ON. + * With this change, option BUILD_W3CTRACECONTEXT_TEST is honored. + * HTTP client/server examples + * Before this change, the HTTP client/server examples were built, or + not, in an unpredictable way, depending on the presence, or not, of a + CURL package. + * With this change, a new option `WITH_EXAMPLES_HTTP` is used to + build the HTTP client/server examples. ## [1.8.1] 2022-12-04 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d4fbed68a..6429162d05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + cmake_minimum_required(VERSION 3.1) # See https://cmake.org/cmake/help/v3.3/policy/CMP0057.html required by certain @@ -5,7 +8,7 @@ cmake_minimum_required(VERSION 3.1) cmake_policy(SET CMP0057 NEW) # See https://cmake.org/cmake/help/v3.12/policy/CMP0074.html required by certain -# version of zlib which is dependeded by cURL. +# version of zlib which CURL depends on. if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.12") cmake_policy(SET CMP0074 NEW) endif() @@ -148,6 +151,10 @@ if(WITH_STL) endif() option(WITH_OTLP "Whether to include the OpenTelemetry Protocol in the SDK" OFF) + +option(WITH_OTLP_HTTP "Whether to include the OTLP http exporter in the SDK" + OFF) + option(WITH_ZIPKIN "Whether to include the Zipkin exporter in the SDK" OFF) option(WITH_PROMETHEUS "Whether to include the Prometheus Client in the SDK" @@ -195,12 +202,26 @@ option( OFF) option(WITH_EXAMPLES "Whether to build examples" ON) +# This requires CURL, OFF by default. +option( + WITH_EXAMPLES_HTTP + "Whether to build http client/server examples. Requires WITH_EXAMPLES and CURL" + OFF) + option(WITH_LOGS_PREVIEW "Whether to build logs preview" OFF) option(WITH_ASYNC_EXPORT_PREVIEW "Whether enable async export" OFF) # Exemplar specs status is experimental, so behind feature flag by default option(WITH_METRICS_EXEMPLAR_PREVIEW "Whethere to enable exemplar within metrics" OFF) +# +# Verify options dependencies +# + +if(WITH_EXAMPLES_HTTP AND NOT WITH_EXAMPLES) + message(FATAL_ERROR "WITH_EXAMPLES_HTTP=ON requires WITH_EXAMPLES=ON") +endif() + find_package(Threads) function(install_windows_deps) @@ -314,22 +335,44 @@ if(WITH_OTLP) endif() endif() include(CMakeDependentOption) - if(WITH_OTLP_HTTP OR (NOT DEFINED WITH_OTLP_HTTP AND NOT DEFINED - CACHE{WITH_OTLP_HTTP})) - find_package(CURL) - endif() cmake_dependent_option( WITH_OTLP_GRPC "Whether to include the OTLP gRPC exporter in the SDK" ON "gRPC_FOUND" OFF) - cmake_dependent_option( - WITH_OTLP_HTTP "Whether to include the OTLP http exporter in the SDK" ON - "CURL_FOUND" OFF) message(STATUS "PROTOBUF_PROTOC_EXECUTABLE=${PROTOBUF_PROTOC_EXECUTABLE}") include(cmake/opentelemetry-proto.cmake) endif() +# +# Do we need HTTP CLIENT CURL ? +# + +if(WITH_OTLP_HTTP + OR WITH_ELASTICSEARCH + OR WITH_JAEGER + OR WITH_ZIPKIN + OR BUILD_W3CTRACECONTEXT_TEST + OR WITH_EXAMPLES_HTTP) + set(WITH_HTTP_CLIENT_CURL ON) +else() + set(WITH_HTTP_CLIENT_CURL OFF) +endif() + +# +# Do we need CURL ? +# + +if((NOT WITH_API_ONLY) AND WITH_HTTP_CLIENT_CURL) + # No specific version required. + find_package(CURL REQUIRED) + message(STATUS "Found CURL: ${CURL_LIBRARIES}, version ${CURL_VERSION}") +endif() + +# +# Do we need NLOHMANN_JSON ? +# + if(WITH_ELASTICSEARCH OR WITH_ZIPKIN OR WITH_OTLP_HTTP diff --git a/ci/do_ci.sh b/ci/do_ci.sh index 6c80c0efe6..873c53b587 100755 --- a/ci/do_ci.sh +++ b/ci/do_ci.sh @@ -95,6 +95,8 @@ elif [[ "$1" == "cmake.maintainer.test" ]]; then rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_PROMETHEUS=ON \ + -DWITH_EXAMPLES=ON \ + -DWITH_EXAMPLES_HTTP=ON \ -DWITH_ZIPKIN=ON \ -DWITH_JAEGER=ON \ -DBUILD_W3CTRACECONTEXT_TEST=ON \ @@ -180,6 +182,7 @@ elif [[ "$1" == "cmake.legacy.exporter.otprotocol.test" ]]; then cmake -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_CXX_STANDARD=11 \ -DWITH_OTLP=ON \ + -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ "${SRC_DIR}" grpc_cpp_plugin=`which grpc_cpp_plugin` @@ -193,6 +196,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.test" ]]; then rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_OTLP=ON \ + -DWITH_OTLP_HTTP=ON \ "${SRC_DIR}" grpc_cpp_plugin=`which grpc_cpp_plugin` proto_make_file="CMakeFiles/opentelemetry_proto.dir/build.make" @@ -205,6 +209,7 @@ elif [[ "$1" == "cmake.exporter.otprotocol.with_async_export.test" ]]; then rm -rf * cmake -DCMAKE_BUILD_TYPE=Debug \ -DWITH_OTLP=ON \ + -DWITH_OTLP_HTTP=ON \ -DWITH_ASYNC_EXPORT_PREVIEW=ON \ "${SRC_DIR}" grpc_cpp_plugin=`which grpc_cpp_plugin` diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 1f891f412d..f1a4ec20e5 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + add_subdirectory(common) include_directories(common) if(WITH_OTLP_GRPC OR WITH_OTLP_HTTP) @@ -24,4 +27,7 @@ add_subdirectory(batch) add_subdirectory(metrics_simple) add_subdirectory(multithreaded) add_subdirectory(multi_processor) -add_subdirectory(http) + +if(WITH_EXAMPLES_HTTP) + add_subdirectory(http) +endif() diff --git a/examples/http/CMakeLists.txt b/examples/http/CMakeLists.txt index a1181c93a4..3aeb2624a1 100644 --- a/examples/http/CMakeLists.txt +++ b/examples/http/CMakeLists.txt @@ -1,20 +1,17 @@ -find_package(CURL) +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 -if(NOT CURL_FOUND) - message(WARNING "Skipping http client/server example build: CURL not found") -else() - include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include - ${CMAKE_SOURCE_DIR}/ext/include ${CMAKE_SOURCE_DIR/}) +include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include + ${CMAKE_SOURCE_DIR}/ext/include ${CMAKE_SOURCE_DIR/}) - add_executable(http_client client.cc) - add_executable(http_server server.cc) +add_executable(http_client client.cc) +add_executable(http_server server.cc) - target_link_libraries( - http_client ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace - opentelemetry_http_client_curl opentelemetry_exporter_ostream_span - ${CURL_LIBRARIES}) +target_link_libraries( + http_client ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace + opentelemetry_http_client_curl opentelemetry_exporter_ostream_span + ${CURL_LIBRARIES}) - target_link_libraries( - http_server ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace - opentelemetry_http_client_curl opentelemetry_exporter_ostream_span) -endif() +target_link_libraries( + http_server ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace + opentelemetry_http_client_curl opentelemetry_exporter_ostream_span) diff --git a/examples/otlp/CMakeLists.txt b/examples/otlp/CMakeLists.txt index 30ce3cab48..bcf387a108 100644 --- a/examples/otlp/CMakeLists.txt +++ b/examples/otlp/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + include_directories( ${CMAKE_BINARY_DIR}/generated/third_party/opentelemetry-proto ${CMAKE_SOURCE_DIR}/exporters/otlp/include) diff --git a/examples/zipkin/CMakeLists.txt b/examples/zipkin/CMakeLists.txt index f55f363d72..e3e3a5f55f 100644 --- a/examples/zipkin/CMakeLists.txt +++ b/examples/zipkin/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + include_directories(${CMAKE_SOURCE_DIR}/exporters/zipkin/include) add_executable(example_zipkin main.cc) diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index 7cecab0eca..49db6058ae 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + add_library( opentelemetry_otlp_recordable src/otlp_log_recordable.cc src/otlp_recordable.cc @@ -94,7 +97,6 @@ if(WITH_OTLP_GRPC) endif() if(WITH_OTLP_HTTP) - find_package(CURL REQUIRED) add_library(opentelemetry_exporter_otlp_http_client src/otlp_http_client.cc) set_target_properties(opentelemetry_exporter_otlp_http_client PROPERTIES EXPORT_NAME otlp_http_client) diff --git a/exporters/zipkin/CMakeLists.txt b/exporters/zipkin/CMakeLists.txt index 0139a783e2..ce093f3e55 100644 --- a/exporters/zipkin/CMakeLists.txt +++ b/exporters/zipkin/CMakeLists.txt @@ -13,7 +13,6 @@ # limitations under the License. include_directories(include) -find_package(CURL REQUIRED) add_definitions(-DWITH_CURL) add_library( opentelemetry_exporter_zipkin_trace diff --git a/ext/src/CMakeLists.txt b/ext/src/CMakeLists.txt index 6d7a14be41..84f30dd906 100644 --- a/ext/src/CMakeLists.txt +++ b/ext/src/CMakeLists.txt @@ -1,5 +1,10 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + if(WITH_ZPAGES) add_subdirectory(zpages) endif() -add_subdirectory(http/client/curl) +if(WITH_HTTP_CLIENT_CURL) + add_subdirectory(http/client/curl) +endif() diff --git a/ext/src/http/client/curl/CMakeLists.txt b/ext/src/http/client/curl/CMakeLists.txt index 836cd019b4..38fdad4030 100644 --- a/ext/src/http/client/curl/CMakeLists.txt +++ b/ext/src/http/client/curl/CMakeLists.txt @@ -1,30 +1,30 @@ -find_package(CURL) -if(CURL_FOUND) - add_library( - opentelemetry_http_client_curl http_client_factory_curl.cc - http_client_curl.cc http_operation_curl.cc) +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 - set_target_properties(opentelemetry_http_client_curl - PROPERTIES EXPORT_NAME http_client_curl) +add_library( + opentelemetry_http_client_curl http_client_factory_curl.cc + http_client_curl.cc http_operation_curl.cc) - if(TARGET CURL::libcurl) - target_link_libraries( - opentelemetry_http_client_curl - PUBLIC opentelemetry_ext - PRIVATE CURL::libcurl) - else() - target_include_directories(opentelemetry_http_client_curl - INTERFACE "${CURL_INCLUDE_DIRS}") - target_link_libraries( - opentelemetry_http_client_curl - PUBLIC opentelemetry_ext - PRIVATE ${CURL_LIBRARIES}) - endif() +set_target_properties(opentelemetry_http_client_curl + PROPERTIES EXPORT_NAME http_client_curl) - install( - TARGETS opentelemetry_http_client_curl - EXPORT "${PROJECT_NAME}-target" - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) +if(TARGET CURL::libcurl) + target_link_libraries( + opentelemetry_http_client_curl + PUBLIC opentelemetry_ext + PRIVATE CURL::libcurl) +else() + target_include_directories(opentelemetry_http_client_curl + INTERFACE "${CURL_INCLUDE_DIRS}") + target_link_libraries( + opentelemetry_http_client_curl + PUBLIC opentelemetry_ext + PRIVATE ${CURL_LIBRARIES}) endif() + +install( + TARGETS opentelemetry_http_client_curl + EXPORT "${PROJECT_NAME}-target" + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/ext/test/http/CMakeLists.txt b/ext/test/http/CMakeLists.txt index 341648085d..268c91cbf2 100644 --- a/ext/test/http/CMakeLists.txt +++ b/ext/test/http/CMakeLists.txt @@ -1,5 +1,7 @@ -find_package(CURL) -if(CURL_FOUND) +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +if(WITH_HTTP_CLIENT_CURL) set(FILENAME curl_http_test) add_compile_definitions(WITH_CURL) add_executable(${FILENAME} ${FILENAME}.cc) @@ -19,6 +21,7 @@ if(CURL_FOUND) TEST_PREFIX ext.http.curl. TEST_LIST ${FILENAME}) endif() + set(URL_PARSER_FILENAME url_parser_test) add_executable(${URL_PARSER_FILENAME} ${URL_PARSER_FILENAME}.cc) target_link_libraries(${URL_PARSER_FILENAME} ${GTEST_BOTH_LIBRARIES} diff --git a/ext/test/w3c_tracecontext_test/CMakeLists.txt b/ext/test/w3c_tracecontext_test/CMakeLists.txt index ea74a8eeb0..cc2ae43b1c 100644 --- a/ext/test/w3c_tracecontext_test/CMakeLists.txt +++ b/ext/test/w3c_tracecontext_test/CMakeLists.txt @@ -1,17 +1,14 @@ -include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include) +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 -find_package(CURL) -if(NOT CURL_FOUND) - message(WARNING "Skipping example_w3c_tracecontext_test: CURL not found") -else() - add_executable(w3c_tracecontext_test main.cc) - target_link_libraries( - w3c_tracecontext_test - PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace - opentelemetry_http_client_curl opentelemetry_exporter_ostream_span - ${CURL_LIBRARIES} nlohmann_json::nlohmann_json) - if(nlohmann_json_clone) - add_dependencies(w3c_tracecontext_test nlohmann_json::nlohmann_json) - endif() +include_directories(${CMAKE_SOURCE_DIR}/exporters/ostream/include) +add_executable(w3c_tracecontext_test main.cc) +target_link_libraries( + w3c_tracecontext_test + PRIVATE ${CMAKE_THREAD_LIBS_INIT} opentelemetry_trace + opentelemetry_http_client_curl opentelemetry_exporter_ostream_span + ${CURL_LIBRARIES} nlohmann_json::nlohmann_json) +if(nlohmann_json_clone) + add_dependencies(w3c_tracecontext_test nlohmann_json::nlohmann_json) endif()