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

Use CPM for dependency management #271

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Build folder
.build/
build/

# Locally installed dependencies
deps/
Expand Down
42 changes: 22 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.13)

project(dd-opentracing-cpp)
project(dd-opentracing-cpp CXX C)

set(SOVERSION 0)

Expand All @@ -25,37 +25,33 @@ endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
set(CMAKE_CXX_STANDARD 14)

# Includes
include_directories(SYSTEM 3rd_party/include deps/include)
include_directories(include)
set(CMAKE_CXX_STANDARD 14)

# Libraries
set(CMAKE_LIBRARY_PATH deps/lib)
include(Dependencies.cmake)
add_external_dependencies()

# Dependencies
find_path(OPENTRACING_INCLUDE_DIR NAMES opentracing/tracer.h)
find_library(OPENTRACING_LIB opentracing)
find_library(MSGPACK_LIB msgpack)
find_package(CURL)
find_package(Threads REQUIRED)

# Code Sanitizers
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rd_party/sanitizers-cmake" ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/sanitizers-cmake")
find_package(Sanitizers)

# Code
install(DIRECTORY include/datadog DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
file(GLOB DD_OPENTRACING_SOURCES "src/*.cpp")
message(STATUS "Compiler ID: ${CMAKE_CXX_COMPILER_ID}")

add_library(datadog_project_options INTERFACE)

if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
add_compile_options(-Wall -Wextra -Werror -pedantic -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast -std=c++14)
target_compile_options(datadog_project_options INTERFACE -Wall -Wextra -pedantic)
if(BUILD_COVERAGE)
add_compile_options(-g -O0 -fprofile-arcs -ftest-coverage)
target_compile_options(datadog_project_options INTERFACE -g -O0 -fprofile-arcs -ftest-coverage)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W3)
target_compile_options(datadog_project_options INTERFACE /W3)
else()
message(FATAL_ERROR "Unknown compiler ${CMAKE_CXX_COMPILER_ID}")
endif()
Expand All @@ -64,7 +60,9 @@ endif()
if(BUILD_COVERAGE)
set(COVERAGE_LIBRARIES gcov)
endif()
set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} Threads::Threads ${COVERAGE_LIBRARIES})
set(DATADOG_LINK_LIBRARIES
msgpack-cxx
libcurl Threads::Threads nlohmann_json::nlohmann_json CLI11::CLI11 ${COVERAGE_LIBRARIES} datadog_project_options opentelemetry_api)

