Skip to content

Commit

Permalink
Support building with local dependencies (no Hunter)
Browse files Browse the repository at this point in the history
jaeger-cpp defaults to using Hunter to download its dependencies off the 'net,
even if they exist locally. This is convenient for development but not
practical for some production environments. It also makes life hard for clients
that want to link to jaeger-cpp since Hunter doesn't install those
dependencies. It's necessary to also use Hunter in apps that use a jaeger-cpp
built this way... and that's not always practical.

Accordingly, add support for finding jaeger-cpp's dependencies via the normal
CMake package discovery mechanism.

A sligtly unsightly hack is required for nlohmann json, because its header
moved from json.hpp to nlohmann/json.hpp in 2.1.0.

This introduces support for building with

   cmake -DHUNTER_ENABLED=0

WIP:

  - nothing packages nlohmann json 2.1.0 yet, 2.0.2 is widespread.
    but jaegertracing's code doesn't appear to support 2.0.2. For now you
    should work around it by installing 2.1.x locally from source.
    (jaegertracing#47)

  - will fail to compile tests if the local thrift is 0.9.1 since there are
    committed generated files from 0.9.2 (jaegertracing#45) and there's no mechanism
    to regenerate them.

This seeks to address the beginnings of jaegertracing#38.

Signed-off-by: Craig Ringer <craig@2ndquadrant.com>
  • Loading branch information
ringerc committed Jan 28, 2018
1 parent 99d5602 commit 9c58195
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 7 deletions.
17 changes: 12 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ 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)
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)
find_package(nlohmann_json ${hunter_config} REQUIRED)
list(APPEND LIBS nlohmann_json)
list(APPEND package_deps nlohmann_json)

Expand All @@ -78,7 +78,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()
Expand Down Expand Up @@ -243,6 +243,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
Expand Down Expand Up @@ -283,7 +290,7 @@ if(BUILD_TESTING)
GTEST_HAS_TR1_TUPLE=0
GTEST_USE_OWN_TR1_TUPLE=0)
target_link_libraries(
UnitTest testutils GTest::main jaegertracing-static ${LIBS})
UnitTest testutils ${GTEST_MAIN_LIBRARY} jaegertracing-static ${LIBS})
add_test(NAME UnitTest COMMAND UnitTest)
if(JAEGERTRACING_COVERAGE)
setup_target_for_coverage(NAME UnitTestCoverage
Expand Down
21 changes: 21 additions & 0 deletions cmake/FindThrift.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Find Thrift library and headers
#
# Sets:
#
# THRIFT_FOUND
# THRIFT_INCLUDE_DIR
# THRIFT_LIBRARIES
#
# Cut down from https://github.com/facebookarchive/fblualib

CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0 FATAL_ERROR)

FIND_LIBRARY(THRIFT_LIBRARIES thrift)
FIND_PATH(THRIFT_INCLUDE_DIR "thrift/Thrift.h")

FIND_PACKAGE_HANDLE_STANDARD_ARGS(
Thrift
REQUIRED_ARGS
THRIFT_INCLUDE_DIR
THRIFT_LIBRARY
THRIFT_CPP2_LIBRARY)
39 changes: 39 additions & 0 deletions cmake/Findnlohmann_json.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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_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")

# 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 DEFAULT_MSG nlohmann_json_INCLUDE_DIR nlohmann_json_INCLUDE_NAME)
25 changes: 25 additions & 0 deletions cmake/Findyaml-cpp.cmake
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions src/jaegertracing/Constants.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define JAEGERTRACING_CONSTANTS_H

#cmakedefine JAEGERTRACING_WITH_YAML_CPP
#cmakedefine JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH

namespace jaegertracing {

Expand Down
9 changes: 8 additions & 1 deletion src/jaegertracing/baggage/RemoteRestrictionJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@
#define JAEGERTRACING_BAGGAGE_REMOTERESTRICTIONJSON_H

#include <cstdint>
#include <nlohmann/json.hpp>
#include <string>
#include <vector>

#include "jaegertracing/Constants.h"
/* nlohmann json changed locations (in 2.1.0?) */
#ifdef JAEGERTRACING_NLOHMANN_UNQUALIFIED_PATH
#include <json.hpp>
#else
#include <nlohmann/json.hpp>
#endif

#include "jaegertracing/thrift-gen/BaggageRestrictionManager.h"
#include "jaegertracing/thrift-gen/baggage_types.h"

Expand Down
7 changes: 6 additions & 1 deletion src/jaegertracing/testutils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ TUDPTransport.cpp)
add_library(testutils ${SRC})
target_include_directories(testutils PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>)
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)

0 comments on commit 9c58195

Please sign in to comment.