• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Convenience function that checks the availability of certain
2# C or C++ compiler flags and returns valid ones as a string.
3
4include(CheckCCompilerFlag)
5include(CheckCXXCompilerFlag)
6
7function(extract_valid_c_flags varname)
8  set(valid_flags)
9  foreach(flag IN LISTS ARGN)
10    string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
11    set(flag_var "C_FLAG_${flag_var}")
12    check_c_compiler_flag("${flag}" "${flag_var}")
13    if(${flag_var})
14      set(valid_flags "${valid_flags} ${flag}")
15    endif()
16  endforeach()
17  set(${varname} "${valid_flags}" PARENT_SCOPE)
18endfunction()
19
20function(extract_valid_cxx_flags varname)
21  set(valid_flags)
22  foreach(flag IN LISTS ARGN)
23    string(REGEX REPLACE "[^a-zA-Z0-9_]+" "_" flag_var ${flag})
24    set(flag_var "CXX_FLAG_${flag_var}")
25    check_cxx_compiler_flag("${flag}" "${flag_var}")
26    if(${flag_var})
27      set(valid_flags "${valid_flags} ${flag}")
28    endif()
29  endforeach()
30  set(${varname} "${valid_flags}" PARENT_SCOPE)
31endfunction()
32