From 4ebb978d98881832ae2e2c56793b6abb2291df90 Mon Sep 17 00:00:00 2001 From: Gustavo Lopes Date: Wed, 30 Nov 2022 12:51:01 +0000 Subject: [PATCH] Fix build on Mac OS/libc++; allow setting build type --- CMakeLists.txt | 16 ++++++++++++++-- src/datadog/clock.h | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13f2b15a..34d40994 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,9 @@ project(dd-trace-cpp) option(BUILD_COVERAGE "Build code with code coverage profiling instrumentation" OFF) option(BUILD_EXAMPLE "Build the example program (example/)" OFF) -set(CMAKE_BUILD_TYPE "RelWithDebInfo") +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 17) @@ -30,6 +32,13 @@ ExternalProject_Add(curl INSTALL_COMMAND make install ) +add_library(libcurl INTERFACE IMPORTED GLOBAL) +target_include_directories(libcurl INTERFACE ${CMAKE_BINARY_DIR}/include) + +execute_process(COMMAND ${CMAKE_BINARY_DIR}/bin/curl-config --static-libs + OUTPUT_VARIABLE CURL_LINK_OPTS OUTPUT_STRIP_TRAILING_WHITESPACE) +target_link_options(libcurl INTERFACE "SHELL:${CURL_LINK_OPTS}") + if (MSVC) add_compile_options(/W4 /WX) else() @@ -163,12 +172,15 @@ target_include_directories(dd_trace_cpp PRIVATE ${CMAKE_BINARY_DIR}/include) # Linking this library requires libcurl and threads. find_package(Threads REQUIRED) -target_link_libraries(dd_trace_cpp PRIVATE ${CMAKE_BINARY_DIR}/lib/libcurl.a PUBLIC Threads::Threads ${COVERAGE_LIBRARIES}) +target_link_libraries(dd_trace_cpp PRIVATE libcurl Threads::Threads ${COVERAGE_LIBRARIES}) # When installing, install the library and its public headers. install(TARGETS dd_trace_cpp + EXPORT dd_trace_cpp-config FILE_SET public_headers) +install(EXPORT dd_trace_cpp-config + DESTINATION share/cmake/dd_trace_cpp) if(BUILD_TESTING) add_subdirectory(test) diff --git a/src/datadog/clock.h b/src/datadog/clock.h index a2758a47..4385475c 100644 --- a/src/datadog/clock.h +++ b/src/datadog/clock.h @@ -26,6 +26,7 @@ namespace datadog { namespace tracing { using Duration = std::chrono::steady_clock::duration; +using SystemDuration = std::chrono::system_clock::duration; struct TimePoint { std::chrono::system_clock::time_point wall = @@ -39,11 +40,11 @@ inline Duration operator-(const TimePoint& after, const TimePoint& before) { } inline TimePoint operator-(const TimePoint& origin, Duration offset) { - return {origin.wall - offset, origin.tick - offset}; + return {origin.wall - std::chrono::duration_cast(offset), origin.tick - offset}; } inline TimePoint& operator+=(TimePoint& self, Duration offset) { - self.wall += offset; + self.wall += std::chrono::duration_cast(offset); self.tick += offset; return self; }