## Shared lib
if(BUILD_SHARED)
Expand All @@ -73,8 +71,9 @@ if(BUILD_SHARED)
if(BUILD_COVERAGE)
target_link_options(dd_opentracing PRIVATE -fprofile-arcs -ftest-coverage)
endif()
target_link_libraries(dd_opentracing ${DATADOG_LINK_LIBRARIES})
target_link_libraries(dd_opentracing opentelemetry_opentracing_shim ${DATADOG_LINK_LIBRARIES})
set_target_properties(dd_opentracing PROPERTIES SOVERSION ${SOVERSION})
target_include_directories(dd_opentracing PUBLIC include)
target_compile_definitions(dd_opentracing PUBLIC DD_OPENTRACING_SHARED)
install(TARGETS dd_opentracing
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -85,8 +84,9 @@ endif()
if(BUILD_STATIC)
add_library(dd_opentracing-static STATIC ${DD_OPENTRACING_SOURCES})
add_sanitizers(dd_opentracing-static)
target_link_libraries(dd_opentracing-static ${DATADOG_LINK_LIBRARIES})
target_link_libraries(dd_opentracing-static opentelemetry_opentracing_shim_static ${DATADOG_LINK_LIBRARIES})
set_target_properties(dd_opentracing-static PROPERTIES OUTPUT_NAME dd_opentracing POSITION_INDEPENDENT_CODE ON)
target_include_directories(dd_opentracing-static PUBLIC include)
target_compile_definitions(dd_opentracing-static PUBLIC DD_OPENTRACING_STATIC)
install(TARGETS dd_opentracing-static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand All @@ -97,7 +97,8 @@ endif()
if(BUILD_OBJECT)
add_library(dd_opentracing-object OBJECT ${DD_OPENTRACING_SOURCES})
add_sanitizers(dd_opentracing-object)
target_link_libraries(dd_opentracing-object ${CURL_LIBRARIES} Threads::Threads)
target_link_libraries(dd_opentracing-object opentelemetry_opentracing_shim ${DATADOG_LINK_LIBRARIES} ${CURL_LIBRARIES} Threads::Threads)
target_include_directories(dd_opentracing-object PUBLIC include)
set_property(TARGET dd_opentracing-object PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(dd_opentracing-object PUBLIC DD_OPENTRACING_OBJECT)
endif()
Expand All @@ -114,10 +115,11 @@ if(BUILD_PLUGIN)
if(BUILD_COVERAGE)
target_link_options(dd_opentracing_plugin PRIVATE -fprofile-arcs -ftest-coverage)
endif()
target_link_libraries(dd_opentracing_plugin PUBLIC ${DATADOG_LINK_LIBRARIES}
target_link_libraries(dd_opentracing_plugin PUBLIC opentelemetry_opentracing_shim ${DATADOG_LINK_LIBRARIES}
-static-libstdc++
-static-libgcc
-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/export.map)
target_include_directories(dd_opentracing_plugin PUBLIC include)
install(TARGETS dd_opentracing_plugin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
Expand Down
38 changes: 38 additions & 0 deletions Dependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
include(cmake/CPM.cmake)
set(CPM_USE_LOCAL_PACKAGES ON)

function(add_external_dependencies)

CPMAddPackage("gh:catchorg/[email protected]")
CPMAddPackage("gh:CLIUtils/[email protected]")
CPMAddPackage(
NAME opentelemetry-cpp
GITHUB_REPOSITORY maztheman/opentelemetry-cpp
GIT_TAG main
OPTIONS
"WITH_STL OFF" "WITH_OPENTRACING ON" "BUILD_TESTING OFF" "BUILD_STATIC_LIBS ON" "WITH_EXAMPLES OFF"
)
CPMAddPackage(
NAME curl
GITHUB_REPOSITORY curl/curl
GIT_TAG curl-8_2_1
OPTIONS
"HTTP_ONLY ON" "CURL_ENABLE_SSL OFF" "BUILD_CURL_EXE OFF" "BUILD_SHARED_LIBS OFF" "CMAKE_POSITION_INDEPENDENT_CODE ON"

)
CPMAddPackage(
NAME msgpack-c
GITHUB_REPOSITORY msgpack/msgpack-c
GIT_TAG cpp-6.1.0
OPTIONS "MSGPACK_CXX14 ON" "MSGPACK_USE_BOOST OFF" "BUILD_SHARED_LIBS OFF"
)
CPMAddPackage(
NAME nlohmann_json
VERSION 3.11.2
GITHUB_REPOSITORY nlohmann/json
GITHUB_TAG v3.11.2
OPTIONS
"JSON_BuildTests OFF"
)

endfunction()
33 changes: 33 additions & 0 deletions cmake/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(CPM_DOWNLOAD_VERSION 0.38.2)

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
download_cpm()
else()
# resume download if it previously failed
file(READ ${CPM_DOWNLOAD_LOCATION} check)
if("${check}" STREQUAL "")
download_cpm()
endif()
unset(check)
endif()

include(${CPM_DOWNLOAD_LOCATION})
2 changes: 1 addition & 1 deletion scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if [ "$BUILD_MSGPACK" -eq "1" ]; then
tar zxf msgpack.tar.gz
mkdir -p "msgpack-${MSGPACK_VERSION}/.build"
cd "msgpack-${MSGPACK_VERSION}/.build"
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -DBUILD_SHARED_LIBS=OFF -DMSGPACK_CXX11=ON ..
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" -DBUILD_SHARED_LIBS=OFF -DMSGPACK_CXX14=ON ..
make --jobs="$MAKE_JOB_COUNT"
make install
cd ../..
Expand Down
5 changes: 2 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
add_library(catch STATIC test_main.cpp)

macro(_datadog_test TEST_NAME)
add_executable(${TEST_NAME} ${ARGN})
add_sanitizers(${TEST_NAME})
if(BUILD_COVERAGE)
target_link_options(${TEST_NAME} PRIVATE -fprofile-arcs -ftest-coverage)
endif()
target_link_libraries(${TEST_NAME} dd_opentracing
Catch2::Catch2WithMain
${DATADOG_LINK_LIBRARIES}
catch)
)
add_test(${TEST_NAME} ${TEST_NAME})
endmacro()

Expand Down
14 changes: 9 additions & 5 deletions test/agent_writer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "../src/agent_writer.h"

#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <datadog/version.h>

#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <ctime>

#include "mocks.h"
Expand Down Expand Up @@ -185,7 +187,7 @@ TEST_CASE("writer") {
}

SECTION("handle error responses") {
using Catch::Matchers::Contains;
using Catch::Matchers::ContainsSubstring;

// HTTP status zero indicates "no status."
handle->response_status = 0;
Expand All @@ -195,7 +197,8 @@ TEST_CASE("writer") {
writer.flush(std::chrono::seconds(10));
REQUIRE(logger->records.size() != 0);
// The logged error diagnostic will say that there was no response status.
REQUIRE_THAT(logger->records.back().message, Contains("response without an HTTP status"));
REQUIRE_THAT(logger->records.back().message,
ContainsSubstring("response without an HTTP status"));

// HTTP status 200 with an empty body means that the response really should
// be 429 "too many requests," but the Agent is not configured to return
Expand All @@ -207,7 +210,7 @@ TEST_CASE("writer") {
writer.flush(std::chrono::seconds(10));
REQUIRE(logger->records.size() != 0);
// The logged error diagnostic will mention the lack of response.
REQUIRE_THAT(logger->records.back().message, Contains("response without a body"));
REQUIRE_THAT(logger->records.back().message, ContainsSubstring("response without a body"));

// HTTP statuses other than 200 are unexpected.
std::vector<int> statuses;
Expand All @@ -225,7 +228,8 @@ TEST_CASE("writer") {
writer.flush(std::chrono::seconds(10));
REQUIRE(logger->records.size() != 0);
// The logged error diagnostic will contain the response status.
REQUIRE_THAT(logger->records.back().message, Contains(" " + std::to_string(status) + " "));
REQUIRE_THAT(logger->records.back().message,
ContainsSubstring(" " + std::to_string(status) + " "));
}

SECTION("queue does not grow indefinitely") {
Expand Down
4 changes: 3 additions & 1 deletion test/glob_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include "../src/glob.h"

#include <catch2/catch.hpp>
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <catch2/catch_all.hpp>

using namespace datadog::opentracing;

Expand Down
4 changes: 3 additions & 1 deletion test/limiter_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "../src/limiter.h"

#include <catch2/catch.hpp>
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <catch2/catch_all.hpp>

#include "mocks.h"
using namespace datadog::opentracing;
Expand Down
5 changes: 4 additions & 1 deletion test/logger_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "../src/logger.h"

#include <catch2/catch.hpp>
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <catch2/catch_all.hpp>

using namespace datadog::opentracing;

TEST_CASE("logger") {
Expand Down
4 changes: 3 additions & 1 deletion test/opentracing_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <datadog/opentracing.h>

#include <catch2/catch.hpp>
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <catch2/catch_all.hpp>

#include "mocks.h"
using namespace datadog::opentracing;
Expand Down
4 changes: 3 additions & 1 deletion test/propagation_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <datadog/tags.h>
#include <opentracing/ext/tags.h>
#include <opentracing/tracer.h>

#include <cassert>
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <nlohmann/json.hpp>
#include <string>

Expand Down
4 changes: 3 additions & 1 deletion test/sample_test.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "../src/sample.h"

#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <algorithm>
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <ctime>
#include <nlohmann/json.hpp>

Expand Down
4 changes: 3 additions & 1 deletion test/span_buffer_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "../src/span_buffer.h"

#include <catch2/catch.hpp>
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <catch2/catch_all.hpp>

#include "../src/sample.h"
#include "mocks.h"
Expand Down
4 changes: 3 additions & 1 deletion test/span_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "../src/span.h"

#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <datadog/tags.h>
#include <opentracing/ext/tags.h>

#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <ctime>
#include <nlohmann/json.hpp>
#include <ostream>
Expand Down
4 changes: 3 additions & 1 deletion test/tag_propagation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

#include "../src/tag_propagation.h"

#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <algorithm>
#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <stdexcept>
#include <string>
#include <unordered_map>
Expand Down
2 changes: 0 additions & 2 deletions test/test_main.cpp

This file was deleted.

4 changes: 3 additions & 1 deletion test/tracer_factory_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "../src/tracer_factory.h"

#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <datadog/tags.h>

#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <cstdio>
#include <fstream>
#include <stdexcept>
Expand Down
4 changes: 3 additions & 1 deletion test/tracer_options_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "../src/tracer_options.h"

#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include <opentracing/ext/tags.h>

#include <catch2/catch.hpp>
#include <catch2/catch_all.hpp>
#include <ostream>
using namespace datadog::opentracing;
using namespace std::string_literals;
Expand Down
Loading