Debian Codegraph @

CMakeLists.txt

raw ◀ ▶
Source reconstructed at patch state 1 of 2 — not the installed (fully patched) source.
2 Debian patches touch this file
1 #
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18 #
19
20 cmake_minimum_required (VERSION 2.8.12)
21
22 project (Proton C)
23
24 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tools/cmake/Modules")
25 set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
26
27 include (CTest)
28 include (CheckLanguage)
29 include (CheckLibraryExists)
30 include (CheckSymbolExists)
31 include (CheckPythonModule)
32
33 find_package (OpenSSL)
34 find_package (Threads)
35 find_package (SWIG)
36 find_package (CyrusSASL)
37
38 # This setting mirrors FindPythonInterp behavior on Windows/macOS, which did not consult registry/frameworks first.`
39 if (NOT DEFINED Python_FIND_REGISTRY)
40 set(Python_FIND_REGISTRY "LAST")
41 endif ()
42 if (NOT DEFINED Python_FIND_FRAMEWORK)
43 set(Python_FIND_FRAMEWORK "LAST")
44 endif ()
45 find_package(Python 3.6
46 REQUIRED COMPONENTS Interpreter
47 OPTIONAL_COMPONENTS Development)
48
49 include(tests/PNAddTest.cmake)
50
51 # Set up runtime checks (valgrind, sanitizers etc.)
52 include(tests/RuntimeCheck.cmake)
53
54 ## Set up so that find_package(Proton) & find_package(ProtonCpp) work in the build tree
55 set (Proton_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/config)
56 set (ProtonCpp_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake/config)
57
58 ## Variables used across components
59
60 set (PN_ENV_SCRIPT "${Python_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/scripts/env.py")
61 set (PN_C_INCLUDE_DIR "${CMAKE_BINARY_DIR}/c/include")
62 set (PN_C_LIBRARY_DIR "${CMAKE_BINARY_DIR}/c")
63 set (PN_C_SOURCE_DIR "${CMAKE_BINARY_DIR}/c/src")
64
65 ## C
66 if (DEFINED CMAKE_C_COMPILE_FEATURES)
67 set(CMAKE_C_STANDARD 99)
68 set(CMAKE_C_EXTENSIONS OFF)
69 set(CMAKE_C_STANDARD_REQUIRED ON)
70 else()
71 set (C_STANDARD_GNU -std=c99)
72 set (C_EXTENDED_GNU -std=gnu99)
73 set (C_STANDARD_Clang -std=c99)
74 set (C_EXTENDED_Clang -std=gnu99)
75 endif()
76
77 set (C_STANDARD_FLAGS ${C_STANDARD_${CMAKE_C_COMPILER_ID}})
78 set (C_EXTENDED_FLAGS ${C_EXTENDED_${CMAKE_C_COMPILER_ID}})
79
80 ## C++
81 check_language (CXX)
82 if (CMAKE_CXX_COMPILER)
83 enable_language(CXX)
84
85 # This effectively checks for cmake version 3.1 or later
86 if (DEFINED CMAKE_CXX_COMPILE_FEATURES)
87 set(CMAKE_CXX_STANDARD 11)
88 set(CMAKE_CXX_EXTENSIONS OFF)
89 else ()
90 # This can only be a fairly old version of Linux in practice
91 set(CXX_STANDARD "-std=c++11")
92 endif ()
93 endif()
94
95 # Build static C and C++ libraries in addition to shared libraries.
96 option(BUILD_STATIC_LIBS "Build static libraries as well as shared libraries" OFF)
97
98 if (CMAKE_CONFIGURATION_TYPES)
99 # There is no single "build type"...
100 message(STATUS "Build types are ${CMAKE_CONFIGURATION_TYPES}")
101 else (CMAKE_CONFIGURATION_TYPES)
102 # There is a single build configuration
103 # If the build type is not set then set the default
104 if (NOT CMAKE_BUILD_TYPE)
105 set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
106 "Build type: Debug, Release, RelWithDebInfo, MinSizeRel or Coverage (default RelWithDebInfo)" FORCE)
107 endif ()
108
109 # Set up extra coverage analysis options for gcc and clang
110 if (CMAKE_COMPILER_IS_GNUCC)
111 set (CMAKE_C_FLAGS_COVERAGE "-g -O0 --coverage")
112 set (CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage")
113 set (CMAKE_EXE_LINKER_FLAGS_COVERAGE "--coverage")
114 set (CMAKE_MODULE_LINKER_FLAGS_COVERAGE "--coverage")
115 set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE "--coverage")
116 mark_as_advanced(
117 CMAKE_C_FLAGS_COVERAGE CMAKE_CXX_FLAGS_COVERAGE
118 CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_MODULE_LINKER_FLAGS_COVERAGE
119 CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
120 endif()
121
122 if (CMAKE_BUILD_TYPE MATCHES "Deb")
123 set (has_debug_symbols " (has debug symbols)")
124 endif (CMAKE_BUILD_TYPE MATCHES "Deb")
125 message(STATUS "Build type is \"${CMAKE_BUILD_TYPE}\"${has_debug_symbols}")
126 endif (CMAKE_CONFIGURATION_TYPES)
127
128 # Add coverage target if we're building for test coverage
129 if (CMAKE_BUILD_TYPE MATCHES "Coverage")
130 make_directory(coverage_results)
131 add_custom_target(coverage
132 WORKING_DIRECTORY ./coverage_results
133 COMMAND ${CMAKE_SOURCE_DIR}/scripts/record-coverage.sh ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
134 endif()
135
136 # Try to keep any platform specific overrides together here:
137
138 # MacOS has a bunch of differences in build tools and process and so we have to turn some things
139 # off if building there:
140 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
141 set (NOENABLE_WARNING_ERROR ON)
142 set (LIB_SUFFIX "")
143 if (POLICY CMP0042)
144 cmake_policy (SET CMP0042 NEW)
145 endif ()
146 endif ()
147
148 # Benchmarks should be disabled by default
149 set (NOENABLE_BENCHMARKS ON)
150
151 # Add options here called <whatever> they will turn into "ENABLE_<whatever" and can be
152 # overridden on a platform specific basis above by NOENABLE_<whatever>
153 set (OPTIONS WARNING_ERROR UNDEFINED_ERROR LINKTIME_OPTIMIZATION HIDE_UNEXPORTED_SYMBOLS FUZZ_TESTING BENCHMARKS)
154
155 foreach (OPTION ${OPTIONS})
156 if (NOT NOENABLE_${OPTION})
157 set ("DEFAULT_${OPTION}" ON)
158 endif ()
159 endforeach (OPTION)
160
161 # And add the option here too with help text
162 option(ENABLE_WARNING_ERROR "Consider compiler warnings to be errors" ${DEFAULT_WARNING_ERROR})
163 option(ENABLE_UNDEFINED_ERROR "Check for unresolved library symbols" ${DEFAULT_UNDEFINED_ERROR})
164 option(ENABLE_LINKTIME_OPTIMIZATION "Perform link time optimization" ${DEFAULT_LINKTIME_OPTIMIZATION})
165 option(ENABLE_HIDE_UNEXPORTED_SYMBOLS "Only export library symbols that are explicitly requested" ${DEFAULT_HIDE_UNEXPORTED_SYMBOLS})
166 option(ENABLE_FUZZ_TESTING "Enable building fuzzers and regression testing with libFuzzer" ${DEFAULT_FUZZ_TESTING})
167 option(ENABLE_BENCHMARKS "Enable building and running benchmarks with Google Benchmark" ${DEFAULT_BENCHMARKS})
168
169 option(BUILD_EXAMPLES "Enable building example programs" ON)
170 option(BUILD_TLS "Enable building separate TLS library for Proton raw connections" OFF)
171
172 # Set any additional compiler specific flags
173 set (LTO_GNU "-flto -fno-fat-lto-objects")
174 set (LTO_Clang "-flto=thin")
175 set (LTO_MSVC "/GL")
176 set (LINK_LTO_GNU "-flto -fno-fat-lto-objects")
177 set (LINK_LTO_Clang "-flto=thin")
178 set (LINK_LTO_MSVC "/LTCG")
179
180 set (WERROR_GNU "-Werror")
181 set (WERROR_Clang "-Werror")
182 set (WERROR_MSVC "")
183
184 set (COMMON_WARNING_GNU "-Wall -pedantic-errors")
185 set (COMMON_WARNING_Clang "-Wall -pedantic")
186 set (COMMON_WARNING_MSVC "")
187
188 set (CC_WARNING_GNU "-Wno-unused-parameter -Wstrict-prototypes -Wvla -Wsign-compare -Wwrite-strings")
189 set (CC_WARNING_Clang "-Wno-unused-parameter -Wstrict-prototypes -Wvla -Wsign-compare -Wwrite-strings")
190 set (CC_WARNING_MSVC "/wd4244 /wd4267 /wd4800 /wd4996")
191
192 set (CXX_WARNING_GNU "")
193 set (CXX_WARNING_Clang "")
194 set (CXX_WARNING_MSVC "")
195
196 set (CATCH_UNDEFINED_Linux "-Wl,--no-undefined")
197 set (CATCH_UNDEFINED_FreeBSD "-Wl,--no-undefined")
198 set (CATCH_UNDEFINED_Darwin "-Wl,-undefined,error")
199 set (CATCH_UNDEFINED_Windows "")
200
201 set (HIDE_SYMBOLS_GNU "-fvisibility=hidden")
202 set (HIDE_SYMBOLS_Clang "-fvisibility=hidden")
203 set (HIDE_SYMBOLS_SunPro "-xldscope=hidden")
204
205 if (ENABLE_LINKTIME_OPTIMIZATION)
206 set (LTO ${LTO_${CMAKE_C_COMPILER_ID}})
207 set (LINK_LTO ${LINK_LTO_${CMAKE_C_COMPILER_ID}})
208 endif (ENABLE_LINKTIME_OPTIMIZATION)
209
210 if (ENABLE_WARNING_ERROR)
211 set (WERROR ${WERROR_${CMAKE_C_COMPILER_ID}})
212 endif (ENABLE_WARNING_ERROR)
213
214 if (ENABLE_UNDEFINED_ERROR)
215 set (CATCH_UNDEFINED ${CATCH_UNDEFINED_${CMAKE_SYSTEM_NAME}})
216 endif (ENABLE_UNDEFINED_ERROR)
217
218 if (ENABLE_HIDE_UNEXPORTED_SYMBOLS)
219 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HIDE_SYMBOLS_${CMAKE_C_COMPILER_ID}}")
220 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HIDE_SYMBOLS_${CMAKE_C_COMPILER_ID}}")
221 endif (ENABLE_HIDE_UNEXPORTED_SYMBOLS)
222
223 set (COMMON_WARNING_FLAGS ${COMMON_WARNING_${CMAKE_C_COMPILER_ID}})
224 set (CXX_WARNING_FLAGS "${WERROR} ${COMMON_WARNING_FLAGS} ${CXX_WARNING_${CMAKE_C_COMPILER_ID}}")
225 set (COMPILE_WARNING_FLAGS "${WERROR} ${COMMON_WARNING_FLAGS} ${CC_WARNING_${CMAKE_C_COMPILER_ID}}")
226
227 if (MSVC)
228 set(CMAKE_DEBUG_POSTFIX "d")
229 endif (MSVC)
230
231 file(READ VERSION.txt PN_VERSION_FILE)
232 string(STRIP ${PN_VERSION_FILE} PN_VERSION_LINE)
233 string(REPLACE "-" ";" PN_VERSION_SPLIT "${PN_VERSION_LINE}")
234 list(GET PN_VERSION_SPLIT 0 PN_VERSION_CLEAN)
235 list(REMOVE_AT PN_VERSION_SPLIT 0)
236 string(REPLACE ";" "-" PN_VERSION_QUALIFIER "${PN_VERSION_SPLIT}")
237 string(REGEX MATCHALL "[0-9]+" PN_VERSION_LIST "${PN_VERSION_CLEAN}")
238
239 list(GET PN_VERSION_LIST 0 PN_VERSION_MAJOR)
240 list(GET PN_VERSION_LIST 1 PN_VERSION_MINOR)
241
242 list(LENGTH PN_VERSION_LIST PN_VERSION_LENGTH)
243 if (${PN_VERSION_LENGTH} GREATER 2)
244 list(GET PN_VERSION_LIST 2 PN_VERSION_POINT)
245 set (PN_VERSION "${PN_VERSION_MAJOR}.${PN_VERSION_MINOR}.${PN_VERSION_POINT}")
246 else()
247 set (PN_VERSION_POINT 0)
248 set (PN_VERSION "${PN_VERSION_MAJOR}.${PN_VERSION_MINOR}")
249 endif()
250
251 message(STATUS "PN_VERSION: ${PN_VERSION} (${PN_VERSION_QUALIFIER})")
252
253 # In rpm builds the build sets some variables:
254 # CMAKE_INSTALL_PREFIX - this is a standard cmake variable
255 # INCLUDE_INSTALL_DIR
256 # LIB_INSTALL_DIR
257 # SYSCONF_INSTALL_DIR
258 # SHARE_INSTALL_DIR
259 # So make these cached variables and the specific variables non cached
260 # and derived from them.
261
262 if (NOT DEFINED LIB_SUFFIX)
263 get_property(LIB64 GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS)
264 if ("${LIB64}" STREQUAL "TRUE" AND ${CMAKE_SIZEOF_VOID_P} STREQUAL "8")
265 set(LIB_SUFFIX 64)
266 else()
267 set(LIB_SUFFIX "")
268 endif()
269 endif()
270
271 # Start of variables used during install
272 set (INCLUDE_INSTALL_DIR include CACHE PATH "Include file directory")
273 set (LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "Library object file directory")
274 set (SYSCONF_INSTALL_DIR etc CACHE PATH "System read only configuration directory")
275 set (SHARE_INSTALL_DIR share CACHE PATH "Shared read only data directory")
276 set (MAN_INSTALL_DIR share/man CACHE PATH "Manpage directory")
277
278 mark_as_advanced (INCLUDE_INSTALL_DIR LIB_INSTALL_DIR SYSCONF_INSTALL_DIR SHARE_INSTALL_DIR MAN_INSTALL_DIR)
279
280 # Sets variable NAME to contain relative path from ROOT to VALUE
281 # if VALUE is already relative, it does nothing
282 macro (pn_relative_install_dir NAME ROOT VALUE)
283 if (IS_ABSOLUTE ${VALUE})
284 file(RELATIVE_PATH "${NAME}" "${ROOT}" "${VALUE}")
285 else ()
286 set (${NAME} "${VALUE}")
287 endif ()
288 endmacro ()
289
290 pn_relative_install_dir (INCLUDEDIR "${CMAKE_INSTALL_PREFIX}" "${INCLUDE_INSTALL_DIR}")
291 pn_relative_install_dir (LIBDIR "${CMAKE_INSTALL_PREFIX}" "${LIB_INSTALL_DIR}")
292
293 ## LANGUAGE BINDINGS
294
295 # Default directory for language bindings not being installed into
296 # system specified locations.
297 set (BINDINGS_DIR ${LIB_INSTALL_DIR}/proton/bindings)
298
299 set (SYSINSTALL_BINDINGS OFF CACHE BOOL "If SYSINSTALL_BINDINGS is OFF then proton bindings will be installed underneath ${BINDINGS_DIR} and each user will need to modify their interpreter configuration to load the appropriate binding. If SYSINSTALL_BINDINGS is ON, then each language interpreter will be queried for the appropriate directory and proton bindings will be installed and available system wide with no additional per user configuration.")
300
301 set (BINDING_LANGS PYTHON RUBY)
302
303 foreach (LANG ${BINDING_LANGS})
304 set (SYSINSTALL_${LANG} OFF CACHE BOOL "Install ${LANG} bindings into interpreter specified location.")
305 if (SYSINSTALL_BINDINGS OR SYSINSTALL_${LANG})
306 set (CHECK_SYSINSTALL_${LANG} ON)
307 else ()
308 set (CHECK_SYSINSTALL_${LANG} OFF)
309 endif ()
310 endforeach()
311
312 set (PROTON_SHARE ${SHARE_INSTALL_DIR}/proton)
313 # End of variables used during install
314
315 # Set result to a native search path - used by examples and binding tests.
316 # args after result are directories or search paths.
317 macro(set_search_path result)
318 set(${result} ${ARGN})
319 if (UNIX)
320 string(REPLACE ";" ":" ${result} "${${result}}") # native search path separators.
321 endif()
322 file(TO_NATIVE_PATH "${${result}}" ${result}) # native slash separators
323 endmacro()
324
325 if (CMAKE_SYSTEM_NAME STREQUAL Windows)
326 # CMake uses semicolon as list separator. Change ';'->'\;'
327 function(to_native_path path result)
328 file (TO_NATIVE_PATH "${path}" path)
329 string (REPLACE ";" "\;" path "${path}")
330 # without this, ...;last\dir\ would later combine with list separator ; into \;
331 set (${result} "${path}\;" PARENT_SCOPE)
332 endfunction()
333 else (CMAKE_SYSTEM_NAME STREQUAL Windows)
334 # Just change ';'->':'
335 function(to_native_path path result)
336 file (TO_NATIVE_PATH "${path}" path)
337 string (REPLACE ";" ":" path "${path}")
338 set (${result} "${path}" PARENT_SCOPE)
339 endfunction()
340 endif (CMAKE_SYSTEM_NAME STREQUAL Windows)
341
342 add_custom_target(docs)
343 add_custom_target(doc DEPENDS docs)
344
345 # Note: Process bindings after the source lists have been defined so
346 # the bindings can reference them.
347 add_subdirectory(c)
348
349 # Add bindings that do not require swig here - the directory name must be the same as the binding name
350 # See below for swig bindings
351 set(BINDINGS cpp go)
352
353 if (CMAKE_CXX_COMPILER)
354 set (DEFAULT_CPP ON)
355 endif()
356
357 # Prerequisites for Go
358 find_program(GO_EXE go)
359 mark_as_advanced(GO_EXE)
360 if (GO_EXE)
361 set (DEFAULT_GO ON)
362 if(WIN32 OR RUNTIME_CHECK)
363 # Go on windows requires gcc tool chain
364 # Go does not work with C-based runtime checkers.
365 set (DEFAULT_GO OFF)
366 endif()
367 endif (GO_EXE)
368
369 if(SWIG_FOUND)
370 # Add any new swig bindings here - the directory name must be the same as the binding name
371 list(APPEND BINDINGS python ruby)
372
373 if (POLICY CMP0078)
374 cmake_policy(SET CMP0078 NEW)
375 endif()
376 if (POLICY CMP0086)
377 cmake_policy(SET CMP0086 NEW)
378 endif()
379 include(UseSWIG)
380
381 # All swig modules should include ${PROTON_HEADERS} in SWIG_MODULE_<name>_EXTRA_DEPS
382 file(GLOB PROTON_HEADERS "${CMAKE_SOURCE_DIR}/c/include/proton/*.h")
383 # All swig modules should include ${BINDING_DEPS} or ${BINDING_DEPS_FULL} in swig_link_libraries
384 set (BINDING_DEPS qpid-proton-core)
385 set (BINDING_DEPS_FULL qpid-proton)
386
387 # Add a block here to detect the prerequisites to build each language binding:
388 #
389 # If the prerequisites for the binding are present set a variable called
390 # DEFAULT_{uppercase name of binding} to ON
391
392 # Prerequisites for Python wrapper:
393 if (Python_Development_FOUND)
394 set (DEFAULT_PYTHON ON)
395 endif ()
396
397 # Prerequisites for Ruby:
398 find_package(Ruby)
399 if (RUBY_FOUND)
400 set (DEFAULT_RUBY ON)
401 endif ()
402 endif()
403
404 # To kick-start a build with just a few bindings enabled by default, e.g. ruby and go:
405 #
406 # cmake -DBUILD_BINDINGS="ruby;go"
407 #
408 # This is only used when CMakeCache.txt is first created, after that set the normal
409 # BUILD_XXX variables to enable/disable bindings.
410 #
411 if (NOT DEFINED BUILD_BINDINGS)
412 set(BUILD_BINDINGS "${BINDINGS}")
413 endif()
414
415 foreach(BINDING ${BINDINGS})
416 string(TOUPPER ${BINDING} UBINDING)
417 list(FIND BUILD_BINDINGS ${BINDING} N)
418 if(NOBUILD_${UBINDING} OR ( N EQUAL -1 ) ) # Over-ridden or not on the BUILD_BINDINGS list
419 set(DEFAULT_${UBINDING} OFF)
420 endif()
421 option(BUILD_${UBINDING} "Build ${BINDING} language binding" ${DEFAULT_${UBINDING}})
422 if (BUILD_${UBINDING})
423 add_subdirectory(${BINDING})
424 endif ()
425 endforeach(BINDING)
426
427 unset(BUILD_BINDINGS CACHE) # Remove from cache, only relevant when creating the initial cache.
428
429 install (FILES LICENSE.txt README.md tests/share/CMakeLists.txt DESTINATION ${PROTON_SHARE})
430 install (FILES tests/share/examples-README.md RENAME README.md DESTINATION ${PROTON_SHARE}/examples)
431 install (DIRECTORY tests DESTINATION ${PROTON_SHARE} PATTERN share EXCLUDE)
432
433 # Generate test environment settings
434 configure_file(${CMAKE_SOURCE_DIR}/misc/config.sh.in
435 ${CMAKE_BINARY_DIR}/config.sh @ONLY)
436 configure_file(${CMAKE_SOURCE_DIR}/misc/config.bat.in
437 ${CMAKE_BINARY_DIR}/config.bat @ONLY)
438
439 if (BUILD_EXAMPLES)
440 add_subdirectory(tests/examples)
441 endif (BUILD_EXAMPLES)