aboutsummaryrefslogtreecommitdiff
path: root/tools/rasm/apultra-master/src/libdivsufsort/CMakeModules/AppendCompilerFlags.cmake
blob: 58d3f99ec2bbcefc1d2f6a01bf3831324ea462f2 (plain)
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
include(CheckCSourceCompiles)
include(CheckCXXSourceCompiles)

macro(append_c_compiler_flags _flags _name _result)
  set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  string(REGEX REPLACE "[-+/ ]" "_" cname "${_name}")
  string(TOUPPER "${cname}" cname)
  foreach(flag ${_flags})
    string(REGEX REPLACE "^[-+/ ]+(.*)[-+/ ]*$" "\\1" flagname "${flag}")
    string(REGEX REPLACE "[-+/ ]" "_" flagname "${flagname}")
    string(TOUPPER "${flagname}" flagname)
    set(have_flag "HAVE_${cname}_${flagname}")
    set(CMAKE_REQUIRED_FLAGS "${flag}")
    check_c_source_compiles("int main() { return 0; }" ${have_flag})
    if(${have_flag})
      set(${_result} "${${_result}} ${flag}")
    endif(${have_flag})
  endforeach(flag)
  set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
endmacro(append_c_compiler_flags)

macro(append_cxx_compiler_flags _flags _name _result)
  set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  string(REGEX REPLACE "[-+/ ]" "_" cname "${_name}")
  string(TOUPPER "${cname}" cname)
  foreach(flag ${_flags})
    string(REGEX REPLACE "^[-+/ ]+(.*)[-+/ ]*$" "\\1" flagname "${flag}")
    string(REGEX REPLACE "[-+/ ]" "_" flagname "${flagname}")
    string(TOUPPER "${flagname}" flagname)
    set(have_flag "HAVE_${cname}_${flagname}")
    set(CMAKE_REQUIRED_FLAGS "${flag}")
    check_cxx_source_compiles("int main() { return 0; }" ${have_flag})
    if(${have_flag})
      set(${_result} "${${_result}} ${flag}")
    endif(${have_flag})
  endforeach(flag)
  set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS})
endmacro(append_cxx_compiler_flags)