aboutsummaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorrobot-ya-builder <robot-ya-builder@yandex-team.com>2023-03-17 19:38:27 +0300
committerrobot-ya-builder <robot-ya-builder@yandex-team.com>2023-03-17 19:38:27 +0300
commit26147c4e01ae75f397d4dd999da238bf2c61c851 (patch)
tree873a652bca08f38df296c77422b40fd404f0481e /cmake
parent08f6d0d9bb84f493c5dfd3c0d1568445faa26d85 (diff)
downloadydb-26147c4e01ae75f397d4dd999da238bf2c61c851.tar.gz
External build system generator release 21
Update tools: yexport
Diffstat (limited to 'cmake')
-rw-r--r--cmake/common.cmake5
-rw-r--r--cmake/global_flags.cmake41
-rw-r--r--cmake/global_flags.compiler.gnu.cmake96
-rw-r--r--cmake/global_flags.compiler.msvc.cmake32
-rw-r--r--cmake/global_flags.linker.gnu.cmake22
-rw-r--r--cmake/global_vars.cmake6
6 files changed, 134 insertions, 68 deletions
diff --git a/cmake/common.cmake b/cmake/common.cmake
index d1affcabbb..784ff43ff0 100644
--- a/cmake/common.cmake
+++ b/cmake/common.cmake
@@ -127,6 +127,11 @@ function(generate_enum_serilization Tgt Input)
target_sources(${Tgt} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${BaseName}_serialized.cpp)
endfunction()
+
+if (MSVC AND (${CMAKE_VERSION} VERSION_LESS "3.21.0"))
+ message(FATAL_ERROR "Build with MSVC-compatible toolchain requires at least cmake 3.21.0 because of used TARGET_OBJECTS feature")
+endif()
+
function(add_global_library_for TgtName MainName)
if (MSVC)
add_library(${TgtName} OBJECT ${ARGN})
diff --git a/cmake/global_flags.cmake b/cmake/global_flags.cmake
index cd857ecd38..e57e9ebcf9 100644
--- a/cmake/global_flags.cmake
+++ b/cmake/global_flags.cmake
@@ -1,29 +1,48 @@
set(CMAKE_C_FLAGS "")
set(CMAKE_CXX_FLAGS "")
+# workaround when old NDK toolchain that does not set CMAKE_ANDROID_NDK_VERSION is used
+# See for details: https://gitlab.kitware.com/cmake/cmake/-/issues/24386
+if(ANDROID_NDK_REVISION AND NOT CMAKE_ANDROID_NDK_VERSION)
+ set(CMAKE_ANDROID_NDK_VERSION "${ANDROID_NDK_REVISION}")
+endif()
+
if (MSVC)
+ set(flagPrefixSymbol "/")
include(global_flags.compiler.msvc)
include(global_flags.linker.msvc)
else()
+ set(flagPrefixSymbol "-")
include(global_flags.compiler.gnu)
include(global_flags.linker.gnu)
endif()
-if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64"))
- set(_X86_64_DEFINES "\
- -DSSE_ENABLED=1 \
- -DSSE3_ENABLED=1 \
- -DSSSE3_ENABLED=1 \
- -DSSE41_ENABLED=1 \
- -DSSE42_ENABLED=1 \
- -DPOPCNT_ENABLED=1 \
- -DCX16_ENABLED=1 \
+if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|AMD64)$")
+ set(_ALL_X86_EXTENSIONS_DEFINES "\
+ ${flagPrefixSymbol}DSSE_ENABLED=1 \
+ ${flagPrefixSymbol}DSSE3_ENABLED=1 \
+ ${flagPrefixSymbol}DSSSE3_ENABLED=1 \
")
+ if ((CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") OR (NOT ANDROID))
+ string(APPEND _ALL_X86_EXTENSIONS_DEFINES "\
+ ${flagPrefixSymbol}DSSE41_ENABLED=1 \
+ ${flagPrefixSymbol}DSSE42_ENABLED=1 \
+ ${flagPrefixSymbol}DPOPCNT_ENABLED=1 \
+ ")
+ if (NOT ANDROID)
+ # older clang versions did not support this feature on Android:
+ # https://reviews.llvm.org/rGc32d307a49f5255602e7543e64e6c38a7f536abc
+ string(APPEND _ALL_X86_EXTENSIONS_DEFINES " ${flagPrefixSymbol}DCX16_ENABLED=1")
+ endif()
+ endif()
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_X86_64_DEFINES}")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_X86_64_DEFINES}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_ALL_X86_EXTENSIONS_DEFINES}")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_ALL_X86_EXTENSIONS_DEFINES}")
endif()
+message(VERBOSE "CMAKE_C_FLAGS = \"${CMAKE_C_FLAGS}\"")
+message(VERBOSE "CMAKE_CXX_FLAGS = \"${CMAKE_CXX_FLAGS}\"")
+
if (NOT CMAKE_CROSSCOMPILING)
set(TOOLS_ROOT ${CMAKE_BINARY_DIR})
elseif(NOT TOOLS_ROOT)
diff --git a/cmake/global_flags.compiler.gnu.cmake b/cmake/global_flags.compiler.gnu.cmake
index f606b71e0e..b086cd4d34 100644
--- a/cmake/global_flags.compiler.gnu.cmake
+++ b/cmake/global_flags.compiler.gnu.cmake
@@ -3,6 +3,7 @@ set(_GNU_COMMON_C_CXX_FLAGS "\
-fno-common \
-fcolor-diagnostics \
-faligned-allocation \
+ -fdebug-default-version=4 \
-ffunction-sections \
-fdata-sections \
-Wall \
@@ -18,60 +19,79 @@ set(_GNU_COMMON_C_CXX_FLAGS "\
-D_LARGEFILE_SOURCE \
-D__STDC_CONSTANT_MACROS \
-D__STDC_FORMAT_MACROS \
- -D_GNU_SOURCE \
-D__LONG_LONG_SUPPORTED \
- -D_YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE \
- -D_libunwind_ \
- -DLIBCXX_BUILDING_LIBCXXRT \
")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS} \
- -D_FILE_OFFSET_BITS=64 \
-")
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS} \
- -Woverloaded-virtual \
- -Wimport-preprocessor-directive-pedantic \
- -Wno-undefined-var-template \
- -Wno-return-std-move \
- -Wno-defaulted-function-deleted \
- -Wno-pessimizing-move \
- -Wno-deprecated-anon-enum-enum-conversion \
- -Wno-deprecated-enum-enum-conversion \
- -Wno-deprecated-enum-float-conversion \
- -Wno-ambiguous-reversed-operator \
- -Wno-deprecated-volatile \
-")
+if (CMAKE_SYSTEM_NAME MATCHES "^(Android|Linux)$")
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -D_GNU_SOURCE")
+endif()
+
+if (CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux)$")
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -DLIBCXX_BUILDING_LIBCXXRT")
+endif()
-if (NOT APPLE)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fuse-init-array")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fuse-init-array")
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ # Use .init_array instead of .ctors (default for old clang versions)
+ # See: https://maskray.me/blog/2021-11-07-init-ctors-init-array
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -fuse-init-array")
endif()
if (ANDROID)
include_directories(SYSTEM ${CMAKE_ANDROID_NDK}/sources/cxx-stl/llvm-libc++abi/include)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsigned-char")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")
+
+ # There is no usable _FILE_OFFSET_BITS=64 support in Androids until API 21. And it's incomplete until at least API 24.
+ # https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md
else()
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64")
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -D_FILE_OFFSET_BITS=64")
endif()
-if (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsigned-char")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char")
+if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|aarch64)")
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -fsigned-char")
endif()
-if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64"))
- set(_X86_64_GNU_COMPILER_FLAGS "\
- -m64 \
+if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i686|x86_64|AMD64)$")
+ if (CMAKE_SYSTEM_PROCESSOR STREQUAL "i686")
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -m32")
+ elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -m64")
+ endif()
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS "\
-msse2 \
-msse3 \
-mssse3 \
- -msse4.1 \
- -msse4.2 \
- -mpopcnt \
- -mcx16 \
")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_X86_64_GNU_COMPILER_FLAGS}")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_X86_64_GNU_COMPILER_FLAGS}")
+ if ((CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$") OR (NOT ANDROID))
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS "\
+ -msse4.1 \
+ -msse4.2 \
+ -mpopcnt \
+ ")
+ if (NOT ANDROID)
+ # older clang versions did not support this feature on Android:
+ # https://reviews.llvm.org/rGc32d307a49f5255602e7543e64e6c38a7f536abc
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -mcx16")
+ endif()
+ endif()
+
+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -D_YNDX_LIBUNWIND_ENABLE_EXCEPTION_BACKTRACE")
+ endif()
+elseif (ANDROID AND (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a"))
+ string(APPEND _GNU_COMMON_C_CXX_FLAGS " -mfloat-abi=softfp")
endif()
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_GNU_COMMON_C_CXX_FLAGS} \
+ -Woverloaded-virtual \
+ -Wimport-preprocessor-directive-pedantic \
+ -Wno-undefined-var-template \
+ -Wno-return-std-move \
+ -Wno-defaulted-function-deleted \
+ -Wno-pessimizing-move \
+ -Wno-deprecated-anon-enum-enum-conversion \
+ -Wno-deprecated-enum-enum-conversion \
+ -Wno-deprecated-enum-float-conversion \
+ -Wno-ambiguous-reversed-operator \
+ -Wno-deprecated-volatile \
+")
diff --git a/cmake/global_flags.compiler.msvc.cmake b/cmake/global_flags.compiler.msvc.cmake
index 34cc3ff437..4c08895cde 100644
--- a/cmake/global_flags.compiler.msvc.cmake
+++ b/cmake/global_flags.compiler.msvc.cmake
@@ -78,7 +78,8 @@ else()
foreach(INCLUDE_PATH $ENV{INCLUDE})
if (INCLUDE_PATH MATCHES ".*\\\\Windows Kits\\\\[0-9]+\\\\include\\\\[0-9\\.]+\\\\ucrt$")
message(VERBOSE "Found Y_UCRT_INCLUDE path \"${INCLUDE_PATH}\"")
- string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /DY_UCRT_INCLUDE=\"${INCLUDE_PATH}\"")
+ string(REPLACE "\\" "/" SAFE_INCLUDE_PATH "${INCLUDE_PATH}")
+ string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /DY_UCRT_INCLUDE=\"${SAFE_INCLUDE_PATH}\"")
set(UCRT_INCLUDE_FOUND true)
break()
endif()
@@ -91,7 +92,8 @@ else()
foreach(INCLUDE_PATH $ENV{INCLUDE})
if (INCLUDE_PATH MATCHES ".*VC\\\\Tools\\\\MSVC\\\\[0-9\\.]+\\\\include$")
message(VERBOSE "Found Y_MSVC_INCLUDE path \"${INCLUDE_PATH}\"")
- string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /DY_MSVC_INCLUDE=\"${INCLUDE_PATH}\"")
+ string(REPLACE "\\" "/" SAFE_INCLUDE_PATH "${INCLUDE_PATH}")
+ string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /DY_MSVC_INCLUDE=\"${SAFE_INCLUDE_PATH}\"")
set(MSVC_INCLUDE_FOUND true)
break()
endif()
@@ -113,6 +115,19 @@ foreach(WARN ${_WARNS_DISABLED})
string(APPEND _MSVC_COMMON_C_CXX_FLAGS " /wd${WARN}")
endforeach()
+if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
+ string(APPEND _MSVC_COMMON_C_CXX_FLAGS " \
+ /D_WIN64 \
+ /DWIN64 \
+ /D__SSE2__ \
+ /D__SSE3__ \
+ /D__SSSE3__ \
+ /D__SSE4_1__ \
+ /D__SSE4_2__ \
+ /D__POPCNT__ \
+ ")
+endif()
+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_MSVC_COMMON_C_CXX_FLAGS} \
")
@@ -125,16 +140,3 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_MSVC_COMMON_C_CXX_FLAGS} \
")
set(CMAKE_CXX_FLAGS_DEBUG "/Z7")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Z7")
-
-if ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") OR (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64"))
- set(CMAKE_C_FLAGS "\
- ${CMAKE_C_FLAGS} \
- /D_WIN64 \
- /DWIN64 \
- ")
- set(CMAKE_CXX_FLAGS "\
- ${CMAKE_CXX_FLAGS} \
- /D_WIN64 \
- /DWIN64 \
- ")
-endif()
diff --git a/cmake/global_flags.linker.gnu.cmake b/cmake/global_flags.linker.gnu.cmake
index 2bb54fbd78..c527053100 100644
--- a/cmake/global_flags.linker.gnu.cmake
+++ b/cmake/global_flags.linker.gnu.cmake
@@ -1,9 +1,29 @@
add_link_options(
- -nodefaultlibs
-lc
-lm
)
+if (ANDROID)
+ # NDK r23 onwards has stopped using libgcc:
+ # - https://github.com/android/ndk/wiki/Changelog-r23#changes
+ # - https://github.com/android/ndk/issues/1230
+ # LLVM's libunwind is now used instead of libgcc for all architectures rather than just 32-bit Arm.
+ # - https://github.com/android/ndk/issues/1231
+ # LLVM's libclang_rt.builtins is now used instead of libgcc.
+ if (CMAKE_ANDROID_NDK_VERSION GREATER_EQUAL 23)
+ # Use toolchain defaults to link with libunwind/clang_rt.builtins
+ add_link_options("-nostdlib++")
+ else ()
+ # Preserve old behaviour: specify runtime libs manually
+ add_link_options(-nodefaultlibs -lgcc)
+ if (CMAKE_ANDROID_ARCH_ABI STREQUAL "armeabi-v7a")
+ add_link_options("-lunwind")
+ endif()
+ endif()
+elseif (CMAKE_SYSTEM_NAME MATCHES "^(Darwin|Linux)$")
+ add_link_options("-nodefaultlibs")
+endif()
+
if (APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "-undefined dynamic_lookup")
endif()
diff --git a/cmake/global_vars.cmake b/cmake/global_vars.cmake
index b7eb44026c..3768009ec5 100644
--- a/cmake/global_vars.cmake
+++ b/cmake/global_vars.cmake
@@ -6,18 +6,18 @@
# original buildsystem will not be accepted.
-if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND UNIX AND NOT APPLE AND NOT ANDROID AND NOT HAVE_CUDA)
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
set(YASM_FLAGS -f elf64 -D UNIX -D _x86_64_ -D_YASM_ -g dwarf2)
set(BISON_FLAGS -v)
set(RAGEL_FLAGS -L -I ${CMAKE_SOURCE_DIR}/)
endif()
-if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND UNIX AND NOT APPLE AND NOT ANDROID)
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(BISON_FLAGS -v)
set(RAGEL_FLAGS -L -I ${CMAKE_SOURCE_DIR}/)
endif()
-if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+if(CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(YASM_FLAGS -f macho64 -D DARWIN -D UNIX -D _x86_64_ -D_YASM_)
set(BISON_FLAGS -v)
set(RAGEL_FLAGS -L -I ${CMAKE_SOURCE_DIR}/)