1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#
# Check if the same compile family is used for both C and CXX
#
if (NOT (CMAKE_C_COMPILER_ID STREQUAL CMAKE_CXX_COMPILER_ID))
message(WARNING "CMAKE_C_COMPILER_ID (${CMAKE_C_COMPILER_ID}) is different "
"from CMAKE_CXX_COMPILER_ID (${CMAKE_CXX_COMPILER_ID})."
"The final binary may be unusable.")
endif()
# We support building with Clang and gcc. First check
# what we're using for build.
#
if (CMAKE_C_COMPILER_ID STREQUAL Clang)
set(CMAKE_COMPILER_IS_CLANG ON)
set(CMAKE_COMPILER_IS_GNUCC OFF)
set(CMAKE_COMPILER_IS_GNUCXX OFF)
endif()
#
# Check supported standards
#
if((NOT HAVE_STD_C11 AND NOT HAVE_STD_GNU99) OR
(NOT HAVE_STD_CXX11 AND NOT HAVE_STD_GNUXX0X))
set(CMAKE_REQUIRED_FLAGS "-std=c11")
check_c_source_compiles("int main(void) { return 0; }" HAVE_STD_C11)
set(CMAKE_REQUIRED_FLAGS "-std=gnu99")
check_c_source_compiles("int main(void) { return 0; }" HAVE_STD_GNU99)
set(CMAKE_REQUIRED_FLAGS "-std=c++11")
check_cxx_source_compiles("int main(void) { return 0; }" HAVE_STD_CXX11)
set(CMAKE_REQUIRED_FLAGS "-std=gnu++0x")
check_cxx_source_compiles("int main(void) { return 0; }" HAVE_STD_GNUXX0X)
set(CMAKE_REQUIRED_FLAGS "")
endif()
if((NOT HAVE_STD_C11 AND NOT HAVE_STD_GNU99) OR
(NOT HAVE_STD_CXX11 AND NOT HAVE_STD_GNUXX0X))
message (FATAL_ERROR
"${CMAKE_C_COMPILER} should support -std=c11 or -std=gnu99. "
"${CMAKE_CXX_COMPILER} should support -std=c++11 or -std=gnu++0x. "
"Please consider upgrade to gcc 4.5+ or clang 3.2+.")
endif()
#
# Perform build type specific configuration.
#
if (CMAKE_COMPILER_IS_GNUCC)
set (CC_DEBUG_OPT "-ggdb")
else()
set (CC_DEBUG_OPT "-g")
endif()
set (CMAKE_C_FLAGS_DEBUG
"${CMAKE_C_FLAGS_DEBUG} ${CC_DEBUG_OPT} -O0")
set (CMAKE_C_FLAGS_RELWITHDEBUGINFO
"${CMAKE_C_FLAGS_RELWITHDEBUGINFO} ${CC_DEBUG_OPT} -O2")
set (CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} ${CC_DEBUG_OPT} -O0")
set (CMAKE_CXX_FLAGS_RELWITHDEBUGINFO
"${CMAKE_CXX_FLAGS_RELWITHDEBUGINFO} ${CC_DEBUG_OPT} -O2")
unset(CC_DEBUG_OPT)
#
# Set flags for all include files: those maintained by us and
# coming from third parties.
# We must set -fno-omit-frame-pointer here, since we rely
# on frame pointer when getting a backtrace, and it must
# be used consistently across all object files.
# The same reasoning applies to -fno-stack-protector switch.
# Since we began using luajit, which uses gcc stack unwind
# internally, we also need to make sure all code is compiled
# with unwind info.
#
add_compile_flags("C;CXX"
"-fno-omit-frame-pointer"
"-fno-stack-protector"
"-fexceptions"
"-funwind-tables")
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
# Remove VALGRIND code and assertions in *any* type of release build.
add_definitions("-DNDEBUG" "-DNVALGRIND")
endif()
macro(enable_tnt_compile_flags)
# Tarantool code is written in GNU C dialect.
# Additionally, compile it with more strict flags than the rest
# of the code.
# Set standard
if (HAVE_STD_C11)
add_compile_flags("C" "-std=c11")
else()
add_compile_flags("C" "-std=gnu99")
endif()
if (HAVE_STD_CXX11)
add_compile_flags("CXX" "-std=c++11")
else()
add_compile_flags("CXX" "-std=gnu++0x")
endif()
# Disable Run-time type information
add_compile_flags("CXX" "-fno-rtti")
add_compile_flags("C;CXX"
"-Wall"
"-Wextra"
"-Wno-sign-compare"
"-Wno-strict-aliasing"
)
if (CMAKE_COMPILER_IS_GNUCXX)
# G++ bug. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31488
add_compile_flags("CXX"
"-Wno-invalid-offsetof"
)
endif()
add_definitions("-D__STDC_FORMAT_MACROS=1")
add_definitions("-D__STDC_LIMIT_MACROS=1")
add_definitions("-D__STDC_CONSTANT_MACROS=1")
# Only add -Werror if it's a debug build, done by developers.
# Release builds should not cause extra trouble.
if ((${CMAKE_BUILD_TYPE} STREQUAL "Debug")
AND HAVE_STD_C11 AND HAVE_STD_CXX11)
add_compile_flags("C;CXX" "-Werror")
endif()
endmacro(enable_tnt_compile_flags)
#
# GCC started to warn for unused result starting from 4.2, and
# this is when it introduced -Wno-unused-result
# GCC can also be built on top of llvm runtime (on mac).
#
check_c_compiler_flag("-Wno-unused-result" CC_HAS_WNO_UNUSED_RESULT)
check_c_compiler_flag("-Wno-unused-value" CC_HAS_WNO_UNUSED_VALUE)
check_c_compiler_flag("-fno-strict-aliasing" CC_HAS_FNO_STRICT_ALIASING)
check_c_compiler_flag("-Wno-comment" CC_HAS_WNO_COMMENT)
check_c_compiler_flag("-Wno-parentheses" CC_HAS_WNO_PARENTHESES)
if (CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCC)
set(HAVE_BUILTIN_CTZ 1)
set(HAVE_BUILTIN_CTZLL 1)
set(HAVE_BUILTIN_CLZ 1)
set(HAVE_BUILTIN_CLZLL 1)
set(HAVE_BUILTIN_POPCOUNT 1)
set(HAVE_BUILTIN_POPCOUNTLL 1)
set(HAVE_BUILTIN_BSWAP32 1)
set(HAVE_BUILTIN_BSWAP64 1)
else()
set(HAVE_BUILTIN_CTZ 0)
set(HAVE_BUILTIN_CTZLL 0)
set(HAVE_BUILTIN_CLZ 0)
set(HAVE_BUILTIN_CLZLL 0)
set(HAVE_BUILTIN_POPCOUNT 0)
set(HAVE_BUILTIN_POPCOUNTLL 0)
set(HAVE_BUILTIN_BSWAP32 0)
set(HAVE_BUILTIN_BSWAP64 0)
endif()
if (NOT HAVE_BUILTIN_CTZ OR NOT HAVE_BUILTIN_CTZLL)
# Check if -D_GNU_SOURCE has been defined and add this flag to
# CMAKE_REQUIRED_DEFINITIONS in order to get check_prototype_definition work
get_property(var DIRECTORY PROPERTY COMPILE_DEFINITIONS)
list(FIND var "_GNU_SOURCE" var)
if (NOT var EQUAL -1)
set(CMAKE_REQUIRED_FLAGS "-Wno-error")
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE")
check_c_source_compiles("#include <string.h>\n#include <strings.h>\nint main(void) { return ffsl(0L); }"
HAVE_FFSL)
check_c_source_compiles("#include <string.h>\n#include <strings.h>\nint main(void) { return ffsll(0UL); }"
HAVE_FFSLL)
endif()
endif()
|