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.
This commit is contained in:
Sergei Golubchik 2015-09-01 21:58:10 +02:00
commit e74f91dfd7
9 changed files with 73 additions and 190 deletions

View file

@ -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()