]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentracing-cpp/CMakeLists.txt
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / opentracing-cpp / CMakeLists.txt
1 set(CPACK_RPM_COMPONENT_INSTALL ON)
2 cmake_minimum_required(VERSION 3.1)
3
4 project(opentracing-cpp)
5
6 # ==============================================================================
7 # Version information
8
9 # Increment ABI version for any ABI-breaking change.
10 #
11 # Also, whenever the ABI is between versions and in development
12 # suffix the ABI version number with "_unstable".
13 set(OPENTRACING_ABI_VERSION "3")
14
15 # Version number follows semver
16 # See https://semver.org/
17 set(OPENTRACING_VERSION_MAJOR "1")
18 set(OPENTRACING_VERSION_MINOR "6")
19 set(OPENTRACING_VERSION_PATCH "0")
20 set(OPENTRACING_VERSION_STRING
21 "${OPENTRACING_VERSION_MAJOR}.${OPENTRACING_VERSION_MINOR}.${OPENTRACING_VERSION_PATCH}")
22
23 # ==============================================================================
24 # Set up cpack
25
26 SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "C++ implementation of the OpenTracing API")
27 SET(CPACK_PACKAGE_VENDOR "opentracing.io")
28 SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
29 SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
30 SET(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
31
32 SET(CPACK_PACKAGE_VERSION_MAJOR ${OPENTRACING_VERSION_MAJOR})
33 SET(CPACK_PACKAGE_VERSION_MINOR ${OPENTRACING_VERSION_MINOR})
34 SET(CPACK_PACKAGE_VERSION_PATCH ${OPENTRACING_VERSION_PATCH})
35 set(CPACK_RPM_DIST_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/runldconfig)
36 set(CPACK_RPM_DIST_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/runldconfig)
37 set(CPACK_COMPONENTS_ALL DIST DEVEL)
38 set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
39 set(CPACK_GENERATOR "RPM")
40 set(CPACK_COMPONENTS_IGNORE_GROUPS 1)
41
42 include(CPack)
43
44 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
45 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
46 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
47
48 # ==============================================================================
49 # Configure compilers
50
51 set(CMAKE_CXX_STANDARD 11)
52 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
53 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything \
54 -Wno-c++98-compat \
55 -Wno-c++98-compat-pedantic \
56 -Wno-c++98-compat-bind-to-temporary-copy \
57 -Wno-weak-vtables \
58 -Wno-exit-time-destructors \
59 -Wno-global-constructors \
60 -Wno-padded")
61 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
62 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
63 elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
64 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_SCL_SECURE_NO_WARNINGS")
65 endif()
66
67 # ==============================================================================
68 # Set up linter
69
70 option(ENABLE_LINTING "Run clang-tidy on source files" ON)
71 if(ENABLE_LINTING)
72 find_program(CLANG_TIDY_EXE NAMES "clang-tidy"
73 DOC "Path to clang-tidy executable")
74 if(NOT CLANG_TIDY_EXE)
75 message(STATUS "clang-tidy not found.")
76 else()
77 message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
78 set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" "-checks=*,-clang-analyzer-alpha.*")
79 endif()
80 endif()
81
82 # ==============================================================================
83 # Check for weak symbol support
84
85 try_compile(
86 SUPPORTS_WEAK_SYMBOLS
87 "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CMakeTmp"
88 SOURCES ${CMAKE_CURRENT_LIST_DIR}/cmake/weak_symbol.cpp)
89
90 # ==============================================================================
91 # Set up options
92
93 option(BUILD_SHARED_LIBS "Build as a shared library" ON)
94 option(BUILD_STATIC_LIBS "Build as a static library" ON)
95 option(BUILD_MOCKTRACER "Build mocktracer library" ON)
96 option(BUILD_DYNAMIC_LOADING "Build with dynamic loading support" ON)
97
98 if (BUILD_DYNAMIC_LOADING)
99 if (NOT WIN32)
100 if (NOT SUPPORTS_WEAK_SYMBOLS OR NOT UNIX)
101 message(WARNING "Building without dynamic loading support.")
102 set(BUILD_DYNAMIC_LOADING OFF)
103 endif()
104 endif()
105 endif()
106
107 set(OPENTRACING_BUILD_DYNAMIC_LOADING ${BUILD_DYNAMIC_LOADING})
108
109 if (NOT BUILD_SHARED_LIBS AND NOT BUILD_STATIC_LIBS)
110 message(FATAL_ERROR "One or both of BUILD_SHARED_LIBS or BUILD_STATIC_LIBS must be set to ON to build")
111 endif()
112
113 # ==============================================================================
114 # Set up libdir
115
116 if (NOT DEFINED LIB_INSTALL_DIR)
117 set(LIB_INSTALL_DIR lib)
118 endif()
119
120 # ==============================================================================
121 # Set up generated header files config.h and version.h
122
123 configure_file(version.h.in include/opentracing/version.h)
124 configure_file(config.h.in include/opentracing/config.h)
125 include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
126 install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/opentracing
127 DESTINATION include
128 COMPONENT DEVEL)
129
130 # ==============================================================================
131 # OpenTracing library targets
132
133 include_directories(include)
134 include_directories(SYSTEM 3rd_party/include)
135
136 set(SRCS src/propagation.cpp
137 src/dynamic_load.cpp
138 src/noop.cpp
139 src/tracer.cpp
140 src/tracer_factory.cpp
141 src/ext/tags.cpp)
142
143 if (BUILD_DYNAMIC_LOADING)
144 if (WIN32)
145 list(APPEND SRCS src/dynamic_load_windows.cpp)
146 else()
147 list(APPEND SRCS src/dynamic_load_unix.cpp)
148 endif()
149 else()
150 list(APPEND SRCS src/dynamic_load_unsupported.cpp)
151 endif()
152
153 list(APPEND LIBRARIES "")
154 if (BUILD_DYNAMIC_LOADING)
155 list(APPEND LIBRARIES ${CMAKE_DL_LIBS})
156 endif()
157
158
159 if (BUILD_SHARED_LIBS)
160 add_library(opentracing SHARED ${SRCS})
161 target_link_libraries(opentracing ${LIBRARIES})
162 target_include_directories(opentracing INTERFACE "$<INSTALL_INTERFACE:include/>")
163 set_target_properties(opentracing PROPERTIES VERSION ${OPENTRACING_VERSION_STRING}
164 SOVERSION ${OPENTRACING_VERSION_MAJOR})
165 target_compile_definitions(opentracing PRIVATE OPENTRACING_EXPORTS)
166 install(TARGETS opentracing EXPORT OpenTracingTargets
167 COMPONENT DIST
168 RUNTIME DESTINATION ${LIB_INSTALL_DIR}
169 LIBRARY DESTINATION ${LIB_INSTALL_DIR}
170 ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
171 )
172 if (CLANG_TIDY_EXE)
173 set_target_properties(opentracing PROPERTIES
174 CXX_CLANG_TIDY "${DO_CLANG_TIDY}")
175 endif()
176 endif()
177
178 if (BUILD_STATIC_LIBS)
179 add_library(opentracing-static STATIC ${SRCS})
180 target_link_libraries(opentracing-static ${LIBRARIES})
181 # Windows generates a lib and dll files for a shared library. using the same name will override the lib file generated by the shared target
182 if (NOT WIN32)
183 set_target_properties(opentracing-static PROPERTIES OUTPUT_NAME opentracing)
184 endif()
185 target_compile_definitions(opentracing-static PUBLIC OPENTRACING_STATIC)
186 target_include_directories(opentracing-static INTERFACE "$<INSTALL_INTERFACE:include/>")
187 install(TARGETS opentracing-static EXPORT OpenTracingTargets
188 ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
189 endif()
190
191
192 install(DIRECTORY 3rd_party/include/opentracing/expected
193 COMPONENT DEVEL
194 DESTINATION include/opentracing
195 FILES_MATCHING PATTERN "*.hpp"
196 PATTERN "*.h")
197 install(DIRECTORY 3rd_party/include/opentracing/variant
198 COMPONENT DEVEL
199 DESTINATION include/opentracing
200 FILES_MATCHING PATTERN "*.hpp"
201 PATTERN "*.h")
202 install(DIRECTORY include/opentracing
203 COMPONENT DEVEL
204 DESTINATION include
205 FILES_MATCHING PATTERN "*.h")
206
207
208 if (BUILD_MOCKTRACER)
209 add_subdirectory(mocktracer)
210 endif()
211
212 # ==============================================================================
213 # Package configuration setup
214
215 include(CMakePackageConfigHelpers)
216 write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/OpenTracingConfigVersion.cmake"
217 VERSION ${OPENTRACING_VERSION_STRING}
218 COMPATIBILITY AnyNewerVersion)
219 export(EXPORT OpenTracingTargets
220 FILE "${CMAKE_CURRENT_BINARY_DIR}/OpenTracingTargets.cmake"
221 NAMESPACE OpenTracing::)
222 configure_file(cmake/OpenTracingConfig.cmake
223 "${CMAKE_CURRENT_BINARY_DIR}/OpenTracingConfig.cmake"
224 COPYONLY)
225 set(ConfigPackageLocation ${LIB_INSTALL_DIR}/cmake/OpenTracing)
226 install(EXPORT OpenTracingTargets
227 FILE OpenTracingTargets.cmake
228 NAMESPACE OpenTracing::
229 DESTINATION ${ConfigPackageLocation})
230 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/OpenTracingConfig.cmake
231 "${CMAKE_CURRENT_BINARY_DIR}/OpenTracingConfigVersion.cmake"
232 DESTINATION ${ConfigPackageLocation}
233 COMPONENT Devel)
234
235 # ==============================================================================
236 # Testing
237
238 include(CTest)
239 if(BUILD_TESTING)
240 add_subdirectory(test)
241 endif()
242
243 # ==============================================================================
244 # Examples
245
246 if(BUILD_TESTING)
247 add_subdirectory(example)
248 endif()