2020-04-24 03:24:12 +08:00
include ( CompilerChecks )
2020-03-28 06:44:55 +08:00
2020-04-24 03:24:12 +08:00
env_set ( USE_GPERFTOOLS OFF BOOL "Use gperfools for profiling" )
2020-02-02 06:34:56 +08:00
env_set ( USE_DTRACE ON BOOL "Enable dtrace probes on supported platforms" )
2020-03-28 06:44:55 +08:00
env_set ( USE_VALGRIND OFF BOOL "Compile for valgrind usage" )
2020-04-24 03:24:12 +08:00
env_set ( USE_VALGRIND_FOR_CTEST ${ USE_VALGRIND } BOOL "Use valgrind for ctest" )
env_set ( ALLOC_INSTRUMENTATION OFF BOOL "Instrument alloc" )
env_set ( USE_ASAN OFF BOOL "Compile with address sanitizer" )
2020-10-14 23:04:51 +08:00
env_set ( USE_GCOV OFF BOOL "Compile with gcov instrumentation" )
2020-10-16 05:37:47 +08:00
env_set ( USE_MSAN OFF BOOL "Compile with memory sanitizer. To avoid false positives you need to dynamically link to a msan-instrumented libc++ and libc++abi, which you must compile separately. See https://github.com/google/sanitizers/wiki/MemorySanitizerLibcxxHowTo#instrumented-libc." )
2020-10-15 04:50:06 +08:00
env_set ( USE_TSAN OFF BOOL "Compile with thread sanitizer. It is recommended to dynamically link to a tsan-instrumented libc++ and libc++abi, which you can compile separately." )
2020-04-24 03:24:12 +08:00
env_set ( USE_UBSAN OFF BOOL "Compile with undefined behavior sanitizer" )
2021-11-24 01:35:30 +08:00
env_set ( FDB_RELEASE_CANDIDATE OFF BOOL "This is a building of a release candidate" )
2020-04-24 03:24:12 +08:00
env_set ( FDB_RELEASE OFF BOOL "This is a building of a final release" )
2020-03-28 06:44:55 +08:00
env_set ( USE_CCACHE OFF BOOL "Use ccache for compilation if available" )
2020-04-24 03:24:12 +08:00
env_set ( RELATIVE_DEBUG_PATHS OFF BOOL "Use relative file paths in debug info" )
env_set ( USE_WERROR OFF BOOL "Compile with -Werror. Recommended for local development and CI." )
default_linker ( _use_ld )
2020-04-24 05:37:20 +08:00
env_set ( USE_LD "${_use_ld}" STRING
" T h e l i n k e r t o u s e f o r b u i l d i n g : c a n b e LD ( system default and same as DEFAULT ) , B F D , G O L D , o r L L D - w i l l b e L L D f o r C l a n g i f a v a i l a b l e , D E F A U L T o t h e r w i s e " )
2020-04-24 03:24:12 +08:00
use_libcxx ( _use_libcxx )
env_set ( USE_LIBCXX "${_use_libcxx}" BOOL "Use libc++" )
static_link_libcxx ( _static_link_libcxx )
env_set ( STATIC_LINK_LIBCXX "${_static_link_libcxx}" BOOL "Statically link libstdcpp/libc++" )
2022-02-05 09:03:15 +08:00
env_set ( TRACE_PC_GUARD_INSTRUMENTATION_LIB "" STRING "Path to a library containing an implementation for __sanitizer_cov_trace_pc_guard. See https://clang.llvm.org/docs/SanitizerCoverage.html for more info." )
2022-02-08 04:34:27 +08:00
env_set ( PROFILE_INSTR_GENERATE OFF BOOL "If set, build FDB as an instrumentation build to generate profiles" )
env_set ( PROFILE_INSTR_USE "" STRING "If set, build FDB with profile" )
2019-07-10 03:11:51 +08:00
2021-02-05 02:53:28 +08:00
set ( USE_SANITIZER OFF )
if ( USE_ASAN OR USE_VALGRIND OR USE_MSAN OR USE_TSAN OR USE_UBSAN )
set ( USE_SANITIZER ON )
endif ( )
2022-03-18 06:17:27 +08:00
set ( jemalloc_default ON )
# We don't want to use jemalloc on Windows
# Nor on FreeBSD, where jemalloc is the default system allocator
if ( USE_SANITIZER OR WIN32 OR ( CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" ) OR APPLE )
set ( jemalloc_default OFF )
endif ( )
env_set ( USE_JEMALLOC ${ jemalloc_default } BOOL "Link with jemalloc" )
2020-04-11 01:08:24 +08:00
if ( USE_LIBCXX AND STATIC_LINK_LIBCXX AND NOT USE_LD STREQUAL "LLD" )
2020-05-14 06:44:43 +08:00
message ( FATAL_ERROR "Unsupported configuration: STATIC_LINK_LIBCXX with libc++ only works if USE_LD=LLD" )
endif ( )
if ( STATIC_LINK_LIBCXX AND USE_TSAN )
message ( FATAL_ERROR "Unsupported configuration: STATIC_LINK_LIBCXX doesn't work with tsan" )
2020-04-11 01:08:24 +08:00
endif ( )
2020-10-15 04:50:06 +08:00
if ( STATIC_LINK_LIBCXX AND USE_MSAN )
message ( FATAL_ERROR "Unsupported configuration: STATIC_LINK_LIBCXX doesn't work with msan" )
endif ( )
2019-07-10 03:11:51 +08:00
set ( rel_debug_paths OFF )
2019-07-16 06:16:43 +08:00
if ( RELATIVE_DEBUG_PATHS )
2019-07-10 03:11:51 +08:00
set ( rel_debug_paths ON )
endif ( )
2019-01-03 05:32:26 +08:00
2019-04-03 08:34:29 +08:00
if ( USE_GPERFTOOLS )
find_package ( Gperftools REQUIRED )
endif ( )
2019-02-09 04:24:32 +08:00
add_compile_options ( -DCMAKE_BUILD )
2019-03-15 08:47:30 +08:00
add_compile_definitions ( BOOST_ERROR_CODE_HEADER_ONLY BOOST_SYSTEM_NO_DEPRECATED )
2019-02-07 10:16:54 +08:00
2020-10-09 05:24:36 +08:00
set ( THREADS_PREFER_PTHREAD_FLAG ON )
2019-01-03 05:32:26 +08:00
find_package ( Threads REQUIRED )
include_directories ( ${ CMAKE_SOURCE_DIR } )
2020-04-07 01:13:49 +08:00
include_directories ( ${ CMAKE_BINARY_DIR } )
2019-01-03 05:32:26 +08:00
2021-02-09 06:01:02 +08:00
if ( WIN32 )
add_definitions ( -DBOOST_USE_WINDOWS_H )
add_definitions ( -DWIN32_LEAN_AND_MEAN )
endif ( )
2019-06-06 23:54:31 +08:00
if ( USE_CCACHE )
2019-12-17 06:37:51 +08:00
FIND_PROGRAM ( CCACHE_FOUND "ccache" )
if ( CCACHE_FOUND )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache )
set_property ( GLOBAL PROPERTY RULE_LAUNCH_LINK ccache )
else ( )
message ( SEND_ERROR "CCACHE is ON, but ccache was not found" )
endif ( )
2019-06-04 10:35:46 +08:00
endif ( )
2019-01-03 05:32:26 +08:00
include ( CheckFunctionExists )
set ( CMAKE_REQUIRED_INCLUDES stdlib.h malloc.h )
set ( CMAKE_REQUIRED_LIBRARIES c )
2019-09-18 03:23:48 +08:00
set ( CMAKE_CXX_STANDARD 17 )
2020-05-21 05:26:05 +08:00
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
2020-05-08 07:45:19 +08:00
set ( CMAKE_C_STANDARD 11 )
2020-05-21 05:26:05 +08:00
set ( CMAKE_C_STANDARD_REQUIRED ON )
2020-11-26 06:06:59 +08:00
if ( NOT OPEN_FOR_IDE )
add_compile_definitions ( NO_INTELLISENSE )
endif ( )
2020-05-21 05:50:15 +08:00
if ( NOT WIN32 )
include ( CheckIncludeFile )
CHECK_INCLUDE_FILE ( "stdatomic.h" HAS_C11_ATOMICS )
if ( NOT HAS_C11_ATOMICS )
message ( FATAL_ERROR "C compiler does not support c11 atomics" )
endif ( )
2020-05-21 05:26:05 +08:00
endif ( )
2020-05-19 00:22:38 +08:00
2019-01-03 05:32:26 +08:00
if ( WIN32 )
2019-03-08 00:20:50 +08:00
# see: https://docs.microsoft.com/en-us/windows/desktop/WinProg/using-the-windows-headers
2019-12-15 23:13:46 +08:00
# this sets the windows target version to Windows Server 2003
set ( WINDOWS_TARGET 0x0502 )
2020-02-10 00:34:14 +08:00
if ( CMAKE_CXX_FLAGS MATCHES "/W[0-4]" )
# TODO: This doesn't seem to be good style, but I couldn't find a better way so far
string ( REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )
endif ( )
add_compile_options ( /W0 /EHsc /bigobj $< $<CONFIG:Release > :/Zi> /MP /FC /Gm- )
2021-02-09 06:01:02 +08:00
add_compile_definitions ( NOMINMAX )
2021-07-08 17:42:16 +08:00
set ( CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>" )
2019-01-03 05:32:26 +08:00
else ( )
set ( GCC NO )
set ( CLANG NO )
2019-06-21 00:29:01 +08:00
set ( ICC NO )
2019-01-03 05:32:26 +08:00
if ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" )
set ( CLANG YES )
2019-06-21 00:29:01 +08:00
elseif ( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" )
set ( ICC YES )
2019-01-03 05:32:26 +08:00
else ( )
# This is not a very good test. However, as we do not really support many architectures
# this is good enough for now
set ( GCC YES )
endif ( )
2019-05-13 01:41:04 +08:00
# check linker flags.
2019-07-26 23:49:56 +08:00
if ( USE_LD STREQUAL "DEFAULT" )
set ( USE_LD "LD" )
2019-08-21 07:35:41 +08:00
else ( )
2019-07-26 23:49:56 +08:00
if ( ( NOT ( USE_LD STREQUAL "LD" ) ) AND ( NOT ( USE_LD STREQUAL "GOLD" ) ) AND ( NOT ( USE_LD STREQUAL "LLD" ) ) AND ( NOT ( USE_LD STREQUAL "BFD" ) ) )
2019-07-30 07:41:42 +08:00
message ( FATAL_ERROR "USE_LD must be set to DEFAULT, LD, BFD, GOLD, or LLD!" )
2019-07-26 23:49:56 +08:00
endif ( )
2019-05-13 01:41:04 +08:00
endif ( )
# if USE_LD=LD, then we don't do anything, defaulting to whatever system
# linker is available (e.g. binutils doesn't normally exist on macOS, so this
# implies the default xcode linker, and other distros may choose others by
# default).
2019-07-26 23:49:56 +08:00
if ( USE_LD STREQUAL "BFD" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=bfd -Wl,--disable-new-dtags" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=bfd -Wl,--disable-new-dtags" )
endif ( )
2019-05-13 01:41:04 +08:00
if ( USE_LD STREQUAL "GOLD" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold -Wl,--disable-new-dtags" )
endif ( )
if ( USE_LD STREQUAL "LLD" )
set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -Wl,--disable-new-dtags" )
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -Wl,--disable-new-dtags" )
endif ( )
2019-07-10 03:11:51 +08:00
if ( rel_debug_paths )
add_compile_options ( "-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=." "-fdebug-prefix-map=${CMAKE_BINARY_DIR}=." )
endif ( )
2021-01-28 10:13:02 +08:00
set ( SANITIZER_COMPILE_OPTIONS )
set ( SANITIZER_LINK_OPTIONS )
2019-01-03 05:32:26 +08:00
# we always compile with debug symbols. CPack will strip them out
# and create a debuginfo rpm
2019-06-19 02:02:48 +08:00
add_compile_options ( -ggdb -fno-omit-frame-pointer )
2022-01-21 05:24:23 +08:00
if ( TRACE_PC_GUARD_INSTRUMENTATION_LIB )
add_compile_options ( -fsanitize-coverage=trace-pc-guard )
link_libraries ( ${ TRACE_PC_GUARD_INSTRUMENTATION_LIB } )
endif ( )
2019-01-03 05:32:26 +08:00
if ( USE_ASAN )
2021-01-28 10:13:02 +08:00
list ( APPEND SANITIZER_COMPILE_OPTIONS
2020-12-02 05:19:25 +08:00
- f s a n i t i z e = a d d r e s s
- D A D D R E S S _ S A N I T I Z E R
- D B O O S T _ U S E _ A S A N
2021-01-28 10:13:02 +08:00
- D B O O S T _ U S E _ U C O N T E X T )
list ( APPEND SANITIZER_LINK_OPTIONS -fsanitize=address )
2020-10-15 04:50:06 +08:00
endif ( )
if ( USE_MSAN )
if ( NOT CLANG )
message ( FATAL_ERROR "Unsupported configuration: USE_MSAN only works with Clang" )
endif ( )
2021-03-09 09:29:47 +08:00
list ( APPEND SANITIZER_COMPILE_OPTIONS
- f s a n i t i z e = m e m o r y
- f s a n i t i z e - m e m o r y - t r a c k - o r i g i n s = 2
- D B O O S T _ U S E _ U C O N T E X T )
2021-01-28 10:13:02 +08:00
list ( APPEND SANITIZER_LINK_OPTIONS -fsanitize=memory )
2019-01-03 05:32:26 +08:00
endif ( )
2020-10-14 23:04:51 +08:00
if ( USE_GCOV )
2020-10-16 22:59:17 +08:00
add_link_options ( --coverage )
2019-01-03 05:32:26 +08:00
endif ( )
2019-08-19 07:52:19 +08:00
if ( USE_UBSAN )
2021-01-28 10:13:02 +08:00
list ( APPEND SANITIZER_COMPILE_OPTIONS
2019-08-19 07:52:19 +08:00
- f s a n i t i z e = u n d e f i n e d
2019-12-06 07:11:10 +08:00
# TODO(atn34) Re-enable -fsanitize=alignment once https://github.com/apple/foundationdb/issues/1434 is resolved
2021-03-09 09:29:47 +08:00
- f n o - s a n i t i z e = a l i g n m e n t
- D B O O S T _ U S E _ U C O N T E X T )
2021-01-28 10:13:02 +08:00
list ( APPEND SANITIZER_LINK_OPTIONS -fsanitize=undefined )
2019-08-19 07:52:19 +08:00
endif ( )
2020-04-25 08:07:50 +08:00
if ( USE_TSAN )
2021-03-09 09:29:47 +08:00
list ( APPEND SANITIZER_COMPILE_OPTIONS -fsanitize=thread -DBOOST_USE_UCONTEXT )
2021-01-28 10:13:02 +08:00
list ( APPEND SANITIZER_LINK_OPTIONS -fsanitize=thread )
endif ( )
2021-03-09 09:29:47 +08:00
if ( USE_VALGRIND )
list ( APPEND SANITIZER_COMPILE_OPTIONS -DBOOST_USE_VALGRIND )
endif ( )
2021-01-28 10:13:02 +08:00
if ( SANITIZER_COMPILE_OPTIONS )
add_compile_options ( ${ SANITIZER_COMPILE_OPTIONS } )
endif ( )
if ( SANITIZER_LINK_OPTIONS )
add_link_options ( ${ SANITIZER_LINK_OPTIONS } )
2020-04-25 08:07:50 +08:00
endif ( )
2019-01-03 05:32:26 +08:00
if ( PORTABLE_BINARY )
message ( STATUS "Create a more portable binary" )
set ( CMAKE_MODULE_LINKER_FLAGS "-static-libstdc++ -static-libgcc ${CMAKE_MODULE_LINKER_FLAGS}" )
set ( CMAKE_SHARED_LINKER_FLAGS "-static-libstdc++ -static-libgcc ${CMAKE_SHARED_LINKER_FLAGS}" )
set ( CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static-libgcc ${CMAKE_EXE_LINKER_FLAGS}" )
endif ( )
2019-06-19 05:30:30 +08:00
if ( STATIC_LINK_LIBCXX )
if ( NOT USE_LIBCXX AND NOT APPLE )
2022-02-15 21:03:12 +08:00
add_link_options ( -static-libstdc++ -static-libgcc )
2019-06-19 05:30:30 +08:00
endif ( )
endif ( )
2019-12-06 07:11:10 +08:00
# # Instruction sets we require to be supported by the CPU
# TODO(atn34) Re-enable once https://github.com/apple/foundationdb/issues/1434 is resolved
# Some of the following instructions have alignment requirements, so it seems
# prudent to disable them until we properly align memory.
# add_compile_options(
# -maes
# -mmmx
# -mavx
# -msse4.2)
2019-09-17 02:47:37 +08:00
2020-05-14 02:59:59 +08:00
# Tentatively re-enabling vector instructions
set ( USE_AVX512F OFF CACHE BOOL "Enable AVX 512F instructions" )
if ( USE_AVX512F )
2020-06-23 01:40:08 +08:00
if ( CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^x86" )
add_compile_options ( -mavx512f )
2020-08-15 05:14:48 +08:00
elseif ( USE_VALGRIND )
message ( STATUS "USE_VALGRIND=ON make USE_AVX OFF to satisfy valgrind analysis requirement" )
set ( USE_AVX512F OFF )
2020-06-23 01:40:08 +08:00
else ( )
message ( STATUS "USE_AVX512F is supported on x86 or x86_64 only" )
set ( USE_AVX512F OFF )
endif ( )
2020-05-14 02:59:59 +08:00
endif ( )
set ( USE_AVX ON CACHE BOOL "Enable AVX instructions" )
if ( USE_AVX )
2020-06-23 01:40:08 +08:00
if ( CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^x86" )
add_compile_options ( -mavx )
2020-08-15 05:14:48 +08:00
elseif ( USE_VALGRIND )
message ( STATUS "USE_VALGRIND=ON make USE_AVX OFF to satisfy valgrind analysis requirement" )
set ( USE_AVX OFF )
2020-06-23 01:40:08 +08:00
else ( )
message ( STATUS "USE_AVX is supported on x86 or x86_64 only" )
set ( USE_AVX OFF )
endif ( )
2020-05-14 02:59:59 +08:00
endif ( )
# Intentionally using builtin memcpy. G++ does a good job on small memcpy's when the size is known at runtime.
# If the size is not known, then it falls back on the memcpy that's available at runtime (rte_memcpy, as of this
# writing; see flow.cpp).
#
# The downside of the builtin memcpy is that it's slower at large copies, so if we spend a lot of time on large
# copies of sizes that are known at compile time, this might not be a win. See the output of performance/memcpy
# for more information.
#add_compile_options(-fno-builtin-memcpy)
2019-01-03 05:32:26 +08:00
if ( CLANG )
2019-09-17 02:47:37 +08:00
add_compile_options ( )
2019-06-11 06:28:27 +08:00
if ( APPLE OR USE_LIBCXX )
add_compile_options ( $< $<COMPILE_LANGUAGE:CXX > :-stdlib=libc++> )
if ( NOT APPLE )
2020-04-10 05:16:14 +08:00
if ( STATIC_LINK_LIBCXX )
add_link_options ( -static-libgcc -nostdlib++ -Wl,-Bstatic -lc++ -lc++abi -Wl,-Bdynamic )
endif ( )
add_link_options ( -stdlib=libc++ -Wl,-build-id=sha1 )
2019-06-11 06:28:27 +08:00
endif ( )
2019-01-03 05:32:26 +08:00
endif ( )
2019-08-13 00:15:10 +08:00
if ( OPEN_FOR_IDE )
add_compile_options (
- W n o - u n k n o w n - a t t r i b u t e s )
endif ( )
2019-01-03 05:32:26 +08:00
add_compile_options (
2021-04-15 01:30:21 +08:00
- W a l l
- W e x t r a
- W r e d u n d a n t - m o v e
- W p e s s i m i z i n g - m o v e
- W o v e r l o a d e d - v i r t u a l
- W s h i f t - s i g n - o v e r f l o w
2021-07-23 14:09:01 +08:00
# Here's the current set of warnings we need to explicitly disable to compile warning-free with clang 11
2020-07-10 06:02:43 +08:00
- W n o - s i g n - c o m p a r e
2019-01-03 05:32:26 +08:00
- W n o - u n d e f i n e d - v a r - t e m p l a t e
2020-07-10 06:02:43 +08:00
- W n o - u n k n o w n - w a r n i n g - o p t i o n
- W n o - u n u s e d - p a r a m e t e r
2021-11-18 08:23:20 +08:00
- W n o - c o n s t a n t - l o g i c a l - o p e r a n d
2020-06-23 07:45:03 +08:00
)
2019-09-17 02:47:37 +08:00
if ( USE_CCACHE )
add_compile_options (
2019-09-18 03:15:58 +08:00
- W n o - r e g i s t e r
2020-04-11 01:08:24 +08:00
- W n o - u n u s e d - c o m m a n d - l i n e - a r g u m e n t )
2019-09-17 02:47:37 +08:00
endif ( )
2022-02-08 04:34:27 +08:00
if ( PROFILE_INSTR_GENERATE )
2022-02-05 08:46:17 +08:00
add_compile_options ( -fprofile-instr-generate )
add_link_options ( -fprofile-instr-generate )
endif ( )
2022-02-08 04:34:27 +08:00
if ( NOT ( PROFILE_INSTR_USE STREQUAL "" ) )
if ( PROFILE_INSTR_GENERATE )
message ( FATAL_ERROR "Can't set both PROFILE_INSTR_GENERATE and PROFILE_INSTR_USE" )
endif ( )
2022-03-01 07:00:30 +08:00
add_compile_options ( -Wno-error=profile-instr-out-of-date -Wno-error=profile-instr-unprofiled )
2022-02-08 04:34:27 +08:00
add_compile_options ( -fprofile-instr-use= ${ PROFILE_INSTR_USE } )
add_link_options ( -fprofile-instr-use= ${ PROFILE_INSTR_USE } )
2022-02-05 08:46:17 +08:00
endif ( )
2019-01-03 05:32:26 +08:00
endif ( )
2019-09-26 13:08:44 +08:00
if ( USE_WERROR )
2019-01-03 05:32:26 +08:00
add_compile_options ( -Werror )
endif ( )
2019-06-21 00:29:01 +08:00
if ( GCC )
2019-09-27 00:34:01 +08:00
add_compile_options ( -Wno-pragmas )
# Otherwise `state [[maybe_unused]] int x;` will issue a warning.
# https://stackoverflow.com/questions/50646334/maybe-unused-on-member-variable-gcc-warns-incorrectly-that-attribute-is
add_compile_options ( -Wno-attributes )
2019-06-21 00:29:01 +08:00
elseif ( ICC )
add_compile_options ( -wd1879 -wd1011 )
2019-06-21 05:28:31 +08:00
add_link_options ( -static-intel )
2019-06-21 00:29:01 +08:00
endif ( )
2019-01-03 05:32:26 +08:00
add_compile_options ( -Wno-error=format
2019-04-10 02:16:45 +08:00
- W u n u s e d - v a r i a b l e
2019-01-03 05:32:26 +08:00
- W n o - d e p r e c a t e d
- f v i s i b i l i t y = h i d d e n
- W r e t u r n - t y p e
- f P I C )
2021-10-29 13:34:20 +08:00
if ( CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^x86" AND NOT CLANG )
2020-06-23 01:40:08 +08:00
add_compile_options ( $< $<COMPILE_LANGUAGE:CXX > :-Wclass-memaccess> )
endif ( )
2019-04-03 10:58:21 +08:00
if ( GPERFTOOLS_FOUND AND GCC )
add_compile_options (
- f n o - b u i l t i n - m a l l o c
- f n o - b u i l t i n - c a l l o c
- f n o - b u i l t i n - r e a l l o c
- f n o - b u i l t i n - f r e e )
endif ( )
2019-01-03 05:32:26 +08:00
2020-04-15 10:22:37 +08:00
if ( CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" )
2021-01-26 02:30:32 +08:00
# Graviton2 or later
2020-04-15 10:22:37 +08:00
# https://github.com/aws/aws-graviton-gettting-started
2021-01-26 02:30:32 +08:00
add_compile_options ( -march=armv8.2-a+crc+simd )
2020-04-15 10:22:37 +08:00
endif ( )
2022-02-11 14:17:15 +08:00
if ( CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64le" )
2022-02-15 21:03:12 +08:00
add_compile_options ( -m64 -mcpu=power9 -mtune=power9 -DNO_WARN_X86_INTRINSICS )
2022-02-11 14:17:15 +08:00
endif ( )
2019-05-22 04:35:27 +08:00
# Check whether we can use dtrace probes
2019-08-01 10:14:11 +08:00
include ( CheckSymbolExists )
2019-05-22 04:35:27 +08:00
check_symbol_exists ( DTRACE_PROBE sys/sdt.h SUPPORT_DTRACE )
2019-10-22 01:57:58 +08:00
check_symbol_exists ( aligned_alloc stdlib.h HAS_ALIGNED_ALLOC )
message ( STATUS "Has aligned_alloc: ${HAS_ALIGNED_ALLOC}" )
2020-02-02 06:34:56 +08:00
if ( ( SUPPORT_DTRACE ) AND ( USE_DTRACE ) )
2020-11-26 06:06:59 +08:00
set ( DTRACE_PROBES 1 )
2019-10-22 01:57:58 +08:00
endif ( )
2019-05-22 04:35:27 +08:00
2021-12-15 07:45:07 +08:00
set ( USE_LTO OFF CACHE BOOL "Do link time optimization" )
if ( USE_LTO )
if ( CLANG )
set ( CLANG_LTO_STRATEGY "Thin" CACHE STRING "LLVM LTO strategy (Thin, or Full)" )
if ( CLANG_LTO_STRATEGY STREQUAL "Full" )
add_compile_options ( $< $<CONFIG:Release > :-flto=full> )
else ( )
add_compile_options ( $< $<CONFIG:Release > :-flto=thin> )
endif ( )
set ( CMAKE_RANLIB "llvm-ranlib" )
set ( CMAKE_AR "llvm-ar" )
endif ( )
if ( CMAKE_COMPILER_IS_GNUCXX )
2019-01-03 05:32:26 +08:00
add_compile_options ( $< $<CONFIG:Release > :-flto> )
set ( CMAKE_AR "gcc-ar" )
set ( CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>" )
set ( CMAKE_C_ARCHIVE_FINISH true )
set ( CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>" )
set ( CMAKE_CXX_ARCHIVE_FINISH true )
endif ( )
endif ( )
endif ( )