Skip to content

Commit

Permalink
(#18816) dd-opentracing-cpp: migrate to Conan v2
Browse files Browse the repository at this point in the history
* dd-opentracing-cpp: migrate to Conan v2

* dd-opentracing-cpp: fix msgpack dependency

* dd-opentracing-cpp: bump deps

* dd-opentracing-cpp: transitive_libs=True

* dd-opentracing-cpp: drop the invalid target names

* dd-opentracing-cpp: add v1.3.7

* Remove clang-specific compiler flag

* Apply suggestions from code review

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* dd-opentracing-cpp: fix patch

* Minor refactors before merging

---------

Co-authored-by: Rubén Rincón Blanco <rubenrb@jfrog.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
  • Loading branch information
4 people authored May 20, 2024
1 parent bb8d59a commit 63c3ee8
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 117 deletions.
11 changes: 0 additions & 11 deletions recipes/dd-opentracing-cpp/all/CMakeLists.txt

This file was deleted.

12 changes: 8 additions & 4 deletions recipes/dd-opentracing-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
sources:
"1.3.7":
url: "https://github.com/DataDog/dd-opentracing-cpp/archive/refs/tags/v1.3.7.tar.gz"
sha256: "8d39c6b23f941a2d11571daaccc04e69539a3fcbcc50a631837560d5861a7b96"
"1.3.0":
url: https://github.com/DataDog/dd-opentracing-cpp/archive/refs/tags/v1.3.0.tar.gz
sha256: 16aad0c0daed054d4bcdf68cf069956e8d3b0c60a33c2162ad655a17b33b65e4
url: "https://github.com/DataDog/dd-opentracing-cpp/archive/refs/tags/v1.3.0.tar.gz"
sha256: "16aad0c0daed054d4bcdf68cf069956e8d3b0c60a33c2162ad655a17b33b65e4"
patches:
"1.3.7":
- patch_file: "patches/1.3.7/0001-Find-packages-setup.patch"
"1.3.0":
- base_path: "source_subfolder"
patch_file: "patches/0001-Find-packages-setup.patch"
- patch_file: "patches/1.3.0/0001-Find-packages-setup.patch"
116 changes: 51 additions & 65 deletions recipes/dd-opentracing-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"


class DatadogOpenTracingConan(ConanFile):
name = "dd-opentracing-cpp"
description = "Monitoring service for cloud-scale applications based on OpenTracing "
license = "Apache-2.0"
topics = ("instrumentration", "monitoring", "security", "tracing")
homepage = "https://github.com/DataDog/dd-opentracing-cpp"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/DataDog/dd-opentracing-cpp"
topics = ("instrumentation", "monitoring", "security", "tracing")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
Expand All @@ -22,99 +29,78 @@ class DatadogOpenTracingConan(ConanFile):
"fPIC": True,
}

generators = "cmake", "cmake_find_package"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _compilers_minimum_version(self):
return {
"gcc": "5",
"Visual Studio": "15",
"msvc": "191",
"clang": "3.4",
"apple-clang": "7",
}

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
self.requires("opentracing-cpp/1.6.0")
self.requires("zlib/1.2.11")
self.requires("libcurl/7.80.0")
self.requires("msgpack/3.3.0")
self.requires("nlohmann_json/3.10.5")
self.requires("opentracing-cpp/1.6.0", transitive_headers=True, transitive_libs=True)
self.requires("zlib/[>=1.2.11 <2]")
self.requires("libcurl/[>=7.78 <9]")
self.requires("msgpack-cxx/6.1.0")
self.requires("nlohmann_json/3.11.2")

@property
def _min_cppstd(self):
return 14

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 14)
check_min_cppstd(self, self._min_cppstd)

minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version:
if tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("Datadog-opentracing requires C++14, which your compiler does not support.")
else:
self.output.warn("Datadog-opentracing requires C++14. Your compiler is unknown. Assuming it supports C++14.")
if Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++ {self._min_cppstd}, which your compiler does not support."
)

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_PLUGIN"] = False
tc.variables["BUILD_SHARED"] = self.options.shared
tc.variables["BUILD_STATIC"] = not self.options.shared
tc.variables["BUILD_TESTING"] = False
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_PLUGIN"] = False
self._cmake.definitions["BUILD_SHARED"] = self.options.shared
self._cmake.definitions["BUILD_STATIC"] = not self.options.shared
self._cmake.definitions["BUILD_TESTING"] = False
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
# TODO: back to global scope in conan v2 once cmake_find_package_* generators removed
self.cpp_info.components["dd_opentracing"].libs = ["dd_opentracing"]
self.cpp_info.components["dd_opentracing"].defines.append(
"DD_OPENTRACING_SHARED" if self.options.shared else "DD_OPENTRACING_STATIC"
)
self.cpp_info.libs = ["dd_opentracing"]
self.cpp_info.defines.append("DD_OPENTRACING_SHARED" if self.options.shared else "DD_OPENTRACING_STATIC")
if self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.components["dd_opentracing"].system_libs.append("pthread")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed.
# Do not support these names in CMakeDeps, it was a mistake, upstream doesn't export targets
self.cpp_info.names["cmake_find_package"] = "DataDogOpenTracing"
self.cpp_info.names["cmake_find_package_multi"] = "DataDogOpenTracing"
target_suffix = "" if self.options.shared else "-static"
self.cpp_info.components["dd_opentracing"].names["cmake_find_package"] = "dd_opentracing" + target_suffix
self.cpp_info.components["dd_opentracing"].names["cmake_find_package_multi"] = "dd_opentracing" + target_suffix
self.cpp_info.components["dd_opentracing"].requires = [
"opentracing-cpp::opentracing-cpp", "zlib::zlib", "libcurl::libcurl",
"msgpack::msgpack", "nlohmann_json::nlohmann_json",
]
self.cpp_info.system_libs.append("pthread")
Original file line number Diff line number Diff line change
@@ -1,65 +1,54 @@
---
CMakeLists.txt | 30 ++++++++++--------------------
1 file changed, 10 insertions(+), 20 deletions(-)

--- CMakeLists.txt
+++ CMakeLists.txt
@@ -34,17 +34,12 @@ include_directories(include)
@@ -34,16 +34,11 @@
set(CMAKE_LIBRARY_PATH deps/lib)

# Dependencies
-find_path(OPENTRACING_INCLUDE_DIR NAMES opentracing/tracer.h)
-find_library(OPENTRACING_LIB opentracing)
+find_package(OpenTracing REQUIRED)
+find_package(OpenTracing REQUIRED CONFIG)
find_package(ZLIB REQUIRED)
-find_library(MSGPACK_LIB msgpack)
-find_package(CURL)
+find_package(msgpack REQUIRED)
+find_package(CURL REQUIRED)
+find_package(msgpack REQUIRED CONFIG)
+find_package(CURL REQUIRED CONFIG)
find_package(Threads REQUIRED)
-
-# Code Sanitizers
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rd_party/sanitizers-cmake" ${CMAKE_MODULE_PATH})
-find_package(Sanitizers)
-
# Code
install(DIRECTORY include/datadog DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
file(GLOB DD_OPENTRACING_SOURCES "src/*.cpp")
@@ -58,29 +53,24 @@ else()
@@ -58,16 +53,16 @@
endif()

# Outputs
-set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} ${ZLIB_LIBRARIES} Threads::Threads)
+set(DATADOG_LINK_LIBRARIES OpenTracing::OpenTracing CURL::CURL msgpack::msgpack ZLIB::ZLIB Threads::Threads)
+set(DATADOG_LINK_LIBRARIES OpenTracing::OpenTracing CURL::libcurl msgpack-cxx ZLIB::ZLIB Threads::Threads)

