Merge 'build: cmake: sync with configure (2/n)' from Kefu Chai

* build: cmake: extract idl out
* build: cmake: link cql3 against xxHash
* build: cmake: correct the check in Findlibdeflate.cmake
* build: cmake find_package(libdeflate) earlier
* build: cmake: set more properties to alternator library
* build: cmake: include generate_cql_grammar
* build: cmake: find xxHash package
* build: cmake: add build mode support

Closes #12866

* github.com:scylladb/scylladb:
  build: cmake: correct generate_cql_grammar
  build: cmake: extract idl out
  build: cmake: link cql3 against xxHash
  build: cmake: correct the check in Findlibdeflate.cmake
  build: cmake: find_package(libdeflate) earlier
  build: cmake: set more properties to alternator library
  build: cmake: include generate_cql_grammar
  build: cmake: find xxHash package
  build: cmake: add build mode support
This commit is contained in:
Botond Dénes
2023-02-16 07:11:26 +02:00
11 changed files with 239 additions and 127 deletions

View File

@@ -5,44 +5,18 @@ project(scylla)
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE "Release" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "Dev" "Sanitize")
endif()
if(CMAKE_BUILD_TYPE)
string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
else()
set(BUILD_TYPE "release")
endif()
function(default_target_arch arch)
set(x86_instruction_sets i386 i686 x86_64)
if(CMAKE_SYSTEM_PROCESSOR IN_LIST x86_instruction_sets)
set(${arch} "westmere" PARENT_SCOPE)
elseif(CMAKE_SYSTEM_PROCESSOR EQUAL "aarch64")
set(${arch} "armv8-a+crc+crypto" PARENT_SCOPE)
else()
set(${arch} "" PARENT_SCOPE)
endif()
endfunction()
default_target_arch(target_arch)
if(target_arch)
set(target_arch_flag "-march=${target_arch}")
endif()
set(cxx_coro_flag)
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
set(cxx_coro_flag -fcoroutines)
endif()
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "Dev" "Sanitize")
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_mode)
include("mode.common")
include("mode.${build_mode}")
add_compile_definitions(${Seastar_DEFINITIONS_${build_mode}})
# Configure Seastar compile options to align with Scylla
set(Seastar_CXX_FLAGS ${cxx_coro_flag} ${target_arch_flag} CACHE INTERNAL "" FORCE)
set(Seastar_CXX_DIALECT gnu++20 CACHE INTERNAL "" FORCE)
set(CMAKE_CXX_STANDARD "20" CACHE INTERNAL "")
set(CMAKE_CXX_EXTENSIONS ON CACHE INTERNAL "")
add_subdirectory(seastar)
@@ -52,15 +26,11 @@ find_package(Lua REQUIRED)
find_package(ZLIB REQUIRED)
find_package(ICU COMPONENTS uc REQUIRED)
find_package(absl REQUIRED)
find_package(libdeflate REQUIRED)
find_package(xxHash REQUIRED)
set(scylla_build_dir "${CMAKE_BINARY_DIR}/build/${BUILD_TYPE}")
set(scylla_gen_build_dir "${scylla_build_dir}/gen")
file(MAKE_DIRECTORY "${scylla_build_dir}" "${scylla_gen_build_dir}")
# Place libraries, executables and archives in ${buildroot}/build/${mode}/
foreach(mode RUNTIME LIBRARY ARCHIVE)
set(CMAKE_${mode}_OUTPUT_DIRECTORY "${scylla_build_dir}")
endforeach()
set(scylla_gen_build_dir "${CMAKE_BINARY_DIR}/gen")
file(MAKE_DIRECTORY "${scylla_gen_build_dir}")
# Generate C++ source files from thrift definitions
function(scylla_generate_thrift)
@@ -143,74 +113,6 @@ foreach(f ${swagger_files})
list(APPEND swagger_gen_files "${scylla_swagger_gen_${fname}_files}")
endforeach()
# Create C++ bindings for IDL serializers
function(scylla_generate_idl_serializer)
set(one_value_args TARGET VAR IN_FILE OUT_FILE)
cmake_parse_arguments(args "" "${one_value_args}" "" ${ARGN})
get_filename_component(out_dir ${args_OUT_FILE} DIRECTORY)
set(idl_compiler "${CMAKE_SOURCE_DIR}/idl-compiler.py")
find_package(Python3 COMPONENTS Interpreter)
add_custom_command(
DEPENDS
${args_IN_FILE}
${idl_compiler}
OUTPUT ${args_OUT_FILE}
COMMAND ${CMAKE_COMMAND} -E make_directory ${out_dir}
COMMAND Python3::Interpreter ${idl_compiler} --ns ser -f ${args_IN_FILE} -o ${args_OUT_FILE})
add_custom_target(${args_TARGET}
DEPENDS ${args_OUT_FILE})
set(${args_VAR} ${args_OUT_FILE} PARENT_SCOPE)
endfunction()
set(idl_serializers
idl/cache_temperature.idl.hh
idl/commitlog.idl.hh
idl/consistency_level.idl.hh
idl/frozen_mutation.idl.hh
idl/frozen_schema.idl.hh
idl/gossip_digest.idl.hh
idl/hinted_handoff.idl.hh
idl/idl_test.idl.hh
idl/keys.idl.hh
idl/messaging_service.idl.hh
idl/mutation.idl.hh
idl/paging_state.idl.hh
idl/partition_checksum.idl.hh
idl/paxos.idl.hh
idl/query.idl.hh
idl/raft.idl.hh
idl/range.idl.hh
idl/read_command.idl.hh
idl/reconcilable_result.idl.hh
idl/replay_position.idl.hh
idl/result.idl.hh
idl/ring_position.idl.hh
idl/streaming.idl.hh
idl/token.idl.hh
idl/tracing.idl.hh
idl/truncation_record.idl.hh
idl/uuid.idl.hh
idl/view.idl.hh)
set(idl_gen_files)
foreach(f ${idl_serializers})
get_filename_component(idl_name "${f}" NAME)
get_filename_component(idl_target "${idl_name}" NAME_WE)
get_filename_component(idl_dir "${f}" DIRECTORY)
string(REPLACE ".idl.hh" ".dist.hh" idl_out_hdr_name "${idl_name}")
scylla_generate_idl_serializer(
TARGET scylla_idl_gen_${idl_target}
VAR scylla_idl_gen_${idl_target}_files
IN_FILE "${CMAKE_SOURCE_DIR}/${f}"
OUT_FILE ${scylla_gen_build_dir}/${idl_dir}/${idl_out_hdr_name})
list(APPEND idl_gen_files "${scylla_idl_gen_${idl_target}_files}")
endforeach()
set(scylla_sources
absl-flat_hash_map.cc
api/api.cc
@@ -519,11 +421,11 @@ set(scylla_sources
set(scylla_gen_sources
"${scylla_thrift_gen_cassandra_files}"
"${scylla_ragel_gen_protocol_parser_file}"
"${swagger_gen_files}"
"${idl_gen_files}")
"${swagger_gen_files}")
add_subdirectory(alternator)
add_subdirectory(cql3)
add_subdirectory(idl)
add_subdirectory(rust)
add_executable(scylla
@@ -533,6 +435,7 @@ add_executable(scylla
target_link_libraries(scylla PRIVATE
alternator
cql3
idl
wasmtime_bindings)
target_link_libraries(scylla PRIVATE
@@ -566,6 +469,7 @@ target_link_libraries(scylla PRIVATE
absl::exponential_biased
absl::throw_delegate
# System libs
libdeflate::libdeflate
ZLIB::ZLIB
ICU::uc
systemd
@@ -581,17 +485,11 @@ target_link_libraries(scylla PRIVATE
-fuse-ld=lld)
# TODO: patch dynamic linker to match configure.py behavior
target_compile_options(scylla PRIVATE
-std=gnu++20
${cxx_coro_flag}
${target_arch_flag})
# Hacks needed to expose internal APIs for xxhash dependencies
target_compile_definitions(scylla PRIVATE XXH_PRIVATE_API HAVE_LZ4_COMPRESS_DEFAULT)
find_package(libdeflate REQUIRED)
target_include_directories(scylla PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
libdeflate::libdeflate
"${scylla_gen_build_dir}")
###

View File

@@ -17,3 +17,10 @@ target_sources(alternator
streams.cc
ttl.cc
${cql_grammar_srcs})
target_include_directories(alternator
PUBLIC
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR})
target_link_libraries(alternator
Seastar::seastar
xxHash::xxhash)

View File

@@ -34,7 +34,7 @@ find_package_handle_standard_args (libdeflate
deflate_INCLUDE_DIR
VERSION_VAR PC_deflate_VERSION)
if (deflate_FOUND)
if (libdeflate_FOUND)
set (deflate_LIBRARIES ${deflate_LIBRARY})
set (deflate_INCLUDE_DIRS ${deflate_INCLUDE_DIR})
if (NOT (TARGET libdeflate::libdeflate))

48
cmake/FindxxHash.cmake Normal file
View File

@@ -0,0 +1,48 @@
#
# Copyright 2023-present ScyllaDB
#
#
# SPDX-License-Identifier: AGPL-3.0-or-later
#
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_xxhash QUIET libxxhash)
find_library(xxhash_LIBRARY
NAMES xxhash
HINTS
${PC_xxhash_LIBDIR}
${PC_xxhash_LIBRARY_DIRS})
find_path(xxhash_INCLUDE_DIR
NAMES xxhash.h
HINTS
${PC_xxhash_INCLUDEDIR}
${PC_xxhash_INCLUDE_DIRS})
mark_as_advanced(
xxhash_LIBRARY
xxhash_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(xxHash
REQUIRED_VARS
xxhash_LIBRARY
xxhash_INCLUDE_DIR
VERSION_VAR PC_xxhash_VERSION)
if(xxHash_FOUND)
set(xxhash_LIBRARIES ${xxhash_LIBRARY})
set(xxhash_INCLUDE_DIRS ${xxhash_INCLUDE_DIR})
if(NOT(TARGET xxHash::xxhash))
add_library(xxHash::xxhash UNKNOWN IMPORTED)
set_target_properties(xxHash::xxhash
PROPERTIES
IMPORTED_LOCATION ${xxhash_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${xxhash_INCLUDE_DIRS}
INTERFACE_COMPILE_DEFINITIONS XXH_PRIVATE_API)
endif()
endif()

View File

@@ -40,7 +40,7 @@ function(generate_cql_grammar)
-e "1i using ExceptionBaseType = int;"
-e "s/^{{/{{ ExceptionBaseType\* ex = nullptr;/"
-e "s/ExceptionBaseType\* ex = new/ex = new/"
-e "s/exceptions::syntax_exception e/exceptions::syntax_exception\& e/"
-e "s/exceptions::syntax_exception e/exceptions::syntax_exception\\& e/"
${gen_dir}/${stem}Parser.cpp
COMMENT "Generating sources from ${grammar}"
VERBATIM)

21
cmake/mode.DEBUG.cmake Normal file
View File

@@ -0,0 +1,21 @@
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
# -fasan -Og breaks some coroutines on aarch64, use -O0 instead
set(default_Seastar_OptimizationLevel_DEBUG "g")
else()
set(default_Seastar_OptimizationLevel_DEBUG "0")
endif()
set(Seastar_OptimizationLevel_DEBUG
${default_Seastar_OptimizationLevel_DEBUG}
CACHE
INTERNAL
"")
set(Seastar_DEFINITIONS_DEBUG
SCYLLA_BUILD_MODE=debug
DEBUG
SANITIZE
DEBUG_LSA_SANITIZER
SCYLLA_ENABLE_ERROR_INJECTION)
set(CMAKE_CXX_FLAGS_DEBUG
" -O${Seastar_OptimizationLevel_DEBUG} -g -gz")

14
cmake/mode.DEV.cmake Normal file
View File

@@ -0,0 +1,14 @@
set(Seastar_OptimizationLevel_DEV "2")
set(CMAKE_CXX_FLAGS_DEV
""
CACHE
INTERNAL
"")
string(APPEND CMAKE_CXX_FLAGS_RELEASE
" -O${Seastar_OptimizationLevel_RELEASE}")
set(Seastar_DEFINITIONS_DEV
SCYLLA_BUILD_MODE=devel
DEVEL
SEASTAR_ENABLE_ALLOC_FAILURE_INJECTION
SCYLLA_ENABLE_ERROR_INJECTION)

14
cmake/mode.RELEASE.cmake Normal file
View File

@@ -0,0 +1,14 @@
set(Seastar_OptimizationLevel_RELEASE "3")
set(CMAKE_CXX_FLAGS_RELEASE
"-ffunction-sections -fdata-sections"
CACHE
INTERNAL
"")
string(APPEND CMAKE_CXX_FLAGS_RELEASE
" -O${Seastar_OptimizationLevel_RELEASE}")
set(Seastar_DEFINITIONS_DEBUG
SCYLLA_BUILD_MODE=release)
set(CMAKE_STATIC_LINKER_FLAGS_RELEASE
"-Wl,--gc-sections")

31
cmake/mode.common.cmake Normal file
View File

@@ -0,0 +1,31 @@
set(disabled_warnings
c++11-narrowing
mismatched-tags
missing-braces
overloaded-virtual
unsupported-friend)
include(CheckCXXCompilerFlag)
foreach(warning disabled_warnings)
check_cxx_compiler_flag("-Wno-${warning}" _warning_supported)
if(_warning_supported)
list(APPEND _supported_warnings ${warning})
endif()
endforeach()
list(TRANSFORM disabled_warnings PREPEND "-Wno-")
string(JOIN " " CMAKE_CXX_FLAGS "-Wall" "-Werror" ${disabled_warnings})
function(default_target_arch arch)
set(x86_instruction_sets i386 i686 x86_64)
if(CMAKE_SYSTEM_PROCESSOR IN_LIST x86_instruction_sets)
set(${arch} "westmere" PARENT_SCOPE)
elseif(CMAKE_SYSTEM_PROCESSOR EQUAL "aarch64")
set(${arch} "armv8-a+crc+crypto" PARENT_SCOPE)
else()
set(${arch} "" PARENT_SCOPE)
endif()
endfunction()
default_target_arch(target_arch)
if(target_arch)
string(APPEND CMAKE_CXX_FLAGS " -march=${target_arch}")
endif()

View File

@@ -1,7 +1,4 @@
find_program (ANTLR3 antlr3)
if(NOT ANTLR3)
message(FATAL "antlr3 is required")
endif()
include(generate_cql_grammar)
generate_cql_grammar(
GRAMMAR Cql.g
@@ -107,3 +104,10 @@ target_sources(cql3
result_set.cc
prepare_context.cc
${cql_grammar_srcs})
target_include_directories(cql3
PUBLIC
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR})
target_link_libraries(cql3
Seastar::seastar
xxHash::xxhash)

75
idl/CMakeLists.txt Normal file
View File

@@ -0,0 +1,75 @@
find_package(Python3 COMPONENTS QUIET REQUIRED Interpreter)
# Create C++ bindings for IDL serializers
function(compile_idl input)
cmake_parse_arguments(parsed_args "" "SOURCES" "" ${ARGN})
get_filename_component(basename ${input} NAME_WE)
get_filename_component(directory ${input} DIRECTORY)
set(input "${CMAKE_CURRENT_SOURCE_DIR}/${input}")
if(directory)
set(directory "${CMAKE_CURRENT_BINARY_DIR}/${directory}")
file(MAKE_DIRECTORY "${directory}")
else()
set(directory "${CMAKE_CURRENT_BINARY_DIR}")
endif()
set(idl_compiler "${CMAKE_SOURCE_DIR}/idl-compiler.py")
set(output "${directory}/${basename}.dist.hh")
add_custom_command(
OUTPUT ${output}
COMMAND ${Python3_EXECUTABLE} ${idl_compiler} --ns ser -f ${input} -o ${output}
DEPENDS ${idle_compiler} ${input})
set(${parsed_args_SOURCES} ${output} PARENT_SCOPE)
endfunction(compile_idl)
set(idl_headers
gossip_digest.idl.hh
uuid.idl.hh
range.idl.hh
keys.idl.hh
read_command.idl.hh
token.idl.hh
ring_position.idl.hh
result.idl.hh
frozen_mutation.idl.hh
reconcilable_result.idl.hh
streaming.idl.hh
paging_state.idl.hh
frozen_schema.idl.hh
partition_checksum.idl.hh
replay_position.idl.hh
truncation_record.idl.hh
mutation.idl.hh
query.idl.hh
idl_test.idl.hh
commitlog.idl.hh
tracing.idl.hh
consistency_level.idl.hh
cache_temperature.idl.hh
view.idl.hh
messaging_service.idl.hh
paxos.idl.hh
raft.idl.hh
raft_storage.idl.hh
group0.idl.hh
hinted_handoff.idl.hh
storage_proxy.idl.hh
group0_state_machine.idl.hh
forward_request.idl.hh
replica_exception.idl.hh
per_partition_rate_limit_info.idl.hh
position_in_partition.idl.hh
experimental/broadcast_tables_lang.idl.hh)
foreach(idl_header ${idl_headers})
compile_idl(${idl_header}
SOURCES srcs)
list(APPEND idl_sources ${srcs})
endforeach()
add_custom_target(idl-sources
DEPENDS ${idl_sources})
add_library(idl INTERFACE)
add_dependencies(idl idl-sources)
target_include_directories(idl
INTERFACE
${CMAKE_BINARY_DIR})