Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup CMake makefiles for CURL usage #1916

Merged
merged 16 commits into from
Jan 17, 2023
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
59 changes: 51 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# 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
# versions of gtest
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()
Expand Down Expand Up @@ -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)
marcalff marked this conversation as resolved.
Show resolved Hide resolved

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"
Expand Down Expand Up @@ -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)

marcalff marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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`
Expand All @@ -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"
Expand All @@ -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`
Expand Down
8 changes: 7 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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()
marcalff marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 13 additions & 16 deletions examples/http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions examples/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 3 additions & 0 deletions examples/zipkin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion exporters/otlp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion exporters/zipkin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

include_directories(include)
find_package(CURL REQUIRED)
marcalff marked this conversation as resolved.
Show resolved Hide resolved
add_definitions(-DWITH_CURL)
add_library(
opentelemetry_exporter_zipkin_trace
Expand Down
7 changes: 6 additions & 1 deletion ext/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
marcalff marked this conversation as resolved.
Show resolved Hide resolved
52 changes: 26 additions & 26 deletions ext/src/http/client/curl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
7 changes: 5 additions & 2 deletions ext/test/http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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}
Expand Down
25 changes: 11 additions & 14 deletions ext/test/w3c_tracecontext_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()