-
Notifications
You must be signed in to change notification settings - Fork 50
/
CMakeLists.txt
359 lines (309 loc) · 14.3 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
cmake_minimum_required(VERSION 3.1)
# ==============================================================================
# Set policies
# Allows us to control options via normal variables
# this is used for the windows build
# See https://cmake.org/cmake/help/git-stage/policy/CMP0077.html
if(NOT (${CMAKE_VERSION} VERSION_LESS "3.13.0"))
cmake_policy(SET CMP0077 NEW)
endif()
# Allows us to specify the MSVC runtime via cmake variables
# See https://cmake.org/cmake/help/git-stage/policy/CMP0091.html
if(NOT (${CMAKE_VERSION} VERSION_LESS "3.15.0"))
cmake_policy(SET CMP0091 NEW)
endif()
project(lightstep-tracer)
# ==============================================================================
# Version information
set(LIGHTSTEP_VERSION_MAJOR "0")
set(LIGHTSTEP_VERSION_MINOR "14")
set(LIGHTSTEP_VERSION_PATCH "0")
set(LIGHTSTEP_VERSION_STRING
"${LIGHTSTEP_VERSION_MAJOR}.${LIGHTSTEP_VERSION_MINOR}.${LIGHTSTEP_VERSION_PATCH}")
# ==============================================================================
# Set up cpack
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
"A LightStep implementation of the C++ OpenTracing API")
set(CPACK_PACKAGE_VENDOR "lightstep.com")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_VERSION_MAJOR ${LIGHTSTEP_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${LIGHTSTEP_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${LIGHTSTEP_VERSION_PATCH})
include(CPack)
# ==============================================================================
# Set up options
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
# * CMAKE_INSTALL_INCLUDEDIR
include(GNUInstallDirs)
option(WITH_GRPC "Build with support for gRPC." ON)
option(WITH_LIBEVENT "Build with support for libevent." OFF)
option(WITH_CARES "Build with support for dns resolution using c-ares." OFF)
option(WITH_DYNAMIC_LOAD "Build support for dynamic loading." ON)
option(HEADERS_ONLY "Only generate version.h." OFF)
# Allow a user to specify an optional default roots.pem file to embed into the
# library.
#
# This is useful if the library is distributed to an environment where gRPC
# hasn't been installed.
#
# To use, invoke cmake with
# cmake -DDEFAULT_SSL_ROOTS_PEM:STRING=/path/to/roots.pem ...
#
# See also discussion on https://github.com/grpc/grpc/issues/4834
set(DEFAULT_SSL_ROOTS_PEM "" CACHE STRING "Path to a default roots.pem file to embed")
if (WITH_GRPC)
set(LIGHTSTEP_USE_GRPC 1)
elseif(WITH_DYNAMIC_LOAD AND NOT WITH_LIBEVENT)
message(WARNING "WITH_GRPC is not set; building without dynamic loading support.")
set(WITH_DYNAMIC_LOAD 0)
endif()
option(BUILD_SHARED_LIBS "Build as a shared library" ON)
option(BUILD_STATIC_LIBS "Build as a static library" ON)
if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
message(FATAL_ERROR "One or both of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be set to ON to build")
endif()
# ==============================================================================
# Set up generated header files config.h and version.h
configure_file(version.h.in include/lightstep/version.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/lightstep
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
if(HEADERS_ONLY)
return()
endif()
# ==============================================================================
# Configure compiler warnings
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ==============================================================================
# Find packages
set(LIGHTSTEP_LINK_LIBRARIES "")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# Newer protobuf versions use cmake config files so try that first
#
# Note: The non-config protobuf module doesn't find PROTOBUF_PROTOC_EXECUTABLE properly on windows.
set(protobuf_MODULE_COMPATIBLE ON)
find_package(Protobuf CONFIG NAMES protobuf)
if (protobuf_FOUND)
list(APPEND LIGHTSTEP_LINK_LIBRARIES protobuf::libprotobuf)
else()
# Fall back to the old style protobuf module
find_package(Protobuf REQUIRED)
list(APPEND LIGHTSTEP_LINK_LIBRARIES ${PROTOBUF_LIBRARIES})
endif()
if (NOT DEFINED OPENTRACING_INCLUDE_DIR)
find_path(OPENTRACING_INCLUDE_DIR NAMES opentracing/tracer.h)
endif()
if (NOT DEFINED OPENTRACING_LIBRARY)
find_library(OPENTRACING_LIBRARY opentracing)
endif()
include_directories(SYSTEM ${OPENTRACING_INCLUDE_DIR})
list(APPEND LIGHTSTEP_LINK_LIBRARIES ${OPENTRACING_LIBRARY})
if (WITH_GRPC)
find_package(gRPC CONFIG)
# First attempt to set up gRPC via cmake; but if cmake config files aren't
# available, fallback to pkg-config.
if (gRPC_FOUND)
set(GRPC_CPP_PLUGIN $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
list(APPEND LIGHTSTEP_LINK_LIBRARIES gRPC::grpc++)
include_directories(SYSTEM
$<TARGET_PROPERTY:gRPC::grpc++,INTERFACE_INCLUDE_DIRECTORIES>)
else()
message("Falling back to finding gRPC with pkg-config")
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
if (NOT GRPC_CPP_PLUGIN)
message(FATAL_ERROR "grpc_cpp_plugin not found!")
endif()
find_package(PkgConfig REQUIRED)
pkg_search_module(GRPC REQUIRED grpc)
pkg_search_module(GRPCPP REQUIRED grpc++)
list(APPEND LIGHTSTEP_LINK_LIBRARIES ${GRPCPP_LDFLAGS} ${GRPC_LDFLAGS})
include_directories(SYSTEM ${GRPC_INCLUDE_DIRS} ${GRPCPP_INCLUDE_DIRS})
endif()
endif()
if (WITH_LIBEVENT)
find_package(Libevent REQUIRED)
list(APPEND LIGHTSTEP_LINK_LIBRARIES ${LIBEVENT_LIBRARIES})
include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
endif()
if (WITH_CARES)
find_package(CARES REQUIRED)
list(APPEND LIGHTSTEP_LINK_LIBRARIES ${CARES_LIBRARIES})
include_directories(SYSTEM ${CARES_INCLUDE_DIR})
endif()
if (WITH_LIBEVENT AND WITH_CARES)
set(LIGHTSTEP_USE_STREAMING 1)
endif()
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
list(APPEND LIGHTSTEP_LINK_LIBRARIES Threads::Threads)
if (WIN32)
list(APPEND LIGHTSTEP_LINK_LIBRARIES "wsock32" "ws2_32")
endif()
# ==============================================================================
# Build LightStep tracer library
add_library(dummy_version_check
src/common/version_check.cpp)
target_link_libraries(dummy_version_check ${OPENTRACING_LIBRARY})
add_subdirectory(3rd_party)
include_directories(SYSTEM ${LIGHTSTEP_THIRD_PARTY_INCLUDES})
include_directories(include)
include_directories(src)
install(DIRECTORY include/lightstep DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
include(LightStepTracerCommon)
include(LightStepTracerConfiguration)
set(LIGHTSTEP_SRCS src/common/utility.cpp
src/common/buffer_chain.cpp
src/common/fragment_input_stream.cpp
src/common/fragment_array_input_stream.cpp
src/common/protobuf.cpp
src/common/hex_conversion.cpp
src/common/in_memory_stream.cpp
src/common/logger.cpp
src/common/random.cpp
src/common/random_traverser.cpp
src/common/serialization.cpp
src/common/chunked_http_framing.cpp
src/common/report_request_framing.cpp
src/common/composable_fragment_input_stream.cpp
src/common/chained_stream.cpp
src/common/timestamp.cpp
src/recorder/report_builder.cpp
src/recorder/auto_recorder.cpp
src/recorder/fork_aware_recorder.cpp
src/recorder/legacy_manual_recorder.cpp
src/recorder/manual_recorder.cpp
src/recorder/metrics_tracker.cpp
src/recorder/transporter.cpp
src/recorder/serialization/report_request.cpp
src/recorder/serialization/report_request_header.cpp
src/recorder/serialization/embedded_metrics_message.cpp
src/tracer/binary_carrier.cpp
src/tracer/json_options.cpp
src/tracer/propagation/b3_propagator.cpp
src/tracer/propagation/baggage_propagator.cpp
src/tracer/propagation/binary_propagation.cpp
src/tracer/propagation/envoy_propagator.cpp
src/tracer/propagation/trace_context.cpp
src/tracer/propagation/trace_context_propagator.cpp
src/tracer/propagation/lightstep_propagator.cpp
src/tracer/propagation/multiheader_propagator.cpp
src/tracer/propagation/cloud_trace_propagator.cpp
src/tracer/propagation/propagation.cpp
src/tracer/propagation/propagation_options.cpp
src/tracer/immutable_span_context.cpp
src/tracer/legacy/legacy_span.cpp
src/tracer/legacy/legacy_tracer_impl.cpp
src/tracer/lightstep_span_context.cpp
src/tracer/lightstep_tracer_factory.cpp
src/tracer/serialization.cpp
src/tracer/span.cpp
src/tracer/tracer_impl.cpp
src/tracer/tracer.cpp
src/tracer/tag.cpp
src/tracer/utility.cpp
)
if (WIN32)
list(APPEND LIGHTSTEP_SRCS src/common/platform/error_windows.cpp
src/common/platform/network_windows.cpp
src/common/platform/network_environment_windows.cpp
src/common/platform/utility_windows.cpp
src/common/platform/string_windows.cpp
src/common/platform/fork_windows.cpp)
else()
list(APPEND LIGHTSTEP_SRCS src/common/platform/error_unix.cpp
src/common/platform/network_unix.cpp
src/common/platform/network_environment_unix.cpp
src/common/platform/utility_unix.cpp
src/common/platform/string_unix.cpp
src/common/platform/fork_unix.cpp)
endif()
if (WITH_GRPC)
list(APPEND LIGHTSTEP_SRCS src/recorder/grpc_transporter/grpc_transporter.cpp)
else()
list(APPEND LIGHTSTEP_SRCS src/recorder/no_grpc_transporter.cpp)
endif()
if (WITH_LIBEVENT)
list(APPEND LIGHTSTEP_SRCS src/recorder/stream_recorder/stream_recorder.cpp
src/recorder/stream_recorder/stream_recorder_impl.cpp
src/recorder/stream_recorder/satellite_dns_resolution_manager.cpp
src/recorder/stream_recorder/satellite_endpoint_manager.cpp
src/recorder/stream_recorder/satellite_connection.cpp
src/recorder/stream_recorder/satellite_streamer.cpp
src/recorder/stream_recorder/span_stream.cpp
src/recorder/metrics_tracker.cpp
src/recorder/stream_recorder/connection_stream.cpp
src/recorder/stream_recorder/host_header.cpp
src/recorder/stream_recorder/status_line_parser.cpp
src/recorder/stream_recorder/utility.cpp
src/network/event.cpp
src/network/event_base.cpp
src/network/timer_event.cpp
src/network/ip_address.cpp
src/network/socket.cpp
src/network/vector_write.cpp
)
if (WITH_CARES)
list(APPEND LIGHTSTEP_SRCS src/network/ares_dns_resolver/ares_dns_resolver.cpp
src/network/ares_dns_resolver/ares_library_handle.cpp
)
else()
list(APPEND LIGHTSTEP_SRCS src/network/no_dns_resolver.cpp)
endif()
else()
list(APPEND LIGHTSTEP_SRCS src/recorder/no_stream_recorder.cpp)
endif()
if (WITH_DYNAMIC_LOAD)
list(APPEND LIGHTSTEP_SRCS src/tracer/dynamic_load.cpp)
endif()
if (DEFAULT_SSL_ROOTS_PEM STREQUAL "")
list(APPEND LIGHTSTEP_SRCS src/tracer/no_default_ssl_roots_pem.cpp)
else()
# Follows the approach described in https://stackoverflow.com/a/11814544/4447365
set(EMBED_SSL_ROOTS_PEM_CPP_FILE ${CMAKE_BINARY_DIR}/default_ssl_roots_pem.cpp)
add_custom_command(
OUTPUT ${EMBED_SSL_ROOTS_PEM_CPP_FILE}
COMMAND embedfile default_ssl_roots_pem ${DEFAULT_SSL_ROOTS_PEM}
DEPENDS ${DEFAULT_ROOT_PEM}
)
list(APPEND LIGHTSTEP_SRCS ${EMBED_SSL_ROOTS_PEM_CPP_FILE})
endif()
if (BUILD_SHARED_LIBS)
add_library(lightstep_tracer SHARED $<TARGET_OBJECTS:lightstep_tracer_common>
$<TARGET_OBJECTS:lightstep_tracer_configuration>
$<TARGET_OBJECTS:lightstep_3rd_party>
${LIGHTSTEP_SRCS})
target_compile_options(lightstep_tracer PUBLIC ${WARNING_CXX_FLAGS})
target_link_libraries(lightstep_tracer ${LIGHTSTEP_LINK_LIBRARIES})
set_target_properties(lightstep_tracer PROPERTIES SOVERSION ${LIGHTSTEP_VERSION_MAJOR})
install(TARGETS lightstep_tracer
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if (BUILD_STATIC_LIBS)
add_library(lightstep_tracer-static STATIC $<TARGET_OBJECTS:lightstep_tracer_common>
$<TARGET_OBJECTS:lightstep_tracer_configuration>
$<TARGET_OBJECTS:lightstep_3rd_party>
${LIGHTSTEP_SRCS})
set_target_properties(lightstep_tracer-static PROPERTIES OUTPUT_NAME lightstep_tracer)
target_compile_options(lightstep_tracer-static PUBLIC ${WARNING_CXX_FLAGS})
target_link_libraries(lightstep_tracer-static ${LIGHTSTEP_LINK_LIBRARIES})
install(TARGETS lightstep_tracer-static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# ==============================================================================
# Build tests and examples
if (BUILD_SHARED_LIBS)
set(LIGHTSTEP_LIBRARY "lightstep_tracer")
else()
set(LIGHTSTEP_LIBRARY "lightstep_tracer-static")
endif()
include(CTest)
if (BUILD_TESTING)
add_subdirectory(test/cmake)
add_subdirectory(example)
endif()