diff --git a/CMakeLists.txt b/CMakeLists.txt index f103d986..754deb9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 3.3) +# See https://cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html +# See https://rix0r.nl/blog/2015/08/13/cmake-guide/ + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake" @@ -14,7 +17,16 @@ HunterGate( LOCAL ) -project(jaegertracing VERSION 0.3.0) +project(jaegertracing VERSION 0.3.0 LANGUAGES CXX) + +# Layout. This works for all platforms: +# * /lib/cmake/ +# * /lib/ +# * /include/ +set(config_install_dir "lib/cmake/${PROJECT_NAME}") +set(include_install_dir "include") + +set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -33,40 +45,22 @@ else() set(hunter_config "") endif() -set(package_deps) - -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND - CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9") - set(boost_components regex) - hunter_add_package(Boost COMPONENTS regex) - list(APPEND LIBS Boost::regex) -else() - set(boost_components) - hunter_add_package(Boost) -endif() -find_package(Boost ${hunter_config} REQUIRED ${boost_components}) -list(APPEND package_deps Boost) +hunter_add_package(Boost COMPONENTS regex) +find_package(Boost ${hunter_config} REQUIRED regex) hunter_add_package(thrift) -find_package(thrift ${hunter_config} REQUIRED) -if(HUNTER_ENABLED) - list(APPEND LIBS thrift::thrift_static) -else() - list(APPEND LIBS ${THRIFT_LIBRARIES}) +find_package(thrift 0.9.2 ${hunter_config} REQUIRED) +if(thrift_VERSION VERSION_GREATER "0.9.3") + message(WARNING "jaeger-cpp is only known to work with Thrift 0.9.2 and Thrift 0.9.3") endif() -list(APPEND package_deps thrift) hunter_add_package(opentracing-cpp) # Not `${hunter_config}` because OpenTracing provides its own # OpenTracingConfig.cmake file -find_package(OpenTracing CONFIG REQUIRED) -list(APPEND LIBS OpenTracing::opentracing-static) -list(APPEND package_deps opentracing-cpp) +find_package(OpenTracing ${hunter_config} REQUIRED) hunter_add_package(nlohmann_json) -find_package(nlohmann_json CONFIG REQUIRED) -list(APPEND LIBS nlohmann_json) -list(APPEND package_deps nlohmann_json) +find_package(nlohmann_json 2.1.0 ${hunter_config} REQUIRED) option(JAEGERTRACING_COVERAGE "Build with coverage" $ENV{COVERAGE}) option(JAEGERTRACING_BUILD_CROSSDOCK "Build crossdock" $ENV{CROSSDOCK}) @@ -76,233 +70,15 @@ cmake_dependent_option( if(JAEGERTRACING_WITH_YAML_CPP) hunter_add_package(yaml-cpp) - # Not `${hunter_config}` because yaml-cpp provides its own - # yaml-cpp-config.cmake file - find_package(yaml-cpp CONFIG REQUIRED) - if(HUNTER_ENABLED) - list(APPEND LIBS yaml-cpp::yaml-cpp) - else() - list(APPEND LIBS yaml-cpp) - endif() - list(APPEND package_deps yaml-cpp) + find_package(yaml-cpp ${hunter_config} REQUIRED) endif() -include(CTest) -if(BUILD_TESTING) - hunter_add_package(GTest) - find_package(GTest ${hunter_config} REQUIRED) - - if(JAEGERTRACING_COVERAGE) - include(CodeCoverage) - append_coverage_compiler_flags() - set(COVERAGE_EXCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/src/jaegertracing/thrift-gen/*" - "*Test.cpp") - endif() -endif() - -if(JAEGERTRACING_BUILD_CROSSDOCK) - set(CROSSDOCK_SRC crossdock/Server.cpp) - add_executable(crossdock ${CROSSDOCK_SRC}) - target_include_directories(crossdock PUBLIC - $) - target_link_libraries(crossdock PUBLIC jaegertracing-static) - - set(JAEGER_CROSSDOCK_URL -"https://raw.githubusercontent.com/jaegertracing/jaeger/master/docker-compose/\ -jaeger-docker-compose.yml") - file(DOWNLOAD ${JAEGER_CROSSDOCK_URL} - "${PROJECT_SOURCE_DIR}/crossdock/jaeger-docker-compose.yml") - find_program(DOCKER_COMPOSE_EXE docker-compose REQUIRED) - set(DOCKER_COMPOSE_CMD ${DOCKER_COMPOSE_EXE} - -f ${PROJECT_SOURCE_DIR}/crossdock/docker-compose.yml - -f ${PROJECT_SOURCE_DIR}/crossdock/jaeger-docker-compose.yml) - add_custom_target(crossdock-kill - COMMAND ${DOCKER_COMPOSE_CMD} kill - COMMAND ${DOCKER_COMPOSE_CMD} rm --force) - add_custom_target(crossdock-run - COMMAND ${DOCKER_COMPOSE_CMD} build - COMMAND ${DOCKER_COMPOSE_CMD} run crossdock - DEPENDS crossdock-kill) - add_custom_target(crossdock-fresh - COMMAND ${DOCKER_COMPOSE_CMD} pull - COMMAND ${DOCKER_COMPOSE_CMD} build - COMMAND ${DOCKER_COMPOSE_CMD} run crossdock - DEPENDS crossdock-kill) - add_custom_target(crossdock-logs - COMMAND ${DOCKER_COMPOSE_CMD} logs) -endif() - -set(SRC - src/jaegertracing/Config.cpp - src/jaegertracing/LogRecord.cpp - src/jaegertracing/Logging.cpp - src/jaegertracing/Reference.cpp - src/jaegertracing/Span.cpp - src/jaegertracing/SpanContext.cpp - src/jaegertracing/Tag.cpp - src/jaegertracing/TraceID.cpp - src/jaegertracing/Tracer.cpp - src/jaegertracing/Transport.cpp - src/jaegertracing/UDPTransport.cpp - src/jaegertracing/baggage/BaggageSetter.cpp - src/jaegertracing/baggage/RemoteRestrictionJSON.cpp - src/jaegertracing/baggage/RemoteRestrictionManager.cpp - src/jaegertracing/baggage/Restriction.cpp - src/jaegertracing/baggage/RestrictionManager.cpp - src/jaegertracing/baggage/RestrictionsConfig.cpp - src/jaegertracing/metrics/Counter.cpp - src/jaegertracing/metrics/Gauge.cpp - src/jaegertracing/metrics/InMemoryStatsReporter.cpp - src/jaegertracing/metrics/Metric.cpp - src/jaegertracing/metrics/Metrics.cpp - src/jaegertracing/metrics/NullCounter.cpp - src/jaegertracing/metrics/NullGauge.cpp - src/jaegertracing/metrics/NullStatsFactory.cpp - src/jaegertracing/metrics/NullStatsReporter.cpp - src/jaegertracing/metrics/NullTimer.cpp - src/jaegertracing/metrics/StatsFactory.cpp - src/jaegertracing/metrics/StatsFactoryImpl.cpp - src/jaegertracing/metrics/StatsReporter.cpp - src/jaegertracing/metrics/Timer.cpp - src/jaegertracing/net/IPAddress.cpp - src/jaegertracing/net/Socket.cpp - src/jaegertracing/net/URI.cpp - src/jaegertracing/net/http/Error.cpp - src/jaegertracing/net/http/Header.cpp - src/jaegertracing/net/http/Method.cpp - src/jaegertracing/net/http/Request.cpp - src/jaegertracing/net/http/Response.cpp - src/jaegertracing/platform/Endian.cpp - src/jaegertracing/platform/Hostname.cpp - src/jaegertracing/propagation/Extractor.cpp - src/jaegertracing/propagation/HeadersConfig.cpp - src/jaegertracing/propagation/Injector.cpp - src/jaegertracing/propagation/Propagator.cpp - src/jaegertracing/reporters/CompositeReporter.cpp - src/jaegertracing/reporters/Config.cpp - src/jaegertracing/reporters/InMemoryReporter.cpp - src/jaegertracing/reporters/LoggingReporter.cpp - src/jaegertracing/reporters/NullReporter.cpp - src/jaegertracing/reporters/RemoteReporter.cpp - src/jaegertracing/reporters/Reporter.cpp - src/jaegertracing/samplers/AdaptiveSampler.cpp - src/jaegertracing/samplers/Config.cpp - src/jaegertracing/samplers/ConstSampler.cpp - src/jaegertracing/samplers/GuaranteedThroughputProbabilisticSampler.cpp - src/jaegertracing/samplers/ProbabilisticSampler.cpp - src/jaegertracing/samplers/RateLimitingSampler.cpp - src/jaegertracing/samplers/RemoteSamplingJSON.cpp - src/jaegertracing/samplers/RemotelyControlledSampler.cpp - src/jaegertracing/samplers/Sampler.cpp - src/jaegertracing/samplers/SamplingStatus.cpp - src/jaegertracing/thrift-gen/Agent.cpp - src/jaegertracing/thrift-gen/AggregationValidator.cpp - src/jaegertracing/thrift-gen/BaggageRestrictionManager.cpp - src/jaegertracing/thrift-gen/Collector.cpp - src/jaegertracing/thrift-gen/Dependency.cpp - src/jaegertracing/thrift-gen/SamplingManager.cpp - src/jaegertracing/thrift-gen/TracedService.cpp - src/jaegertracing/thrift-gen/ZipkinCollector.cpp - src/jaegertracing/thrift-gen/agent_constants.cpp - src/jaegertracing/thrift-gen/agent_types.cpp - src/jaegertracing/thrift-gen/aggregation_validator_constants.cpp - src/jaegertracing/thrift-gen/aggregation_validator_types.cpp - src/jaegertracing/thrift-gen/baggage_constants.cpp - src/jaegertracing/thrift-gen/baggage_types.cpp - src/jaegertracing/thrift-gen/dependency_constants.cpp - src/jaegertracing/thrift-gen/dependency_types.cpp - src/jaegertracing/thrift-gen/jaeger_constants.cpp - src/jaegertracing/thrift-gen/jaeger_types.cpp - src/jaegertracing/thrift-gen/sampling_constants.cpp - src/jaegertracing/thrift-gen/sampling_types.cpp - src/jaegertracing/thrift-gen/tracetest_constants.cpp - src/jaegertracing/thrift-gen/tracetest_types.cpp - src/jaegertracing/thrift-gen/zipkincore_constants.cpp - src/jaegertracing/thrift-gen/zipkincore_types.cpp - src/jaegertracing/utils/ErrorUtil.cpp - src/jaegertracing/utils/HexParsing.cpp - src/jaegertracing/utils/RateLimiter.cpp - src/jaegertracing/utils/Regex.cpp - src/jaegertracing/utils/UDPClient.cpp - src/jaegertracing/utils/YAML.cpp) - -add_library(jaegertracing SHARED ${SRC}) -target_include_directories(jaegertracing PUBLIC - $ - $) -target_link_libraries(jaegertracing ${LIBS}) -set_target_properties(jaegertracing PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION ${PROJECT_VERSION_MAJOR}) - -add_library(jaegertracing-static STATIC ${SRC}) -target_include_directories(jaegertracing-static PUBLIC - $ - $) -target_link_libraries(jaegertracing-static ${LIBS}) -set_target_properties(jaegertracing-static PROPERTIES - OUTPUT_NAME jaegertracing) - -configure_file( - src/jaegertracing/Constants.h.in - src/jaegertracing/Constants.h - @ONLY) -set(CMAKE_INSTALL_CURRENT_DIR ON) - -if(BUILD_TESTING) - add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/jaegertracing/testutils") - set(TEST_SRC - src/jaegertracing/ConfigTest.cpp - src/jaegertracing/ReferenceTest.cpp - src/jaegertracing/SpanContextTest.cpp - src/jaegertracing/SpanTest.cpp - src/jaegertracing/TagTest.cpp - src/jaegertracing/TraceIDTest.cpp - src/jaegertracing/TracerTest.cpp - src/jaegertracing/UDPTransportTest.cpp - src/jaegertracing/baggage/BaggageTest.cpp - src/jaegertracing/metrics/MetricsTest.cpp - src/jaegertracing/metrics/NullStatsFactoryTest.cpp - src/jaegertracing/net/IPAddressTest.cpp - src/jaegertracing/net/SocketTest.cpp - src/jaegertracing/net/URITest.cpp - src/jaegertracing/net/http/HeaderTest.cpp - src/jaegertracing/net/http/MethodTest.cpp - src/jaegertracing/net/http/ResponseTest.cpp - src/jaegertracing/propagation/PropagatorTest.cpp - src/jaegertracing/reporters/ReporterTest.cpp - src/jaegertracing/samplers/SamplerTest.cpp - src/jaegertracing/testutils/MockAgentTest.cpp - src/jaegertracing/testutils/TracerUtil.cpp - src/jaegertracing/testutils/TUDPTransportTest.cpp - src/jaegertracing/utils/ErrorUtilTest.cpp - src/jaegertracing/utils/RateLimiterTest.cpp - src/jaegertracing/utils/UDPClientTest.cpp) - add_executable(UnitTest ${TEST_SRC}) - target_compile_definitions(UnitTest PUBLIC - GTEST_HAS_TR1_TUPLE=0 - GTEST_USE_OWN_TR1_TUPLE=0) - target_link_libraries( - UnitTest testutils GTest::main jaegertracing-static ${LIBS}) - add_test(NAME UnitTest COMMAND UnitTest) - if(JAEGERTRACING_COVERAGE) - setup_target_for_coverage(NAME UnitTestCoverage - EXECUTABLE UnitTest - DEPENDENCIES UnitTest) - endif() +if(JAEGERTRACING_COVERAGE) + include(CodeCoverage) endif() -# Installation (https://github.com/forexample/package-example) - -# Layout. This works for all platforms: -# * /lib/cmake/ -# * /lib/ -# * /include/ -set(config_install_dir "lib/cmake/${PROJECT_NAME}") -set(include_install_dir "include") - -set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") - +# Installation and CMake package +# # Configuration set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") @@ -329,33 +105,6 @@ configure_package_config_file( INSTALL_DESTINATION "${config_install_dir}" ) -# Targets: -# * /lib/libjaegertracing.a -# * /lib/libjaegertracing.so -# * header location after install: /include/jaegertracing/Tracer.h -# * headers can be included by C++ code `#include ` -install( - TARGETS jaegertracing jaegertracing-static - EXPORT "${TARGETS_EXPORT_NAME}" - LIBRARY DESTINATION "lib" - ARCHIVE DESTINATION "lib" - RUNTIME DESTINATION "bin" - INCLUDES DESTINATION "${include_install_dir}" -) - -# Headers: -# * src/jaegertracing/Tracer.h -> /include/jaegertracing/Tracer.h -install(DIRECTORY "src/jaegertracing" - DESTINATION "${include_install_dir}" - FILES_MATCHING - PATTERN "*.h" - PATTERN "testutils/*.h" EXCLUDE) - -# * build/src/jaegertracing/Constants.h -> -# /include/jaegertracing/Constants.h -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/src/jaegertracing/Constants.h" - DESTINATION "${include_install_dir}/jaegertracing") - # Config # * /lib/cmake/jaegertracing/jaegertracingConfig.cmake # * /lib/cmake/jaegertracing/jaegertracingConfigVersion.cmake @@ -371,3 +120,11 @@ install( NAMESPACE "${namespace}" DESTINATION "${config_install_dir}" ) + +if (BUILD_TESTING) + enable_testing() + add_custom_target(check COMMAND echo "run make test instead") +endif() + +add_subdirectory(src/jaegertracing) +add_subdirectory(crossdock) diff --git a/cmake/Findnlohmann_json.cmake b/cmake/Findnlohmann_json.cmake new file mode 100644 index 00000000..b65ef308 --- /dev/null +++ b/cmake/Findnlohmann_json.cmake @@ -0,0 +1,64 @@ +# Find jsoncpp +# +# Find the nlohmann json header +# +# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH +# +# This module defines +# +# nlohmann_json_INCLUDE_DIR, where to find header, etc. +# +# nlohmann_json_FOUND, If false, do not try to use jsoncpp. +# +# nlohmann_json_LIBRARIES, empty since no linkage is required, this +# is a header-only library. +# +# nlohmann_json_INCLUDE_NAME, the actual header name. You only have +# to use this if you want to support 2.0.x which installs +# a top-level json.hpp instead of nlohmann/json.hpp +# + +# only look in default directories +set(nlohmann_json_INCLUDE_NAME "nlohmann/json.hpp") +find_path( + nlohmann_json_INCLUDE_DIR + NAMES "${nlohmann_json_INCLUDE_NAME}" + DOC "nlohmann json include dir" +) + +if (NOT nlohmann_json_INCLUDE_DIR) + set(nlohmann_json_INCLUDE_NAME "json.hpp") + find_path( + nlohmann_json_INCLUDE_DIR + NAMES "${nlohmann_json_INCLUDE_NAME}" + ) +endif() + +set(nlohmann_json_INCLUDE_NAME ${nlohmann_json_INCLUDE_NAME} CACHE STRING "nlohmann header file name") + +set(nlohmann_json_LIBRARIES NOTFOUND CACHE STRING "no library is required by nlohmann_json") + +# Version detection. Unfortunately the header doesn't expose a proper version +# define. +if (nlohmann_json_INCLUDE_DIR AND nlohmann_json_INCLUDE_NAME) + file(READ "${nlohmann_json_INCLUDE_DIR}/${nlohmann_json_INCLUDE_NAME}" NL_HDR_TXT LIMIT 1000) + if (NL_HDR_TXT MATCHES "version ([0-9]+\.[0-9]+\.[0-9]+)") + set(nlohmann_json_VERSION "${CMAKE_MATCH_1}") + endif() +endif() + +set(nlohmann_json_VERSION "${nlohmann_json_VERSION}" CACHE STRING "nlohmann header version") + +# handle the QUIETLY and REQUIRED arguments and set nlohmann_json_FOUND to TRUE +# if all listed variables are TRUE, hide their existence from configuration view +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + nlohmann_json + REQUIRED_VARS nlohmann_json_INCLUDE_DIR nlohmann_json_INCLUDE_NAME + VERSION_VAR nlohmann_json_VERSION) + +add_library(nlohmann_json INTERFACE IMPORTED) + +set_target_properties(nlohmann_json PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${nlohmann_json_INCLUDE_DIR}" +) diff --git a/cmake/Findthrift.cmake b/cmake/Findthrift.cmake index 1d272d51..a47ac76b 100644 --- a/cmake/Findthrift.cmake +++ b/cmake/Findthrift.cmake @@ -1,93 +1,60 @@ -# https://github.com/snikulov/cmake-modules/blob/master/FindThrift.cmake - -# - Find Thrift (a cross platform RPC lib/tool) -# This module defines -# THRIFT_VERSION_STRING, version string of ant if found -# THRIFT_LIBRARIES, libraries to link -# THRIFT_INCLUDE_DIR, where to find THRIFT headers -# THRIFT_COMPILER, thrift compiler executable -# THRIFT_FOUND, If false, do not try to use ant -# Function -# thrift_gen_cpp( ) +# Find Thrift library and headers +# +# Sets: +# +# thrift_FOUND +# thrift_INCLUDE_DIR +# thrift_LIBRARIES +# thrift_VERSION +# +# Component libraries not currently detected separately. # -# Initial work was done by Cloudera https://github.com/cloudera/Impala -# 2014 - modified by snikulov +# Cut down from https://github.com/facebookarchive/fblualib -# prefer the thrift version supplied in THRIFT_HOME (cmake -DTHRIFT_HOME then environment) -find_path(THRIFT_INCLUDE_DIR - NAMES - thrift/Thrift.h - HINTS - ${THRIFT_HOME} - ENV THRIFT_HOME - /usr/local - /opt/local - PATH_SUFFIXES - include -) +CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR) -# prefer the thrift version supplied in THRIFT_HOME -find_library(THRIFT_LIBRARIES - NAMES - thrift libthrift - HINTS - ${THRIFT_HOME} - ENV THRIFT_HOME - /usr/local - /opt/local - PATH_SUFFIXES - lib lib64 -) +FIND_PATH(thrift_INCLUDE_DIR "thrift/Thrift.h") -find_program(THRIFT_COMPILER - NAMES - thrift - HINTS - ${THRIFT_HOME} - ENV THRIFT_HOME - /usr/local - /opt/local - PATH_SUFFIXES - bin bin64 -) +FIND_LIBRARY(thrift_LIBRARY thrift) +FIND_LIBRARY(thrift_LIBRARY_STATIC libthrift.a thrift.a) -if (THRIFT_COMPILER) - exec_program(${THRIFT_COMPILER} - ARGS -version OUTPUT_VARIABLE __thrift_OUT RETURN_VALUE THRIFT_RETURN) - string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+-[a-z]+$" THRIFT_VERSION_STRING ${__thrift_OUT}) +SET(thrift_LIBRARIES ${thrift_LIBRARY} CACHE STRING "main thrift library") - # define utility function to generate cpp files - function(thrift_gen_cpp thrift_file THRIFT_CPP_FILES_LIST THRIFT_GEN_INCLUDE_DIR) - set(_res) - set(_res_inc_path) - if(EXISTS ${thrift_file}) - get_filename_component(_target_dir ${thrift_file} NAME_WE) - message("thrif_gen_cpp: ${thrift_file}") +MARK_AS_ADVANCED(thrift_LIBRARY thrift_LIBRARY_STATIC) - if(NOT EXISTS ${CMAKE_BINARY_DIR}/${_target_dir}) - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/${_target_dir}) - endif() - exec_program(${THRIFT_COMPILER} - ARGS -o "${CMAKE_BINARY_DIR}/${_target_dir}" --gen cpp ${thrift_file} - OUTPUT_VARIABLE __thrift_OUT - RETURN_VALUE THRIFT_RETURN) - file(GLOB_RECURSE __result_src "${CMAKE_BINARY_DIR}/${_target_dir}/*.cpp") - file(GLOB_RECURSE __result_hdr "${CMAKE_BINARY_DIR}/${_target_dir}/*.h") - list(APPEND _res ${__result_src}) - list(APPEND _res ${__result_hdr}) - if(__result_hdr) - list(GET __result_hdr 0 _res_inc_path) - get_filename_component(_res_inc_path ${_res_inc_path} DIRECTORY) - endif() - else() - message("thrift_gen_cpp: file ${thrift_file} does not exists") - endif() - set(${THRIFT_CPP_FILES_LIST} "${_res}" PARENT_SCOPE) - set(${THRIFT_GEN_INCLUDE_DIR} "${_res_inc_path}" PARENT_SCOPE) - endfunction() -endif () +FILE(READ "${thrift_INCLUDE_DIR}/thrift/config.h" thrift_CONFIG_H) +IF (thrift_CONFIG_H MATCHES "#define VERSION \"([0-9]+\\.[0-9]+\\.[0-9]+)\"") + SET(thrift_VERSION "${CMAKE_MATCH_1}") +ENDIF() +SET(thrift_VERSION "${thrift_VERSION}" CACHE STRING "thrift library version") include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(THRIFT DEFAULT_MSG THRIFT_LIBRARIES THRIFT_INCLUDE_DIR THRIFT_COMPILER) -mark_as_advanced(THRIFT_LIBRARIES THRIFT_INCLUDE_DIR THRIFT_COMPILER THRIFT_VERSION_STRING) +find_package_handle_standard_args( + thrift + REQUIRED_VARS thrift_INCLUDE_DIR thrift_LIBRARIES + VERSION_VAR thrift_VERSION) + +# See https://cmake.org/cmake/help/v3.3/command/add_library.html +# and https://cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html + +IF (thrift_LIBRARY_STATIC AND thrift_INCLUDE_DIR) + ADD_LIBRARY(thrift::thrift_static STATIC IMPORTED) + SET_TARGET_PROPERTIES(thrift::thrift_static PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + INTERFACE_INCLUDE_DIRECTORIES "${thrift_INCLUDE_DIR}" + IMPORTED_LOCATION "${thrift_LIBRARY_STATIC}" + ) +ENDIF() + +# This won't work right on Windows if we find a .dll; we have to find the +# separate import library and set IMPORTED_IMPLIB to the .lib associated with +# the .DLL +IF (thrift_LIBRARY AND thrift_INCLUDE_DIR) + ADD_LIBRARY(thrift::thrift UNKNOWN IMPORTED) + SET_TARGET_PROPERTIES(thrift::thrift PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + INTERFACE_INCLUDE_DIRECTORIES "${thrift_INCLUDE_DIR}" + IMPORTED_LOCATION "${thrift_LIBRARY}" + ) +ENDIF() diff --git a/cmake/Findyaml-cpp.cmake b/cmake/Findyaml-cpp.cmake new file mode 100644 index 00000000..1a7bff19 --- /dev/null +++ b/cmake/Findyaml-cpp.cmake @@ -0,0 +1,40 @@ +# Find the yaml-cpp header and libraries +# +# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH +# +# This module defines +# yaml-cpp_INCLUDE_DIR, where to find header, etc. +# yaml-cpp_LIBRARIES, libraries to link to use yaml-cpp +# yaml-cpp_FOUND, If false, do not try to use yaml-cpp. +# + +# only look in default directories +find_path( + yaml-cpp_INCLUDE_DIR + NAMES yaml-cpp/yaml.h + DOC "yaml-cpp include dir" +) + +find_library(yaml-cpp_LIBRARIES + NAMES yaml-cpp + PATH_SUFFIXES lib lib64) + +# handle the QUIETLY and REQUIRED arguments and set yaml-cpp_FOUND to TRUE +# if all listed variables are TRUE, hide their existence from configuration view +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(yaml-cpp DEFAULT_MSG yaml-cpp_LIBRARIES yaml-cpp_INCLUDE_DIR) + +# See https://cmake.org/cmake/help/v3.3/manual/cmake-packages.7.html +# See https://rix0r.nl/blog/2015/08/13/cmake-guide/ + +IF (yaml-cpp_LIBRARIES AND yaml-cpp_INCLUDE_DIR) + # This won't work right on Windows if we find a .dll; we have to find the + # separate import library and set IMPORTED_IMPLIB to the .lib associated with + # the .DLL + ADD_LIBRARY(yaml-cpp::yaml-cpp UNKNOWN IMPORTED) + SET_TARGET_PROPERTIES(yaml-cpp::yaml-cpp PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + INTERFACE_INCLUDE_DIRECTORIES "${yaml-cpp_INCLUDE_DIR}" + IMPORTED_LOCATION "${yaml-cpp_LIBRARIES}" + ) +ENDIF() diff --git a/crossdock/CMakeLists.txt b/crossdock/CMakeLists.txt new file mode 100644 index 00000000..79465909 --- /dev/null +++ b/crossdock/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 3.3) + +project(jaegertracing_crossdock LANGUAGES CXX) + +if(JAEGERTRACING_BUILD_CROSSDOCK) + add_executable(crossdock Server.cpp) + target_include_directories(crossdock PUBLIC + $) + target_link_libraries(crossdock PUBLIC jaegertracing-static) + + set(JAEGER_CROSSDOCK_URL +"https://raw.githubusercontent.com/jaegertracing/jaeger/master/docker-compose/\ +jaeger-docker-compose.yml") + file(DOWNLOAD ${JAEGER_CROSSDOCK_URL} "${CMAKE_CURRENT_BINARY_DIR}/jaeger-docker-compose.yml") + find_program(DOCKER_COMPOSE_EXE docker-compose) + if (NOT DOCKER_COMPOSE_EXE) + message(WARNING "cannot build crossdock support requested by -DJAEGERTRACING_BUILD_CROSSDOCK: docker-compose not found") + else() + set(DOCKER_COMPOSE_CMD ${DOCKER_COMPOSE_EXE} + -f "${CMAKE_CURRENT_SOURCE_DIR}/docker-compose.yml" + -f "${CMAKE_CURRENT_BINARY_DIR}/jaeger-docker-compose.yml") + add_custom_target(crossdock-kill + COMMAND ${DOCKER_COMPOSE_CMD} kill + COMMAND ${DOCKER_COMPOSE_CMD} rm --force) + add_custom_target(crossdock-run + COMMAND ${DOCKER_COMPOSE_CMD} build + COMMAND ${DOCKER_COMPOSE_CMD} run crossdock + DEPENDS crossdock-kill) + add_custom_target(crossdock-fresh + COMMAND ${DOCKER_COMPOSE_CMD} pull + COMMAND ${DOCKER_COMPOSE_CMD} build + COMMAND ${DOCKER_COMPOSE_CMD} run crossdock + DEPENDS crossdock-kill) + add_custom_target(crossdock-logs + COMMAND ${DOCKER_COMPOSE_CMD} logs) + message(STATUS "crossdock enabled, use 'make crossdock-run'") + endif() +endif() diff --git a/scripts/build.sh b/scripts/build.sh index 1c850b97..9ec4acba 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -35,7 +35,9 @@ else fi info "Running tests..." -if ./UnitTest; then +if [ -e src/jaegertracing/UnitTest ] && src/jaegertracing/UnitTest; then + true +elif src/jaegertracing/UnitTestStatic; then true else error "Error: test failure" diff --git a/src/jaegertracing/CMakeLists-UnitTest.cmake b/src/jaegertracing/CMakeLists-UnitTest.cmake new file mode 100644 index 00000000..f95195f9 --- /dev/null +++ b/src/jaegertracing/CMakeLists-UnitTest.cmake @@ -0,0 +1,93 @@ +cmake_minimum_required(VERSION 3.3) + +project(UnitTest LANGUAGES CXX) + +include(CTest) +if(BUILD_TESTING) + hunter_add_package(GTest) + find_package(GTest ${hunter_config} REQUIRED) + + set(TEST_SRC + ConfigTest.cpp + ReferenceTest.cpp + SpanContextTest.cpp + SpanTest.cpp + TagTest.cpp + TraceIDTest.cpp + TracerTest.cpp + UDPTransportTest.cpp + baggage/BaggageTest.cpp + metrics/MetricsTest.cpp + metrics/NullStatsFactoryTest.cpp + net/IPAddressTest.cpp + net/SocketTest.cpp + net/URITest.cpp + net/http/HeaderTest.cpp + net/http/MethodTest.cpp + net/http/ResponseTest.cpp + propagation/PropagatorTest.cpp + reporters/ReporterTest.cpp + samplers/SamplerTest.cpp + testutils/MockAgent.cpp + testutils/TUDPTransport.cpp + testutils/SamplingManager.cpp + testutils/MockAgentTest.cpp + testutils/TracerUtil.cpp + testutils/TUDPTransportTest.cpp + utils/ErrorUtilTest.cpp + utils/RateLimiterTest.cpp + utils/UDPClientTest.cpp) + + if(HUNTER_ENABLED) + # Hunter uses a different target name for GTest than CMake's own packages do; + # note the target name's case. + list(APPEND TEST_LIBS GTest::main) + else() + list(APPEND TEST_LIBS GTest::Main) + endif() + + find_package(Threads REQUIRED) + list(APPEND TEST_LIBS Threads::Threads) + + # Shared test + add_executable(UnitTest ${TEST_SRC}) + target_link_libraries(UnitTest ${TEST_LIBS} jaegertracing) + + # Also make sure static linkage works + add_executable(UnitTestStatic ${TEST_SRC}) + target_link_libraries(UnitTestStatic ${TEST_LIBS} jaegertracing-static) + + foreach(tgt UnitTest UnitTestStatic) + target_compile_definitions(${tgt} PUBLIC + GTEST_HAS_TR1_TUPLE=0 + GTEST_USE_OWN_TR1_TUPLE=0) + target_include_directories(${tgt} PRIVATE + $ + $) + add_test(NAME ${tgt} COMMAND ${tgt}) + + if(THREADS_HAVE_PTHREAD_ARG) + target_compile_options(${tgt} PUBLIC "-pthread") + endif() + if(CMAKE_THREAD_LIBS_INIT) + target_link_libraries(${tgt} "${CMAKE_THREAD_LIBS_INIT}") + endif() + + endforeach(tgt) + + if(JAEGERTRACING_COVERAGE) + set(COVERAGE_EXCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/thrift-gen/*" "*Test.cpp") + + # Don't do coverage twice, just instrument one build + if (JAEGER_BUILD_STATIC) + setup_target_for_coverage(NAME UnitTestCoverage + EXECUTABLE UnitTestStatic + DEPENDENCIES UnitTestStatic) + else() + setup_target_for_coverage(NAME UnitTestCoverage + EXECUTABLE UnitTest + DEPENDENCIES UnitTest) + endif() + endif() + +endif(BUILD_TESTING) diff --git a/src/jaegertracing/CMakeLists.txt b/src/jaegertracing/CMakeLists.txt new file mode 100644 index 00000000..186b40d4 --- /dev/null +++ b/src/jaegertracing/CMakeLists.txt @@ -0,0 +1,194 @@ +# Build the jaegertracing library its self +cmake_minimum_required(VERSION 3.3) + +project(libjaegertracing VERSION ${jaegertracing_VERSION} LANGUAGES CXX) + +set(SRC + Config.cpp + LogRecord.cpp + Logging.cpp + Reference.cpp + Span.cpp + SpanContext.cpp + Tag.cpp + TraceID.cpp + Tracer.cpp + Transport.cpp + UDPTransport.cpp + baggage/BaggageSetter.cpp + baggage/RemoteRestrictionJSON.cpp + baggage/RemoteRestrictionManager.cpp + baggage/Restriction.cpp + baggage/RestrictionManager.cpp + baggage/RestrictionsConfig.cpp + metrics/Counter.cpp + metrics/Gauge.cpp + metrics/InMemoryStatsReporter.cpp + metrics/Metric.cpp + metrics/Metrics.cpp + metrics/NullCounter.cpp + metrics/NullGauge.cpp + metrics/NullStatsFactory.cpp + metrics/NullStatsReporter.cpp + metrics/NullTimer.cpp + metrics/StatsFactory.cpp + metrics/StatsFactoryImpl.cpp + metrics/StatsReporter.cpp + metrics/Timer.cpp + net/IPAddress.cpp + net/Socket.cpp + net/URI.cpp + net/http/Error.cpp + net/http/Header.cpp + net/http/Method.cpp + net/http/Request.cpp + net/http/Response.cpp + platform/Endian.cpp + platform/Hostname.cpp + propagation/Extractor.cpp + propagation/HeadersConfig.cpp + propagation/Injector.cpp + propagation/Propagator.cpp + reporters/CompositeReporter.cpp + reporters/Config.cpp + reporters/InMemoryReporter.cpp + reporters/LoggingReporter.cpp + reporters/NullReporter.cpp + reporters/RemoteReporter.cpp + reporters/Reporter.cpp + samplers/AdaptiveSampler.cpp + samplers/Config.cpp + samplers/ConstSampler.cpp + samplers/GuaranteedThroughputProbabilisticSampler.cpp + samplers/ProbabilisticSampler.cpp + samplers/RateLimitingSampler.cpp + samplers/RemoteSamplingJSON.cpp + samplers/RemotelyControlledSampler.cpp + samplers/Sampler.cpp + samplers/SamplingStatus.cpp + thrift-gen/Agent.cpp + thrift-gen/AggregationValidator.cpp + thrift-gen/BaggageRestrictionManager.cpp + thrift-gen/Collector.cpp + thrift-gen/Dependency.cpp + thrift-gen/SamplingManager.cpp + thrift-gen/TracedService.cpp + thrift-gen/ZipkinCollector.cpp + thrift-gen/agent_constants.cpp + thrift-gen/agent_types.cpp + thrift-gen/aggregation_validator_constants.cpp + thrift-gen/aggregation_validator_types.cpp + thrift-gen/baggage_constants.cpp + thrift-gen/baggage_types.cpp + thrift-gen/dependency_constants.cpp + thrift-gen/dependency_types.cpp + thrift-gen/jaeger_constants.cpp + thrift-gen/jaeger_types.cpp + thrift-gen/sampling_constants.cpp + thrift-gen/sampling_types.cpp + thrift-gen/tracetest_constants.cpp + thrift-gen/tracetest_types.cpp + thrift-gen/zipkincore_constants.cpp + thrift-gen/zipkincore_types.cpp + utils/ErrorUtil.cpp + utils/HexParsing.cpp + utils/RateLimiter.cpp + utils/Regex.cpp + utils/UDPClient.cpp + utils/YAML.cpp) + +add_library(jaegertracing SHARED ${SRC}) +add_library(jaegertracing-static STATIC ${SRC}) + +if (JAEGERTRACING_COVERAGE) + append_coverage_compiler_flags() +endif() + +foreach(tgt jaegertracing jaegertracing-static) + # This lets us use the "jaegertracing/" include prefix as if we were installed + target_include_directories(${tgt} PRIVATE + PRIVATE $ + PRIVATE $) + target_compile_features(${tgt} PUBLIC cxx_std_11) + set_target_properties(${tgt} PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION ${PROJECT_VERSION_MAJOR}) +endforeach() + +# Tell others where we'll install our headers for the cmake +# package output. +target_include_directories(jaegertracing-static INTERFACE + PUBLIC $) +target_include_directories(jaegertracing INTERFACE + PUBLIC $) + +# This works whether Boost::regex is header-only or requires +# a linked library for older GCC +target_link_libraries(jaegertracing PUBLIC Boost::regex) +target_link_libraries(jaegertracing-static PUBLIC Boost::regex) + +# Prefer shared Thrift for our own shared build, static Thrift +# for our own static build. +if (TARGET thrift::thrift) + target_link_libraries(jaegertracing PUBLIC thrift::thrift) +else() + target_link_libraries(jaegertracing PUBLIC thrift::thrift_static) +endif() +if (TARGET thrift::thrift_static) + target_link_libraries(jaegertracing-static PUBLIC thrift::thrift_static) +else() + target_link_libraries(jaegertracing-static PUBLIC thrift::thrift) +endif() + +target_link_libraries(jaegertracing PUBLIC OpenTracing::opentracing) +target_link_libraries(jaegertracing-static PUBLIC OpenTracing::opentracing-static) + +target_link_libraries(jaegertracing PUBLIC OpenTracing::opentracing) +target_link_libraries(jaegertracing-static PUBLIC OpenTracing::opentracing-static) + +# This "link" will just add the header path via the INTERFACE library +target_link_libraries(jaegertracing PUBLIC nlohmann_json) +target_link_libraries(jaegertracing-static PUBLIC nlohmann_json) + +if(JAEGERTRACING_WITH_YAML_CPP) + # yaml-cpp doesn't usually provide a static lib, so link the shared lib + target_link_libraries(jaegertracing PUBLIC yaml-cpp::yaml-cpp) + target_link_libraries(jaegertracing-static PUBLIC yaml-cpp::yaml-cpp) +endif() + +configure_file( + Constants.h.in + Constants.h + @ONLY) +set(CMAKE_INSTALL_CURRENT_DIR ON) + +include(CMakeLists-UnitTest.cmake) + +# Installation +# +# Targets: +# * /lib/libjaegertracing.a +# * /lib/libjaegertracing.so +# * header location after install: /include/jaegertracing/Tracer.h +# * headers can be included by C++ code `#include ` +install( + TARGETS jaegertracing jaegertracing-static + EXPORT "${TARGETS_EXPORT_NAME}" + LIBRARY DESTINATION "lib" + ARCHIVE DESTINATION "lib" + RUNTIME DESTINATION "bin" + INCLUDES DESTINATION "${include_install_dir}" +) + +# Headers: +# * Tracer.h -> /include/jaegertracing/Tracer.h +install(DIRECTORY "." + DESTINATION "${include_install_dir}" + FILES_MATCHING + PATTERN "*.h" + PATTERN "testutils/*.h" EXCLUDE) + +# * build/src/jaegertracing/Constants.h -> +# /include/jaegertracing/Constants.h +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Constants.h" + DESTINATION "${include_install_dir}/jaegertracing") diff --git a/src/jaegertracing/testutils/CMakeLists.txt b/src/jaegertracing/testutils/CMakeLists.txt deleted file mode 100644 index 215630f6..00000000 --- a/src/jaegertracing/testutils/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(SRC -MockAgent.cpp -SamplingManager.cpp -TUDPTransport.cpp) - -add_library(testutils ${SRC}) -target_include_directories(testutils PUBLIC - $) -target_link_libraries(testutils thrift::thrift_static)