## Shared lib
if(BUILD_SHARED)
add_library(dd_opentracing SHARED ${DD_OPENTRACING_SOURCES})
- add_sanitizers(dd_opentracing)
target_link_libraries(dd_opentracing ${DATADOG_LINK_LIBRARIES})
set_target_properties(dd_opentracing PROPERTIES SOVERSION ${SOVERSION})
- target_compile_definitions(dd_opentracing PRIVATE DD_OPENTRACING_SHARED)
- install(TARGETS dd_opentracing
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+ target_compile_definitions(dd_opentracing PUBLIC DD_OPENTRACING_SHARED)
+ install(TARGETS dd_opentracing)
target_compile_definitions(dd_opentracing PRIVATE DD_OPENTRACING_SHARED)
install(TARGETS dd_opentracing
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
@@ -75,9 +70,9 @@
## Static lib
if(BUILD_STATIC)
add_library(dd_opentracing-static STATIC ${DD_OPENTRACING_SOURCES})
- add_sanitizers(dd_opentracing-static)
- set_target_properties(dd_opentracing-static PROPERTIES OUTPUT_NAME dd_opentracing POSITION_INDEPENDENT_CODE ON)
- target_compile_definitions(dd_opentracing PRIVATE DD_OPENTRACING_STATIC)
- install(TARGETS dd_opentracing-static
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+ target_link_libraries(dd_opentracing-static ${DATADOG_LINK_LIBRARIES})
+ set_target_properties(dd_opentracing-static PROPERTIES OUTPUT_NAME dd_opentracing)
+ target_compile_definitions(dd_opentracing-static PUBLIC DD_OPENTRACING_STATIC)
+ install(TARGETS dd_opentracing-static)
endif()

## Plugin

install(TARGETS dd_opentracing-static
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -35,15 +35,10 @@
set(CMAKE_LIBRARY_PATH deps/lib)

# 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(OpenTracing REQUIRED CONFIG)
+find_package(msgpack REQUIRED CONFIG)
+find_package(CURL REQUIRED CONFIG)
find_package(Threads REQUIRED)
-
-# Code Sanitizers
-set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rd_party/sanitizers-cmake" ${CMAKE_MODULE_PATH})
-find_package(Sanitizers)

# Code
install(DIRECTORY include/datadog DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
@@ -64,12 +59,12 @@
if(BUILD_COVERAGE)
set(COVERAGE_LIBRARIES gcov)
endif()
-set(DATADOG_LINK_LIBRARIES ${OPENTRACING_LIB} ${CURL_LIBRARIES} Threads::Threads ${COVERAGE_LIBRARIES})
+set(DATADOG_LINK_LIBRARIES OpenTracing::OpenTracing CURL::libcurl ${msgpack_LIBRARIES} ZLIB::ZLIB Threads::Threads)
+include_directories(${msgpack_INCLUDE_DIRS})

## Shared lib
if(BUILD_SHARED)
add_library(dd_opentracing SHARED ${DD_OPENTRACING_SOURCES})
- add_sanitizers(dd_opentracing)
if(BUILD_COVERAGE)
target_link_options(dd_opentracing PRIVATE -fprofile-arcs -ftest-coverage)
endif()
@@ -77,6 +72,7 @@
set_target_properties(dd_opentracing PROPERTIES SOVERSION ${SOVERSION})
target_compile_definitions(dd_opentracing PUBLIC DD_OPENTRACING_SHARED)
install(TARGETS dd_opentracing
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
@@ -84,13 +80,10 @@
## Static lib
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})
- set_target_properties(dd_opentracing-static PROPERTIES OUTPUT_NAME dd_opentracing POSITION_INDEPENDENT_CODE ON)
+ set_target_properties(dd_opentracing-static PROPERTIES OUTPUT_NAME dd_opentracing)
target_compile_definitions(dd_opentracing-static PUBLIC DD_OPENTRACING_STATIC)
- install(TARGETS dd_opentracing-static
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+ install(TARGETS dd_opentracing-static)
endif()

## Object lib
7 changes: 3 additions & 4 deletions recipes/dd-opentracing-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
find_package(dd-opentracing-cpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE dd-opentracing-cpp::dd-opentracing-cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14)
19 changes: 14 additions & 5 deletions recipes/dd-opentracing-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/dd-opentracing-cpp/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
Loading

0 comments on commit 63c3ee8

Please sign in to comment.