2 # This file is open source software, licensed to you under the terms
3 # of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 # distributed with this work for additional information regarding copyright
5 # ownership. You may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
20 # Copyright (C) 2018 Scylladb, Ltd.
23 cmake_minimum_required (VERSION 3.5)
25 list (APPEND CMAKE_MODULE_PATH
26 ${CMAKE_CURRENT_SOURCE_DIR}/cmake
27 ${CMAKE_CURRENT_BINARY_DIR})
29 include (Cooking OPTIONAL)
31 # This variable impacts the way DPDK is configured by cmake-cooking (if DPDK is enabled), so its definition needs to
32 # come before PROJECT.
33 set (Seastar_DPDK_MACHINE
37 "Configure DPDK for this processor architecture (if `Seastar_DPDK` is enabled). A DPDK code name abbreviation (e.g., ivb)")
43 # generic boolean values passed as string, potentially from configure.py
44 set (True_STRING_VALUES "ON" "yes" "Yes" "YES" "true" "True" "TRUE")
45 set (False_STRING_VALUES "OFF" "no" "No" "NO" "false" "False" "FALSE")
46 set (Default_STRING_VALUES "DEFAULT" "default" "Default")
48 set (Seastar_ALLOC_FAILURE_INJECTION
52 "Enable failure injection into the Seastar allocator. Can be ON, OFF or DEFAULT (which enables it for Dev mode)")
54 option (Seastar_TASK_BACKTRACE
55 "Collect backtrace at deferring points."
58 option (Seastar_DEBUG_ALLOCATIONS
59 "For now just writes 0xab to newly allocated memory"
62 option (Seastar_SSTRING
63 "Use seastar's own string implementation"
66 set (Seastar_API_LEVEL
70 "Seastar compatibility API level (2=server_socket::accept() returns accept_result, 3=make_file_output_stream(), make_file_data_sink() returns future<...>, 4=when_all_succeed returns future<std::tuple<>>, 5=future<T>::get() returns T&&), 6=future is not variadic")
72 set_property (CACHE Seastar_API_LEVEL
76 set (Seastar_SCHEDULING_GROUPS_COUNT
80 "A positive number to set Seastar's reactor number of allowed different scheduling groups.")
82 if (NOT Seastar_SCHEDULING_GROUPS_COUNT MATCHES "^[1-9][0-9]*")
83 message(FATAL_ERROR "Seastar_SCHEDULING_GROUPS_COUNT must be a positive number (${Seastar_SCHEDULING_GROUPS_COUNT})")
87 # Add a dev build type.
89 # All pre-defined build modes include optimizations or debug info,
90 # which make them slow to build. The dev build mode is intended for
91 # fast build/test iteration.
94 if (CMAKE_CXX_COMPILER_ID MATCHES Clang)
95 set (CMAKE_CXX_FLAGS_DEV_OPT_LEVEL "-O2")
97 set (CMAKE_CXX_FLAGS_DEV_OPT_LEVEL "-O1")
100 set (CMAKE_CXX_FLAGS_DEV
101 "${CMAKE_CXX_FLAGS_DEV_OPT_LEVEL}"
104 "Flags used by the C++ compiler during dev builds."
107 set (CMAKE_C_FLAGS_DEV
111 "Flags used by the C compiler during dev builds."
114 set (CMAKE_EXE_LINKER_FLAGS_DEV
118 "Flags used for linking binaries during dev builds."
121 set (CMAKE_SHARED_LINKER_FLAGS_DEV
125 "Flags used by the shared libraries linker during builds."
131 CMAKE_EXE_LINKER_FLAGS_DEV
132 CMAKE_SHARED_LINKER_FLAGS_DEV)
134 set (CMAKE_CXX_FLAGS_SANITIZE
138 "Flags used by the C++ compiler during sanitize builds."
141 set (CMAKE_C_FLAGS_SANITIZE
145 "Flags used by the C compiler during sanitize builds."
148 set (CMAKE_EXE_LINKER_FLAGS_SANITIZE
152 "Flags used for linking binaries during sanitize builds."
155 set (CMAKE_SHARED_LINKER_FLAGS_SANITIZE
159 "Flags used by the shared libraries linker during sanitize builds."
163 CMAKE_CXX_FLAGS_SANITIZE
164 CMAKE_C_FLAGS_SANITIZE
165 CMAKE_EXE_LINKER_FLAGS_SANITIZE
166 CMAKE_SHARED_LINKER_FLAGS_SANITIZE)
168 set (CMAKE_BUILD_TYPE
169 "${CMAKE_BUILD_TYPE}"
172 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Dev Sanitize."
175 if (NOT CMAKE_BUILD_TYPE)
176 set (CMAKE_BUILD_TYPE "Release")
179 set (Seastar_ALLOC_PAGE_SIZE
183 "Override the Seastar allocator page size, in bytes.")
186 "Enable application targets."
189 set (Seastar_CXX_DIALECT
193 "Compile Seastar according to the named C++ standard.")
194 if (Seastar_CXX_DIALECT)
195 # extract CXX standard (14/17/...) from Seastar_CXX_DIALECT
196 string(SUBSTRING ${Seastar_CXX_DIALECT} 5 2 STANDARD)
197 set(CMAKE_CXX_STANDARD ${STANDARD})
198 set(CMAKE_CXX_STANDARD_REQUIRED ON)
201 set (Seastar_CXX_FLAGS
205 "Semicolon-separated list of extra compilation flags for Seastar itself.")
207 option (Seastar_DEMOS
208 "Enable demonstration targets."
212 "Enable documentation targets."
216 "Enable DPDK support."
219 option (Seastar_EXCLUDE_APPS_FROM_ALL
220 "When enabled alongside Seastar_APPS, do not build applications by default."
223 option (Seastar_EXCLUDE_DEMOS_FROM_ALL
224 "When enabled alongside Seastar_DEMOS, do not build demonstrations by default."
227 option (Seastar_EXCLUDE_TESTS_FROM_ALL
228 "When enabled alongside Seastar_TESTING, do not build tests by default."
231 option (Seastar_EXECUTE_ONLY_FAST_TESTS
232 "Only execute tests which run quickly."
235 option (Seastar_HWLOC
236 "Enable hwloc support."
243 "If non-empty, the prefix for XML files containing the results of running tests (for Jenkins).")
245 set (Seastar_LD_FLAGS
249 "Semicolon-separated list of extra linking flags for Seastar itself.")
251 option (Seastar_INSTALL
256 "Enable NUMA support."
259 option (Seastar_TESTING
260 "Enable testing targets."
263 option (Seastar_COMPRESS_DEBUG
264 "Compress debug info."
267 option (Seastar_SPLIT_DWARF
271 option (Seastar_HEAP_PROFILING
272 "Enable heap profiling. No effect when Seastar is compiled with the default allocator."
275 option (Seastar_DEFERRED_ACTION_REQUIRE_NOEXCEPT
276 "Enable noexcept requirement for deferred actions."
279 set (Seastar_TEST_TIMEOUT
283 "Maximum allowed time for a test to run, in seconds.")
285 # We set the following environment variables
286 # * ASAN_OPTIONS=disable_coredump=0:abort_on_error=1:detect_stack_use_after_return=1
287 # By default asan disables core dumps because they used to be
288 # huge. This is no longer the case since the shadow memory is
289 # excluded, so it is safe to enable them.
290 # * UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1
291 # Fail the test if any undefined behavior is found and use abort
292 # instead of exit. Using abort is what causes core dumps to be
294 # * BOOST_TEST_CATCH_SYSTEM_ERRORS=no
295 # Normally the boost test library handles SIGABRT and prevents core
296 # dumps from being produced.
298 # This works great with clang and gcc 10.2, but unfortunately not any
300 set (Seastar_USE_AFTER_RETURN "")
301 if ((NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")) OR
302 (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.2))
303 set (Seastar_USE_AFTER_RETURN ":detect_stack_use_after_return=1")
306 set (Seastar_TEST_ENVIRONMENT
307 "ASAN_OPTIONS=disable_coredump=0:abort_on_error=1${Seastar_USE_AFTER_RETURN};UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1;BOOST_TEST_CATCH_SYSTEM_ERRORS=no"
310 "Environment variables for running tests")
312 option (Seastar_UNUSED_RESULT_ERROR
313 "Make [[nodiscard]] violations an error (instead of a warning)."
316 set (Seastar_STACK_GUARDS
320 "Enable stack guards. Can be ON, OFF or DEFAULT (which enables it for non release builds)")
322 set (Seastar_SANITIZE
326 "Enable ASAN and UBSAN. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")
328 set (Seastar_DEBUG_SHARED_PTR
332 "Enable shared_ptr debugging. Can be ON, OFF or DEFAULT (which enables it for Debug and Sanitize)")
334 # When Seastar is embedded with `add_subdirectory`, disable the non-library targets.
335 if (NOT (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR))
336 set (Seastar_APPS OFF)
337 set (Seastar_DEMOS OFF)
338 set (Seastar_DOCS OFF)
339 set (Seastar_INSTALL OFF)
340 set (Seastar_TESTING OFF)
344 # Useful (non-cache) variables.
347 set (Seastar_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
348 set (Seastar_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
349 set (Seastar_GEN_BINARY_DIR ${Seastar_BINARY_DIR}/gen)
355 include (SeastarDependencies)
356 seastar_find_dependencies ()
358 # Private build dependencies not visible to consumers
359 find_package (ragel 6.10 REQUIRED)
360 find_package (Threads REQUIRED)
361 find_package (PthreadSetName REQUIRED)
364 # Code generation helpers.
367 function (seastar_generate_ragel)
368 set (one_value_args TARGET VAR IN_FILE OUT_FILE)
369 cmake_parse_arguments (args "" "${one_value_args}" "" ${ARGN})
370 get_filename_component (out_dir ${args_OUT_FILE} DIRECTORY)
373 DEPENDS ${args_IN_FILE}
374 OUTPUT ${args_OUT_FILE}
375 COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir}
376 COMMAND ${ragel_RAGEL_EXECUTABLE} -G2 -o ${args_OUT_FILE} ${args_IN_FILE}
377 COMMAND sed -i -e "'1h;2,$$H;$$!d;g'" -re "'s/static const char _nfa[^;]*;//g'" ${args_OUT_FILE})
379 add_custom_target (${args_TARGET}
380 DEPENDS ${args_OUT_FILE})
382 set (${args_VAR} ${args_OUT_FILE} PARENT_SCOPE)
385 function (seastar_generate_swagger)
386 set (one_value_args TARGET VAR IN_FILE OUT_DIR)
387 cmake_parse_arguments (args "" "${one_value_args}" "" ${ARGN})
388 get_filename_component (in_file_name ${args_IN_FILE} NAME)
389 set (generator ${Seastar_SOURCE_DIR}/scripts/seastar-json2code.py)
390 set (header_out ${args_OUT_DIR}/${in_file_name}.hh)
391 set (source_out ${args_OUT_DIR}/${in_file_name}.cc)
397 OUTPUT ${header_out} ${source_out}
398 COMMAND ${CMAKE_COMMAND} -E make_directory ${args_OUT_DIR}
399 COMMAND ${generator} --create-cc -f ${args_IN_FILE} -o ${header_out})
401 add_custom_target (${args_TARGET}
406 set (${args_VAR} ${header_out} ${source_out} PARENT_SCOPE)
410 # The `seastar` library.
413 seastar_generate_ragel (
414 TARGET seastar_http_chunk_parsers
415 VAR http_chunk_parsers_file
416 IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/http/chunk_parsers.rl
417 OUT_FILE ${Seastar_GEN_BINARY_DIR}/include/seastar/http/chunk_parsers.hh)
419 seastar_generate_ragel (
420 TARGET seastar_http_request_parser
421 VAR http_request_parser_file
422 IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/http/request_parser.rl
423 OUT_FILE ${Seastar_GEN_BINARY_DIR}/include/seastar/http/request_parser.hh)
425 seastar_generate_ragel (
426 TARGET seastar_http_response_parser
427 VAR http_response_parser_file
428 IN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/http/response_parser.rl
429 OUT_FILE ${Seastar_GEN_BINARY_DIR}/include/seastar/http/response_parser.hh)
432 set (seastar_dpdk_obj seastar-dpdk.o)
435 add_library (seastar STATIC
436 ${http_chunk_parsers_file}
437 ${http_request_parser_file}
439 include/seastar/core/abort_source.hh
440 include/seastar/core/alien.hh
441 include/seastar/core/align.hh
442 include/seastar/core/aligned_buffer.hh
443 include/seastar/core/app-template.hh
444 include/seastar/core/array_map.hh
445 include/seastar/core/bitops.hh
446 include/seastar/core/bitset-iter.hh
447 include/seastar/core/byteorder.hh
448 include/seastar/core/cacheline.hh
449 include/seastar/core/checked_ptr.hh
450 include/seastar/core/chunked_fifo.hh
451 include/seastar/core/circular_buffer.hh
452 include/seastar/core/circular_buffer_fixed_capacity.hh
453 include/seastar/core/condition-variable.hh
454 include/seastar/core/deleter.hh
455 include/seastar/core/distributed.hh
456 include/seastar/core/do_with.hh
457 include/seastar/core/dpdk_rte.hh
458 include/seastar/core/enum.hh
459 include/seastar/core/exception_hacks.hh
460 include/seastar/core/execution_stage.hh
461 include/seastar/core/expiring_fifo.hh
462 include/seastar/core/fair_queue.hh
463 include/seastar/core/file.hh
464 include/seastar/core/file-types.hh
465 include/seastar/core/fsqual.hh
466 include/seastar/core/fstream.hh
467 include/seastar/core/function_traits.hh
468 include/seastar/core/future-util.hh
469 include/seastar/core/future.hh
470 include/seastar/core/gate.hh
471 include/seastar/core/iostream-impl.hh
472 include/seastar/core/iostream.hh
473 include/seastar/util/later.hh
474 include/seastar/core/layered_file.hh
475 include/seastar/core/linux-aio.hh
476 include/seastar/core/loop.hh
477 include/seastar/core/lowres_clock.hh
478 include/seastar/core/manual_clock.hh
479 include/seastar/core/map_reduce.hh
480 include/seastar/core/memory.hh
481 include/seastar/core/metrics.hh
482 include/seastar/core/metrics_api.hh
483 include/seastar/core/metrics_registration.hh
484 include/seastar/core/metrics_types.hh
485 include/seastar/core/pipe.hh
486 include/seastar/core/posix.hh
487 include/seastar/core/preempt.hh
488 include/seastar/core/prefetch.hh
489 include/seastar/core/print.hh
490 include/seastar/core/prometheus.hh
491 include/seastar/core/queue.hh
492 include/seastar/core/ragel.hh
493 include/seastar/core/reactor.hh
494 include/seastar/core/report_exception.hh
495 include/seastar/core/resource.hh
496 include/seastar/core/rwlock.hh
497 include/seastar/core/scattered_message.hh
498 include/seastar/core/scheduling.hh
499 include/seastar/core/scollectd.hh
500 include/seastar/core/scollectd_api.hh
501 include/seastar/core/seastar.hh
502 include/seastar/core/semaphore.hh
503 include/seastar/core/sharded.hh
504 include/seastar/core/shared_future.hh
505 include/seastar/core/shared_mutex.hh
506 include/seastar/core/shared_ptr.hh
507 include/seastar/core/shared_ptr_debug_helper.hh
508 include/seastar/core/shared_ptr_incomplete.hh
509 include/seastar/core/simple-stream.hh
510 include/seastar/core/slab.hh
511 include/seastar/core/sleep.hh
512 include/seastar/core/sstring.hh
513 include/seastar/core/stall_sampler.hh
514 include/seastar/core/stream.hh
515 include/seastar/core/systemwide_memory_barrier.hh
516 include/seastar/core/task.hh
517 include/seastar/core/temporary_buffer.hh
518 include/seastar/core/thread.hh
519 include/seastar/core/thread_cputime_clock.hh
520 include/seastar/core/thread_impl.hh
521 include/seastar/core/timed_out_error.hh
522 include/seastar/core/timer-set.hh
523 include/seastar/core/timer.hh
524 include/seastar/core/transfer.hh
525 include/seastar/core/unaligned.hh
526 include/seastar/core/units.hh
527 include/seastar/core/vector-data-sink.hh
528 include/seastar/core/weak_ptr.hh
529 include/seastar/core/when_all.hh
530 include/seastar/core/with_scheduling_group.hh
531 include/seastar/core/with_timeout.hh
532 include/seastar/http/api_docs.hh
533 include/seastar/http/common.hh
534 include/seastar/http/exception.hh
535 include/seastar/http/file_handler.hh
536 include/seastar/http/function_handlers.hh
537 include/seastar/http/handlers.hh
538 include/seastar/http/httpd.hh
539 include/seastar/http/json_path.hh
540 include/seastar/http/matcher.hh
541 include/seastar/http/matchrules.hh
542 include/seastar/http/mime_types.hh
543 include/seastar/http/reply.hh
544 include/seastar/http/request.hh
545 include/seastar/http/routes.hh
546 include/seastar/http/short_streams.hh
547 include/seastar/http/transformers.hh
548 include/seastar/json/formatter.hh
549 include/seastar/json/json_elements.hh
550 include/seastar/net/api.hh
551 include/seastar/net/arp.hh
552 include/seastar/net/byteorder.hh
553 include/seastar/net/config.hh
554 include/seastar/net/const.hh
555 include/seastar/net/dhcp.hh
556 include/seastar/net/dns.hh
557 include/seastar/net/dpdk.hh
558 include/seastar/net/ethernet.hh
559 include/seastar/net/inet_address.hh
560 include/seastar/net/ip.hh
561 include/seastar/net/ip_checksum.hh
562 include/seastar/net/native-stack.hh
563 include/seastar/net/net.hh
564 include/seastar/net/packet-data-source.hh
565 include/seastar/net/packet-util.hh
566 include/seastar/net/packet.hh
567 include/seastar/net/posix-stack.hh
568 include/seastar/net/proxy.hh
569 include/seastar/net/socket_defs.hh
570 include/seastar/net/stack.hh
571 include/seastar/net/tcp-stack.hh
572 include/seastar/net/tcp.hh
573 include/seastar/net/tls.hh
574 include/seastar/net/toeplitz.hh
575 include/seastar/net/udp.hh
576 include/seastar/net/unix_address.hh
577 include/seastar/net/virtio-interface.hh
578 include/seastar/net/virtio.hh
579 include/seastar/rpc/lz4_compressor.hh
580 include/seastar/rpc/lz4_fragmented_compressor.hh
581 include/seastar/rpc/multi_algo_compressor_factory.hh
582 include/seastar/rpc/rpc.hh
583 include/seastar/rpc/rpc_impl.hh
584 include/seastar/rpc/rpc_types.hh
585 include/seastar/util/alloc_failure_injector.hh
586 include/seastar/util/backtrace.hh
587 include/seastar/util/concepts.hh
588 include/seastar/util/bool_class.hh
589 include/seastar/util/conversions.hh
590 include/seastar/util/defer.hh
591 include/seastar/util/eclipse.hh
592 include/seastar/util/function_input_iterator.hh
593 include/seastar/util/gcc6-concepts.hh
594 include/seastar/util/indirect.hh
595 include/seastar/util/is_smart_ptr.hh
596 include/seastar/util/lazy.hh
597 include/seastar/util/log-cli.hh
598 include/seastar/util/log-impl.hh
599 include/seastar/util/log.hh
600 include/seastar/util/noncopyable_function.hh
601 include/seastar/util/optimized_optional.hh
602 include/seastar/util/print_safe.hh
603 include/seastar/util/program-options.hh
604 include/seastar/util/read_first_line.hh
605 include/seastar/util/reference_wrapper.hh
606 include/seastar/util/spinlock.hh
607 include/seastar/util/std-compat.hh
608 include/seastar/util/transform_iterator.hh
609 include/seastar/util/tuple_utils.hh
610 include/seastar/util/variant_utils.hh
611 include/seastar/util/closeable.hh
612 include/seastar/util/source_location-compat.hh
613 include/seastar/util/short_streams.hh
614 include/seastar/websocket/server.hh
617 src/core/fair_queue.cc
618 src/core/reactor_backend.cc
619 src/core/thread_pool.cc
620 src/core/app-template.cc
622 src/core/exception_hacks.cc
623 src/core/execution_stage.cc
624 src/core/file-impl.hh
629 src/core/future-util.cc
630 src/core/linux-aio.cc
633 src/core/on_internal_error.cc
635 src/core/prometheus.cc
636 src/core/program_options.cc
640 src/core/scollectd.cc
641 src/core/scollectd-impl.hh
642 src/core/systemwide_memory_barrier.cc
649 src/core/semaphore.cc
650 src/core/condition-variable.cc
653 src/http/file_handler.cc
655 src/http/json_path.cc
657 src/http/mime_types.cc
660 src/http/transformers.cc
661 src/json/formatter.cc
662 src/json/json_elements.cc
669 src/net/inet_address.cc
671 src/net/ip_checksum.cc
672 src/net/native-stack-impl.hh
673 src/net/native-stack.cc
676 src/net/posix-stack.cc
678 src/net/socket_address.cc
683 src/net/unix_address.cc
685 src/rpc/lz4_compressor.cc
686 src/rpc/lz4_fragmented_compressor.cc
688 src/util/alloc_failure_injector.cc
689 src/util/backtrace.cc
690 src/util/conversions.cc
691 src/util/exceptions.cc
694 src/util/program-options.cc
695 src/util/read_first_line.cc
697 src/util/short_streams.cc
698 src/websocket/server.cc
701 add_library (Seastar::seastar ALIAS seastar)
703 add_dependencies (seastar
704 seastar_http_chunk_parsers
705 seastar_http_request_parser
706 seastar_http_response_parser)
708 target_include_directories (seastar
710 $<INSTALL_INTERFACE:include>
711 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
712 $<BUILD_INTERFACE:${Seastar_GEN_BINARY_DIR}/include>
714 ${CMAKE_CURRENT_SOURCE_DIR}/src
715 ${Seastar_GEN_BINARY_DIR}/src)
717 set (Seastar_PRIVATE_CXX_FLAGS
722 -Wno-array-bounds # Disabled because of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93437
723 -Wno-error=deprecated-declarations)
725 if (Seastar_COMPRESS_DEBUG)
726 # -gz doesn't imply -g, so it is safe to add it regardless of debug
727 # info being enabled.
728 list (APPEND Seastar_PRIVATE_CXX_FLAGS -gz)
731 target_link_libraries (seastar
734 Boost::program_options
744 lksctp-tools::lksctp-tools
749 set (Seastar_SANITIZE_MODES "Debug" "Sanitize")
750 if ((Seastar_SANITIZE STREQUAL "ON") OR
751 ((Seastar_SANITIZE STREQUAL "DEFAULT") AND
752 (CMAKE_BUILD_TYPE IN_LIST Seastar_SANITIZE_MODES)))
753 if (NOT Sanitizers_FOUND)
754 message (FATAL_ERROR "Sanitizers not found!")
756 set (Seastar_Sanitizers_OPTIONS ${Sanitizers_COMPILER_OPTIONS})
757 target_link_libraries (seastar
760 Sanitizers::undefined_behavior)
763 # We only need valgrind to find uninitialized memory uses, so disable
764 # the leak sanitizer.
765 # To test with valgrind run "ctest -T memcheck"
766 set( MEMORYCHECK_COMMAND_OPTIONS "--error-exitcode=1 --leak-check=no --trace-children=yes" )
770 # We want asserts enabled on all modes, but cmake defaults to passing
771 # -DNDEBUG in some modes. We add -UNDEBUG to our private options to
772 # reenable it. To force asserts off pass -DNDEBUG in
775 # To disable -Werror, pass -Wno-error to Seastar_CXX_FLAGS.
777 # We disable _FORTIFY_SOURCE because it generates false positives with longjmp() (src/core/thread.cc)
780 target_compile_options (seastar
782 $<$<COMPILE_LANGUAGE:CXX>:-std=${Seastar_CXX_DIALECT}>
785 target_compile_definitions(seastar
787 SEASTAR_API_LEVEL=${Seastar_API_LEVEL})
789 function (seastar_supports_flag flag var)
790 set (CMAKE_REQUIRED_FLAGS "${flag}")
791 check_cxx_source_compiles ("int main() { return 0; }" tmp_${var})
792 set (${var} ${tmp_${var}} PARENT_SCOPE)
795 seastar_supports_flag ("-Wno-maybe-uninitialized -Werror" MaybeUninitialized_FOUND)
796 if (MaybeUninitialized_FOUND)
797 target_compile_options (seastar
799 # With std::experimental::optional it is easy to hit
800 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88897. We disable
801 # -Wmaybe-uninitialized in here since otherwise we would have to
802 # disable it on many types used inside optional<>.
803 -Wno-maybe-uninitialized)
807 target_compile_options (seastar PUBLIC -DSEASTAR_SSTRING)
810 if (LinuxMembarrier_FOUND)
811 list (APPEND Seastar_PRIVATE_COMPILE_DEFINITIONS SEASTAR_HAS_MEMBARRIER)
813 target_link_libraries (seastar
814 PRIVATE LinuxMembarrier::membarrier)
817 set (Seastar_ALLOC_FAILURE_INJECTION_MODES "Dev")
818 if ((Seastar_ALLOC_FAILURE_INJECTION IN_LIST True_STRING_VALUES) OR
819 ((Seastar_ALLOC_FAILURE_INJECTION STREQUAL "DEFAULT") AND
820 (CMAKE_BUILD_TYPE IN_LIST Seastar_ALLOC_FAILURE_INJECTION_MODES)))
821 target_compile_definitions (seastar
822 PUBLIC SEASTAR_ENABLE_ALLOC_FAILURE_INJECTION)
825 if (Seastar_TASK_BACKTRACE)
826 target_compile_definitions (seastar
827 PUBLIC SEASTAR_TASK_BACKTRACE)
830 if (Seastar_DEBUG_ALLOCATIONS)
831 target_compile_definitions (seastar
832 PRIVATE SEASTAR_DEBUG_ALLOCATIONS)
835 if (Sanitizers_FIBER_SUPPORT)
836 list (APPEND Seastar_PRIVATE_COMPILE_DEFINITIONS SEASTAR_HAVE_ASAN_FIBER_SUPPORT)
839 if (Seastar_ALLOC_PAGE_SIZE)
840 target_compile_definitions (seastar
841 PUBLIC SEASTAR_OVERRIDE_ALLOCATOR_PAGE_SIZE=${Seastar_ALLOC_PAGE_SIZE})
844 target_compile_definitions (seastar
845 PUBLIC SEASTAR_SCHEDULING_GROUPS_COUNT=${Seastar_SCHEDULING_GROUPS_COUNT})
847 if (Seastar_CXX_FLAGS)
848 list (APPEND Seastar_PRIVATE_CXX_FLAGS ${Seastar_CXX_FLAGS})
851 # When using split dwarf --gdb-index is effectively required since
852 # otherwise gdb is just too slow. We also want to use split dwarf in
853 # as many compilation units as possible. So while these flags don't
854 # have to be public, we don't expect anyone to want to build seastar
855 # with them and some client code without.
856 if (Seastar_SPLIT_DWARF AND (NOT (CMAKE_BUILD_TYPE STREQUAL "Dev")))
857 set (Seastar_SPLIT_DWARF_FLAG "-Wl,--gdb-index")
858 target_link_libraries (seastar PUBLIC ${Seastar_SPLIT_DWARF_FLAG})
859 target_compile_options (seastar PUBLIC "-gsplit-dwarf")
862 if (Seastar_HEAP_PROFILING)
864 SOURCE "src/core/memory.cc"
866 COMPILE_DEFINITIONS SEASTAR_HEAPPROF)
869 if (Seastar_DEFERRED_ACTION_REQUIRE_NOEXCEPT)
870 list (APPEND Seastar_PRIVATE_COMPILE_DEFINITIONS SEASTAR_DEFERRED_ACTION_REQUIRE_NOEXCEPT)
875 message (FATAL_ERROR "dpdk support is enabled but it is not available!")
879 # The DPDK architecture needs to be transitively applied to consumers of Seastar as well.
882 set (Seastar_ARCH_FOR_native "native")
883 set (Seastar_ARCH_FOR_nhm "nehalem")
884 set (Seastar_ARCH_FOR_wsm "westmere")
885 set (Seastar_ARCH_FOR_snb "sandybridge")
886 set (Seastar_ARCH_FOR_ivb "ivybridge")
887 set (Seastar_ARCH_FOR_armv8a "armv8-a")
888 set (Seastar_ARCH ${Seastar_ARCH_FOR_${Seastar_DPDK_MACHINE}})
890 if (NOT Seastar_ARCH)
891 message (FATAL_ERROR "Unrecognized DPDK machine identifier: ${Seastar_DPDK_MACHINE}")
894 target_compile_options (seastar
895 PUBLIC -march=${Seastar_ARCH})
897 target_compile_definitions (seastar
898 PUBLIC SEASTAR_HAVE_DPDK)
900 # No pmd driver code will be pulled in without "--whole-archive". To
901 # avoid exposing that to seastar users, combine dpdk into a single
904 OUTPUT seastar-dpdk.o
905 COMMAND ld -r -o seastar-dpdk.o --whole-archive ${dpdk_LIBRARIES} --no-whole-archive
908 # This just provides the include path to cmake
909 target_link_libraries (seastar
915 message (FATAL_ERROR "`hwloc` support is enabled but it is not available!")
918 list (APPEND Seastar_PRIVATE_COMPILE_DEFINITIONS SEASTAR_HAVE_HWLOC)
920 target_link_libraries (seastar
921 PRIVATE hwloc::hwloc)
924 if (Seastar_LD_FLAGS)
925 # In newer versions of CMake, there is `target_link_options`.
926 target_link_libraries (seastar
927 PRIVATE ${Seastar_LD_FLAGS})
931 if (NOT numactl_FOUND)
932 message (FATAL_ERROR "NUMA support is enabled but `numactl` is not available!")
935 list (APPEND Seastar_PRIVATE_COMPILE_DEFINITIONS SEASTAR_HAVE_NUMA)
937 target_link_libraries (seastar
938 PRIVATE numactl::numactl)
941 if (lz4_HAVE_COMPRESS_DEFAULT)
942 list (APPEND Seastar_PRIVATE_COMPILE_DEFINITIONS SEASTAR_HAVE_LZ4_COMPRESS_DEFAULT)
945 seastar_supports_flag ("-Werror=unused-result" ErrorUnused_FOUND)
946 if (ErrorUnused_FOUND)
947 if (Seastar_UNUSED_RESULT_ERROR)
948 target_compile_options (seastar
949 PUBLIC -Werror=unused-result)
951 target_compile_options (seastar
952 PUBLIC -Wno-error=unused-result)
956 seastar_supports_flag ("-Wno-error=#warnings" ErrorWarnings_FOUND)
957 if (ErrorWarnings_FOUND)
958 target_compile_options (seastar
959 PUBLIC "-Wno-error=#warnings")
962 if ((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (CMAKE_BUILD_TYPE STREQUAL "Sanitize"))
963 target_compile_definitions (seastar
966 SEASTAR_DEFAULT_ALLOCATOR
967 SEASTAR_SHUFFLE_TASK_QUEUE)
970 set (Seastar_DEBUG_SHARED_PTR_MODES "Debug" "Sanitize")
971 if (Seastar_DEBUG_SHARED_PTR IN_LIST True_STRING_VALUES OR
972 ((Seastar_DEBUG_SHARED_PTR IN_LIST Default_STRING_VALUES) AND
973 (CMAKE_BUILD_TYPE IN_LIST Seastar_DEBUG_SHARED_PTR_MODES)))
974 target_compile_definitions (seastar
976 SEASTAR_DEBUG_SHARED_PTR)
979 set (Seastar_STACK_GUARD_MODES "Debug" "Sanitize" "Dev")
980 if ((Seastar_STACK_GUARDS STREQUAL "ON") OR
981 ((Seastar_STACK_GUARDS STREQUAL "DEFAULT") AND
982 (CMAKE_BUILD_TYPE IN_LIST Seastar_STACK_GUARD_MODES)))
983 # check for -fstack-clash-protection together with -Werror, because
984 # otherwise clang can soft-fail (return 0 but emit a warning) instead.
985 seastar_supports_flag ("-fstack-clash-protection -Werror" StackClashProtection_FOUND)
986 if (StackClashProtection_FOUND)
987 target_compile_options (seastar
989 -fstack-clash-protection)
991 target_compile_definitions (seastar
993 SEASTAR_THREAD_STACK_GUARDS)
996 if ((CMAKE_BUILD_TYPE STREQUAL "Dev") OR (CMAKE_BUILD_TYPE STREQUAL "Debug"))
997 target_compile_definitions (seastar
999 SEASTAR_TYPE_ERASE_MORE)
1002 target_compile_definitions (seastar
1003 PRIVATE ${Seastar_PRIVATE_COMPILE_DEFINITIONS})
1005 target_compile_options (seastar
1006 PRIVATE ${Seastar_PRIVATE_CXX_FLAGS})
1008 add_library (seastar_private INTERFACE)
1010 target_compile_definitions (seastar_private
1011 INTERFACE ${Seastar_PRIVATE_COMPILE_DEFINITIONS})
1013 target_compile_options (seastar_private
1014 INTERFACE ${Seastar_PRIVATE_CXX_FLAGS})
1016 target_link_libraries (seastar_private
1020 # The testing library.
1023 if (Seastar_INSTALL OR Seastar_TESTING)
1024 add_library (seastar_testing
1025 include/seastar/testing/entry_point.hh
1026 include/seastar/testing/exchanger.hh
1027 include/seastar/testing/random.hh
1028 include/seastar/testing/seastar_test.hh
1029 include/seastar/testing/test_case.hh
1030 include/seastar/testing/test_runner.hh
1031 include/seastar/testing/thread_test_case.hh
1032 src/testing/entry_point.cc
1033 src/testing/random.cc
1034 src/testing/seastar_test.cc
1035 src/testing/test_runner.cc)
1037 add_library (Seastar::seastar_testing ALIAS seastar_testing)
1039 target_compile_definitions (seastar_testing
1040 PUBLIC BOOST_TEST_DYN_LINK
1041 PRIVATE ${Seastar_PRIVATE_COMPILE_DEFINITIONS})
1043 target_compile_options (seastar_testing
1044 PRIVATE ${Seastar_PRIVATE_CXX_FLAGS})
1046 target_link_libraries (seastar_testing
1048 Boost::unit_test_framework
1051 add_library(seastar_perf_testing
1052 src/testing/random.cc
1053 include/seastar/testing/perf_tests.hh
1054 tests/perf/perf_tests.cc)
1055 add_library (Seastar::seastar_perf_testing ALIAS seastar_perf_testing)
1056 target_compile_definitions (seastar_perf_testing
1057 PRIVATE ${Seastar_PRIVATE_COMPILE_DEFINITIONS})
1058 target_compile_options (seastar_perf_testing
1059 PRIVATE ${Seastar_PRIVATE_CXX_FLAGS})
1060 target_link_libraries (seastar_perf_testing
1067 # The tests themselves.
1070 if (Seastar_TESTING)
1073 if (Seastar_EXCLUDE_TESTS_FROM_ALL)
1074 set (exclude EXCLUDE_FROM_ALL)
1079 add_subdirectory (tests ${exclude})
1087 if (Seastar_EXCLUDE_DEMOS_FROM_ALL)
1088 set (exclude EXCLUDE_FROM_ALL)
1093 add_subdirectory (demos ${exclude})
1101 add_subdirectory (doc)
1109 if (Seastar_EXCLUDE_APPS_FROM_ALL)
1110 set (exclude EXCLUDE_FROM_ALL)
1115 add_subdirectory (apps ${exclude})
1119 # Installation and export.
1122 if (Seastar_INSTALL)
1124 # pkg-config generation.
1126 # Note that unlike the CMake "config module", this description is not relocatable because
1127 # some dependencies do not natively support pkg-config.
1130 # Necessary here for pkg-config.
1131 include (GNUInstallDirs)
1133 # Set paths in pkg-config files for installation.
1134 set (Seastar_PKG_CONFIG_PREFIX ${CMAKE_INSTALL_PREFIX})
1135 set (Seastar_PKG_CONFIG_LIBDIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
1136 set (Seastar_PKG_CONFIG_SEASTAR_INCLUDE_FLAGS "-I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
1139 ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/seastar.pc.in
1140 ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar-install.pc.in
1144 ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/seastar-testing.pc.in
1145 ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar-testing-install.pc.in
1148 # Set paths in pkg-config files for direct use in the build directory.
1149 set (Seastar_PKG_CONFIG_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
1150 set (Seastar_PKG_CONFIG_LIBDIR ${CMAKE_CURRENT_BINARY_DIR})
1151 set (Seastar_PKG_CONFIG_SEASTAR_INCLUDE_FLAGS "-I${CMAKE_CURRENT_SOURCE_DIR}/include -I${CMAKE_CURRENT_BINARY_DIR}/gen/include")
1154 ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/seastar.pc.in
1155 ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar.pc.in
1159 ${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig/seastar-testing.pc.in
1160 ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar-testing.pc.in
1164 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/seastar.pc
1165 INPUT ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar.pc.in)
1168 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/seastar-testing.pc
1169 INPUT ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar-testing.pc.in)
1172 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/seastar-install.pc
1173 INPUT ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar-install.pc.in)
1176 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/seastar-testing-install.pc
1177 INPUT ${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/seastar-testing-install.pc.in)
1179 include (CMakePackageConfigHelpers)
1180 set (install_cmakedir ${CMAKE_INSTALL_LIBDIR}/cmake/Seastar)
1183 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/
1184 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1187 DIRECTORY ${Seastar_GEN_BINARY_DIR}/include/
1188 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
1191 PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/seastar-json2code.py
1192 DESTINATION ${CMAKE_INSTALL_BINDIR})
1198 seastar_perf_testing
1199 EXPORT seastar-export
1200 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
1201 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
1204 EXPORT seastar-export
1205 FILE SeastarTargets.cmake
1207 DESTINATION ${install_cmakedir})
1209 write_basic_package_version_file (
1210 ${CMAKE_CURRENT_BINARY_DIR}/SeastarConfigVersion.cmake
1211 VERSION ${PROJECT_VERSION}
1212 COMPATIBILITY ExactVersion)
1214 configure_package_config_file (
1215 ${CMAKE_CURRENT_LIST_DIR}/cmake/SeastarConfig.cmake.in
1216 ${CMAKE_CURRENT_BINARY_DIR}/SeastarConfig.cmake
1217 INSTALL_DESTINATION ${install_cmakedir})
1221 ${CMAKE_CURRENT_BINARY_DIR}/SeastarConfig.cmake
1222 ${CMAKE_CURRENT_BINARY_DIR}/SeastarConfigVersion.cmake
1223 DESTINATION ${install_cmakedir})
1227 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindConcepts.cmake
1228 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGnuTLS.cmake
1229 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLinuxMembarrier.cmake
1230 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindSanitizers.cmake
1231 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindStdAtomic.cmake
1232 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findc-ares.cmake
1233 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findcryptopp.cmake
1234 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Finddpdk.cmake
1235 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findhwloc.cmake
1236 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findlksctp-tools.cmake
1237 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findlz4.cmake
1238 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findnumactl.cmake
1239 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findragel.cmake
1240 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findrt.cmake
1241 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findyaml-cpp.cmake
1242 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/SeastarDependencies.cmake
1243 DESTINATION ${install_cmakedir})
1246 DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake/code_tests
1247 DESTINATION ${install_cmakedir})
1250 FILES ${CMAKE_CURRENT_BINARY_DIR}/seastar-install.pc
1251 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
1255 FILES ${CMAKE_CURRENT_BINARY_DIR}/seastar-testing-install.pc
1256 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
1257 RENAME seastar-testing.pc)
1260 # Export targets from the build tree for the user package registry.
1264 EXPORT seastar-export
1265 FILE ${CMAKE_CURRENT_BINARY_DIR}/SeastarTargets.cmake
1266 NAMESPACE Seastar::)
1268 export (PACKAGE Seastar)
1274 set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
1275 set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
1276 set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})