diff --git a/CMakeLists.txt b/CMakeLists.txt index d6c99c99..73211277 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,24 +48,26 @@ find_package(Boost ${hunter_config} REQUIRED ${boost_components}) list(APPEND package_deps Boost) hunter_add_package(thrift) -find_package(thrift ${hunter_config} REQUIRED) +find_package(thrift 0.9.2 ${hunter_config} REQUIRED) if(HUNTER_ENABLED) list(APPEND LIBS thrift::thrift_static) else() - list(APPEND LIBS ${THRIFT_LIBRARIES}) + list(APPEND LIBS ${thrift_LIBRARIES}) endif() list(APPEND package_deps thrift) +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() 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) +find_package(OpenTracing ${hunter_config} REQUIRED) +list(APPEND LIBS OpenTracing::opentracing) list(APPEND package_deps opentracing-cpp) hunter_add_package(nlohmann_json) -find_package(nlohmann_json CONFIG REQUIRED) -list(APPEND LIBS nlohmann_json) +find_package(nlohmann_json 2.1.0 ${hunter_config} REQUIRED) list(APPEND package_deps nlohmann_json) option(JAEGERTRACING_COVERAGE "Build with coverage" $ENV{COVERAGE}) @@ -78,7 +80,7 @@ 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) + find_package(yaml-cpp ${hunter_config} REQUIRED) if(HUNTER_ENABLED) list(APPEND LIBS yaml-cpp::yaml-cpp) else() @@ -243,6 +245,13 @@ target_link_libraries(jaegertracing-static ${LIBS}) set_target_properties(jaegertracing-static PROPERTIES OUTPUT_NAME jaegertracing) +SET(JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH 0) +if (nlohmann_json_INCLUDE_NAME STREQUAL "json.hpp") + SET(JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH 1) +endif() +set(JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH ${JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH} + CACHE BOOL "does nlohmann json lack the nlohmann/ path prefix") + configure_file( src/jaegertracing/Constants.h.in src/jaegertracing/Constants.h @@ -278,18 +287,33 @@ if(BUILD_TESTING) src/jaegertracing/utils/ErrorUtilTest.cpp src/jaegertracing/utils/RateLimiterTest.cpp src/jaegertracing/utils/UDPClientTest.cpp) + + list(APPEND TEST_LIBS testutils ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY} pthread) + + # Shared test 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}) + UnitTest ${LIBS} ${TEST_LIBS} jaegertracing) add_test(NAME UnitTest COMMAND UnitTest) + + # Also make sure static linkage works + add_executable(UnitTestStatic ${TEST_SRC}) + target_compile_definitions(UnitTestStatic PUBLIC + GTEST_HAS_TR1_TUPLE=0 + GTEST_USE_OWN_TR1_TUPLE=0) + target_link_libraries( + UnitTestStatic ${LIBS} ${TEST_LIBS} jaegertracing-static) + add_test(NAME UnitTestStatic COMMAND UnitTestStatic) + if(JAEGERTRACING_COVERAGE) setup_target_for_coverage(NAME UnitTestCoverage EXECUTABLE UnitTest DEPENDENCIES UnitTest) endif() + endif() # Installation (https://github.com/forexample/package-example) diff --git a/cmake/Findnlohmann_json.cmake b/cmake/Findnlohmann_json.cmake new file mode 100644 index 00000000..2e81dd1c --- /dev/null +++ b/cmake/Findnlohmann_json.cmake @@ -0,0 +1,58 @@ +# 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) diff --git a/cmake/Findthrift.cmake b/cmake/Findthrift.cmake index 1d272d51..b5fe86fd 100644 --- a/cmake/Findthrift.cmake +++ b/cmake/Findthrift.cmake @@ -1,93 +1,38 @@ -# 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_LIBRARY(thrift_LIBRARY thrift) +FIND_LIBRARY(thrift_LIBRARY_Z thriftz) +FIND_LIBRARY(thrift_LIBRARY_NB thriftnb) +FIND_LIBRARY(thrift_LIBRARY_C_GLIB thrift_c_glib) -find_program(THRIFT_COMPILER - NAMES - thrift - HINTS - ${THRIFT_HOME} - ENV THRIFT_HOME - /usr/local - /opt/local - PATH_SUFFIXES - bin bin64 -) +SET(thrift_LIBRARIES ${thrift_LIBRARY} CACHE STRING "main thrift library") -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}) +MARK_AS_ADVANCED(thrift_LIBRARY thrift_LIBRARY_Z thrift_LIBRARY_NB thrift_LIBRARY_C_GLIB) - # 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}") +FIND_PATH(thrift_INCLUDE_DIR "thrift/Thrift.h") - 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) diff --git a/cmake/Findyaml-cpp.cmake b/cmake/Findyaml-cpp.cmake new file mode 100644 index 00000000..75028614 --- /dev/null +++ b/cmake/Findyaml-cpp.cmake @@ -0,0 +1,25 @@ +# 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) diff --git a/src/jaegertracing/Constants.h.in b/src/jaegertracing/Constants.h.in index c5b90f55..15afa4bd 100644 --- a/src/jaegertracing/Constants.h.in +++ b/src/jaegertracing/Constants.h.in @@ -18,6 +18,7 @@ #define JAEGERTRACING_CONSTANTS_H #cmakedefine JAEGERTRACING_WITH_YAML_CPP +#cmakedefine JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH namespace jaegertracing { diff --git a/src/jaegertracing/baggage/RemoteRestrictionJSON.h b/src/jaegertracing/baggage/RemoteRestrictionJSON.h index ea62f00b..7f3d1ff1 100644 --- a/src/jaegertracing/baggage/RemoteRestrictionJSON.h +++ b/src/jaegertracing/baggage/RemoteRestrictionJSON.h @@ -18,10 +18,17 @@ #define JAEGERTRACING_BAGGAGE_REMOTERESTRICTIONJSON_H #include -#include #include #include +#include "jaegertracing/Constants.h" +/* nlohmann json changed locations (in 2.1.0?) */ +#ifdef JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH + #include +#else + #include +#endif + #include "jaegertracing/thrift-gen/BaggageRestrictionManager.h" #include "jaegertracing/thrift-gen/baggage_types.h" diff --git a/src/jaegertracing/testutils/CMakeLists.txt b/src/jaegertracing/testutils/CMakeLists.txt index 215630f6..257bd9c4 100644 --- a/src/jaegertracing/testutils/CMakeLists.txt +++ b/src/jaegertracing/testutils/CMakeLists.txt @@ -6,4 +6,9 @@ TUDPTransport.cpp) add_library(testutils ${SRC}) target_include_directories(testutils PUBLIC $) -target_link_libraries(testutils thrift::thrift_static) +if(HUNTER_ENABLED) + target_link_libraries(testutils thrift::thrift_static) +else() + target_link_libraries(testutils ${THRIFT_LIBRARIES}) +endif() +list(APPEND package_deps thrift)