1include(CheckCSourceCompiles) 2include(CheckCXXSourceCompiles) 3 4macro(append_c_compiler_flags _flags _name _result) 5 set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) 6 string(REGEX REPLACE "[-+/ ]" "_" cname "${_name}") 7 string(TOUPPER "${cname}" cname) 8 foreach(flag ${_flags}) 9 string(REGEX REPLACE "^[-+/ ]+(.*)[-+/ ]*$" "\\1" flagname "${flag}") 10 string(REGEX REPLACE "[-+/ ]" "_" flagname "${flagname}") 11 string(TOUPPER "${flagname}" flagname) 12 set(have_flag "HAVE_${cname}_${flagname}") 13 set(CMAKE_REQUIRED_FLAGS "${flag}") 14 check_c_source_compiles("int main() { return 0; }" ${have_flag}) 15 if(${have_flag}) 16 set(${_result} "${${_result}} ${flag}") 17 endif(${have_flag}) 18 endforeach(flag) 19 set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS}) 20endmacro(append_c_compiler_flags) 21 22macro(append_cxx_compiler_flags _flags _name _result) 23 set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) 24 string(REGEX REPLACE "[-+/ ]" "_" cname "${_name}") 25 string(TOUPPER "${cname}" cname) 26 foreach(flag ${_flags}) 27 string(REGEX REPLACE "^[-+/ ]+(.*)[-+/ ]*$" "\\1" flagname "${flag}") 28 string(REGEX REPLACE "[-+/ ]" "_" flagname "${flagname}") 29 string(TOUPPER "${flagname}" flagname) 30 set(have_flag "HAVE_${cname}_${flagname}") 31 set(CMAKE_REQUIRED_FLAGS "${flag}") 32 check_cxx_source_compiles("int main() { return 0; }" ${have_flag}) 33 if(${have_flag}) 34 set(${_result} "${${_result}} ${flag}") 35 endif(${have_flag}) 36 endforeach(flag) 37 set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS}) 38endmacro(append_cxx_compiler_flags) 39