Commit e74f91df authored by Sergei Golubchik's avatar Sergei Golubchik

cmake: always use the same function to test for compiler flags

Fix all cmake tests (including plugin) to use
MY_CHECK_AND_SET_COMPILER_FLAG. And fix that function
to be compatible with cmake 3.0. This way flag checks
are correctly cached (even in cmake 3.0) and properly reused.
parent efbd4bb0
......@@ -9,11 +9,13 @@ SET(fail_patterns
FAIL_REGEX "unrecognized .*option"
FAIL_REGEX "ignoring unknown option"
FAIL_REGEX "warning:.*ignored"
FAIL_REGEX "warning:.*is valid for.*but not for"
FAIL_REGEX "warning:.*redefined"
FAIL_REGEX "[Ww]arning: [Oo]ption"
)
MACRO (MY_CHECK_C_COMPILER_FLAG flag result)
MACRO (MY_CHECK_C_COMPILER_FLAG flag)
STRING(REGEX REPLACE "[-,= ]" "_" result "HAVE_C_${flag}")
SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${result}
......@@ -21,7 +23,8 @@ MACRO (MY_CHECK_C_COMPILER_FLAG flag result)
SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")
ENDMACRO()
MACRO (MY_CHECK_CXX_COMPILER_FLAG flag result)
MACRO (MY_CHECK_CXX_COMPILER_FLAG flag)
STRING(REGEX REPLACE "[-,= ]" "_" result "HAVE_CXX_${flag}")
SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
CHECK_CXX_SOURCE_COMPILES("int main(void) { return 0; }" ${result}
......@@ -35,10 +38,11 @@ FUNCTION(MY_CHECK_AND_SET_COMPILER_FLAG flag)
IF(WIN32)
RETURN()
ENDIF()
MY_CHECK_C_COMPILER_FLAG(${flag} HAVE_C_${flag})
MY_CHECK_CXX_COMPILER_FLAG(${flag} HAVE_CXX_${flag})
MY_CHECK_C_COMPILER_FLAG(${flag})
MY_CHECK_CXX_COMPILER_FLAG(${flag})
STRING(REGEX REPLACE "[-,= ]" "_" result "${flag}")
FOREACH(lang C CXX)
IF (HAVE_${lang}_${flag})
IF (HAVE_${lang}_${result})
IF(ARGN)
FOREACH(type ${ARGN})
SET(CMAKE_${lang}_FLAGS_${type} "${CMAKE_${lang}_FLAGS_${type}} ${flag}" PARENT_SCOPE)
......
......@@ -15,8 +15,8 @@
# Common warning flags for GCC, G++, Clang and Clang++
SET(MY_WARNING_FLAGS "-Wall -Wextra -Wformat-security -Wno-init-self")
MY_CHECK_C_COMPILER_FLAG("-Wvla" HAVE_WVLA) # Requires GCC 4.3+ or Clang
IF(HAVE_WVLA)
MY_CHECK_C_COMPILER_FLAG("-Wvla") # Requires GCC 4.3+ or Clang
IF(HAVE_C__Wvla)
SET(MY_WARNING_FLAGS "${MY_WARNING_FLAGS} -Wvla")
ENDIF()
......
......@@ -274,8 +274,8 @@ ENDIF()
FIND_PACKAGE (Threads)
FUNCTION(MY_CHECK_PTHREAD_ONCE_INIT)
CHECK_C_COMPILER_FLAG("-Werror" HAVE_WERROR_FLAG)
IF(NOT HAVE_WERROR_FLAG)
MY_CHECK_C_COMPILER_FLAG("-Werror")
IF(NOT HAVE_C__Werror)
RETURN()
ENDIF()
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror")
......
......@@ -132,31 +132,6 @@ include(${MRN_SOURCE_DIR}/build/cmake_modules/ReadFileList.cmake)
set(MRN_C_COMPILE_FLAGS "")
set(MRN_CXX_COMPILE_FLAGS "")
macro(mrn_check_cflag flag)
string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag})
string(TOUPPER "${temporary_variable_name}" temporary_variable_name)
set(temporary_variable_name "CFLAG${temporary_variable_name}")
check_c_compiler_flag(${flag} ${temporary_variable_name})
if(${temporary_variable_name})
set(MRN_C_COMPILE_FLAGS "${MRN_C_COMPILE_FLAGS} ${flag}")
endif()
endmacro()
macro(mrn_check_cxxflag flag)
string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag})
string(TOUPPER "${temporary_variable_name}" temporary_variable_name)
set(temporary_variable_name "CXXFLAG${temporary_variable_name}")
check_cxx_compiler_flag(${flag} ${temporary_variable_name})
if(${temporary_variable_name})
set(MRN_CXX_COMPILE_FLAGS "${MRN_CXX_COMPILE_FLAGS} ${flag}")
endif()
endmacro()
macro(mrn_build_flag flag)
mrn_check_cflag(${flag})
mrn_check_cxxflag(${flag})
endmacro()
if(MRN_BUNDLED)
set(MRN_RELATIVE_DIR_PREFIX "${MRN_SOURCE_DIR}/")
else()
......@@ -360,19 +335,15 @@ else()
endif()
if(CMAKE_COMPILER_IS_GNUCXX)
mrn_build_flag("-Wall")
mrn_build_flag("-Wextra")
mrn_build_flag("-Wno-unused-parameter")
mrn_build_flag("-Wno-strict-aliasing")
mrn_build_flag("-Wno-deprecated")
mrn_check_cxxflag("-fno-implicit-templates")
if(("${MYSQL_VARIANT}" STREQUAL "MariaDB") OR
("${MYSQL_VARIANT}" STREQUAL "MySQL" AND
${MYSQL_VERSION} VERSION_LESS "5.7.0"))
mrn_check_cxxflag("-fno-exceptions")
mrn_check_cxxflag("-fno-rtti")
endif()
mrn_check_cxxflag("-felide-constructors")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wall")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wextra")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-parameter")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-strict-aliasing")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-deprecated")
MY_CHECK_AND_SET_COMPILER_FLAG("-fno-implicit-templates")
MY_CHECK_AND_SET_COMPILER_FLAG("-fno-exceptions")
MY_CHECK_AND_SET_COMPILER_FLAG("-fno-rtti")
MY_CHECK_AND_SET_COMPILER_FLAG("-felide-constructors")
endif()
set_source_files_properties(${MRN_SOURCES} PROPERTIES
COMPILE_FLAGS "${MYSQL_CFLAGS} ${MRN_CXX_COMPILE_FLAGS}")
......
......@@ -143,59 +143,34 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif()
macro(check_cflag flag)
string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag})
string(TOUPPER "${temporary_variable_name}" temporary_variable_name)
set(temporary_variable_name "CFLAG${temporary_variable_name}")
check_c_compiler_flag(${flag} ${temporary_variable_name})
if(${temporary_variable_name})
set(GRN_C_COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS} ${flag}")
endif()
endmacro()
macro(check_cxxflag flag)
string(REGEX REPLACE "[-=]" "_" temporary_variable_name ${flag})
string(TOUPPER "${temporary_variable_name}" temporary_variable_name)
set(temporary_variable_name "CXXFLAG${temporary_variable_name}")
check_cxx_compiler_flag(${flag} ${temporary_variable_name})
if(${temporary_variable_name})
set(GRN_CXX_COMPILE_FLAGS "${GRN_CXX_COMPILE_FLAGS} ${flag}")
endif()
endmacro()
macro(check_build_flag flag)
check_cflag(${flag})
check_cxxflag(${flag})
endmacro()
if(CMAKE_COMPILER_IS_GNUCXX)
check_build_flag("-Wall")
check_build_flag("-Wextra")
check_build_flag("-Wno-unused-but-set-variable")
check_build_flag("-Wno-unused-parameter")
check_build_flag("-Wno-sign-compare")
check_cflag("-Wno-pointer-sign")
check_build_flag("-Wno-missing-field-initializers")
check_build_flag("-Wformat=2")
check_build_flag("-Wstrict-aliasing=2")
check_build_flag("-fno-strict-aliasing")
check_build_flag("-Wdisabled-optimization")
check_build_flag("-Wfloat-equal")
check_build_flag("-Wpointer-arith")
check_cflag("-Wdeclaration-after-statement")
check_cflag("-Wbad-function-cast")
check_build_flag("-Wcast-align")
# check_build_flag("-Wredundant-decls")
check_build_flag("-Wwrite-strings")
check_cxxflag("-fexceptions")
check_cxxflag("-fimplicit-templates")
check_build_flag("-Wno-clobbered")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wall")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wextra")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-but-set-variable")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-unused-parameter")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-sign-compare")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-pointer-sign")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-missing-field-initializers")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wformat=2")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wstrict-aliasing=2")
MY_CHECK_AND_SET_COMPILER_FLAG("-fno-strict-aliasing")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wdisabled-optimization")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wfloat-equal")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wpointer-arith")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wdeclaration-after-statement")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wbad-function-cast")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wcast-align")
#MY_CHECK_AND_SET_COMPILER_FLAG("-Wredundant-decls")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wwrite-strings")
MY_CHECK_AND_SET_COMPILER_FLAG("-fexceptions")
MY_CHECK_AND_SET_COMPILER_FLAG("-fimplicit-templates")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-clobbered")
endif()
if(NOT DEFINED CMAKE_C_COMPILE_OPTIONS_PIC)
# For old CMake
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGCXX)
check_build_flag("-fPIC")
MY_CHECK_AND_SET_COMPILER_FLAG("-fPIC")
endif()
endif()
......
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_HANDLERSOCKET")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_HANDLERSOCKET")
IF(HAVE_WVLA)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-vla")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wno-vla")
ENDIF()
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-vla" DEBUG)
SET(SPIDER_SOURCES
spd_param.cc spd_sys_table.cc spd_trx.cc spd_db_conn.cc spd_conn.cc
......
......@@ -17,12 +17,8 @@ IF(NOT LIBJEMALLOC)
MESSAGE(WARNING "TokuDB is enabled, but jemalloc is not. This configuration is not supported")
ENDIF()
IF (HAVE_WVLA)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-vla")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-vla")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wno-vla")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-vla")
ENDIF()
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-vla")
MY_CHECK_AND_SET_COMPILER_FLAG("-Wno-vla" DEBUG)
############################################
SET(TOKUDB_DEB_FILES "usr/lib/mysql/plugin/ha_tokudb.so\netc/mysql/conf.d/tokudb.cnf\nusr/bin/tokuftdump\nusr/share/doc/mariadb-server-10.1/README-TOKUDB\nusr/share/doc/mariadb-server-10.1/README.md" PARENT_SCOPE)
......@@ -70,36 +66,7 @@ ENDIF()
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
macro(set_cflags_if_supported)
foreach(flag ${ARGN})
string(REGEX REPLACE "-" "_" temp_flag ${flag})
check_c_compiler_flag(${flag} HAVE_C_${temp_flag})
if (HAVE_C_${temp_flag})
set(CMAKE_C_FLAGS "${flag} ${CMAKE_C_FLAGS}")
endif ()
check_cxx_compiler_flag(${flag} HAVE_CXX_${temp_flag})
if (HAVE_CXX_${temp_flag})
set(CMAKE_CXX_FLAGS "${flag} ${CMAKE_CXX_FLAGS}")
endif ()
endforeach(flag)
endmacro(set_cflags_if_supported)
macro(append_cflags_if_supported)
foreach(flag ${ARGN})
string(REGEX REPLACE "-" "_" temp_flag ${flag})
check_c_compiler_flag(${flag} HAVE_C_${temp_flag})
if (HAVE_C_${temp_flag})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
endif ()
check_cxx_compiler_flag(${flag} HAVE_CXX_${temp_flag})
if (HAVE_CXX_${temp_flag})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
endif ()
endforeach(flag)
endmacro(append_cflags_if_supported)
set_cflags_if_supported(-Wno-missing-field-initializers)
append_cflags_if_supported(-Wno-vla)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-missing-field-initializers)
ADD_SUBDIRECTORY(ft-index)
......
......@@ -46,18 +46,6 @@ endif (USE_GCOV)
include(CheckCCompilerFlag)
include(CheckCXXCompilerFlag)
## adds a compiler flag if the compiler supports it
macro(set_cflags_if_supported_named flag flagname)
check_c_compiler_flag("${flag}" HAVE_C_${flagname})
if (HAVE_C_${flagname})
set(CMAKE_C_FLAGS "${flag} ${CMAKE_C_FLAGS}")
endif ()
check_cxx_compiler_flag("${flag}" HAVE_CXX_${flagname})
if (HAVE_CXX_${flagname})
set(CMAKE_CXX_FLAGS "${flag} ${CMAKE_CXX_FLAGS}")
endif ()
endmacro(set_cflags_if_supported_named)
## adds a compiler flag if the compiler supports it
macro(set_cflags_if_supported)
foreach(flag ${ARGN})
......@@ -84,21 +72,19 @@ macro(set_ldflags_if_supported)
endmacro(set_ldflags_if_supported)
## disable some warnings
set_cflags_if_supported(
-Wno-missing-field-initializers
-Wstrict-null-sentinel
-Winit-self
-Wswitch
-Wtrampolines
-Wlogical-op
-Wmissing-format-attribute
-Wno-error=missing-format-attribute
-Wno-error=address-of-array-temporary
-Wno-error=tautological-constant-out-of-range-compare
-Wno-ignored-attributes
-fno-rtti
-fno-exceptions
)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-missing-field-initializers)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wstrict-null-sentinel)
MY_CHECK_AND_SET_COMPILER_FLAG(-Winit-self)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wswitch)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wtrampolines)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wlogical-op)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wmissing-format-attribute)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-error=missing-format-attribute)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-error=address-of-array-temporary)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-error=tautological-constant-out-of-range-compare)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-ignored-attributes)
MY_CHECK_AND_SET_COMPILER_FLAG(-fno-rtti)
MY_CHECK_AND_SET_COMPILER_FLAG(-fno-exceptions)
## set_cflags_if_supported_named("-Weffc++" -Weffcpp)
if (CMAKE_CXX_FLAGS MATCHES -fno-implicit-templates)
......@@ -111,19 +97,12 @@ endif()
## Clang has stricter POD checks. So, only enable this warning on our other builds (Linux + GCC)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES Clang)
set_cflags_if_supported(
-Wpacked
)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wpacked)
endif ()
## this hits with optimized builds somewhere in ftleaf_split, we don't
## know why but we don't think it's a big deal
set_cflags_if_supported(
-Wno-error=strict-overflow
)
set_ldflags_if_supported(
-Wno-error=strict-overflow
)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-error=strict-overflow)
## set extra debugging flags and preprocessor definitions
set(CMAKE_C_FLAGS_DEBUG "-g3 -O0 ${CMAKE_C_FLAGS_DEBUG}")
......@@ -154,16 +133,15 @@ else ()
endif ()
## set warnings
set_cflags_if_supported(
-Wextra
-Wbad-function-cast
-Wno-missing-noreturn
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
-Wpointer-arith
-Wmissing-format-attribute
-Wshadow
MY_CHECK_AND_SET_COMPILER_FLAG(-Wextra)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wbad-function-cast)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wno-missing-noreturn)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wstrict-prototypes)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wmissing-prototypes)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wmissing-declarations)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wpointer-arith)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wmissing-format-attribute)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wshadow)
## other flags to try:
#-Wunsafe-loop-optimizations
#-Wpointer-arith
......@@ -173,11 +151,10 @@ set_cflags_if_supported(
#-Wzero-as-null-pointer-constant
#-Wlogical-op
#-Wvector-optimization-performance
)
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL Clang)
# Disabling -Wcast-align with clang. TODO: fix casting and re-enable it, someday.
set_cflags_if_supported(-Wcast-align)
MY_CHECK_AND_SET_COMPILER_FLAG(-Wcast-align)
endif ()
## always want these
......
......@@ -462,14 +462,6 @@ SET(INNOBASE_SOURCES
ut/ut0wqueue.cc
ut/ut0timer.cc)
# These files have unused result errors, so we skip Werror
CHECK_C_COMPILER_FLAG("-Werror" HAVE_WERROR)
IF(HAVE_WERROR)
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
ADD_COMPILE_FLAGS(page/page0zip.c COMPILE_FLAGS "-Wno-error")
ADD_COMPILE_FLAGS(ut/ut0ut.c COMPILE_FLAGS "-Wno-error")
ENDIF()
IF(XTRADB_OK)
MYSQL_ADD_PLUGIN(xtradb ${INNOBASE_SOURCES} STORAGE_ENGINE
DEFAULT RECOMPILE_FOR_EMBEDDED
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment