| 1 |
# HandleLibcxxFlags - A set of macros used to setup the flags used to compile |
| 2 |
# and link libc++abi. These macros add flags to the following CMake variables. |
| 3 |
# - LIBCXXABI_COMPILE_FLAGS: flags used to compile libc++abi |
| 4 |
# - LIBCXXABI_LINK_FLAGS: flags used to link libc++abi |
| 5 |
# - LIBCXXABI_LIBRARIES: libraries to link libc++abi to. |
| 6 |
|
| 7 |
include(CheckCXXCompilerFlag) |
| 8 |
include(HandleFlags) |
| 9 |
|
| 10 |
unset(add_flag_if_supported) |
| 11 |
|
| 12 |
# Add a specified list of flags to both 'LIBCXXABI_COMPILE_FLAGS' and |
| 13 |
# 'LIBCXXABI_LINK_FLAGS'. |
| 14 |
macro(add_flags) |
| 15 |
foreach(value ${ARGN}) |
| 16 |
list(APPEND LIBCXXABI_COMPILE_FLAGS ${value}) |
| 17 |
list(APPEND LIBCXXABI_LINK_FLAGS ${value}) |
| 18 |
endforeach() |
| 19 |
endmacro() |
| 20 |
|
| 21 |
# If the specified 'condition' is true then add a list of flags to both |
| 22 |
# 'LIBCXXABI_COMPILE_FLAGS' and 'LIBCXXABI_LINK_FLAGS'. |
| 23 |
macro(add_flags_if condition) |
| 24 |
if (${condition}) |
| 25 |
add_flags(${ARGN}) |
| 26 |
endif() |
| 27 |
endmacro() |
| 28 |
|
| 29 |
# Add each flag in the list to LIBCXXABI_COMPILE_FLAGS and LIBCXXABI_LINK_FLAGS |
| 30 |
# if that flag is supported by the current compiler. |
| 31 |
macro(add_flags_if_supported) |
| 32 |
foreach(flag ${ARGN}) |
| 33 |
mangle_name("${flag}" flagname) |
| 34 |
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") |
| 35 |
add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag}) |
| 36 |
endforeach() |
| 37 |
endmacro() |
| 38 |
|
| 39 |
# Add a list of flags to 'LIBCXXABI_COMPILE_FLAGS'. |
| 40 |
macro(add_compile_flags) |
| 41 |
foreach(f ${ARGN}) |
| 42 |
list(APPEND LIBCXXABI_COMPILE_FLAGS ${f}) |
| 43 |
endforeach() |
| 44 |
endmacro() |
| 45 |
|
| 46 |
# If 'condition' is true then add the specified list of flags to |
| 47 |
# 'LIBCXXABI_COMPILE_FLAGS' |
| 48 |
macro(add_compile_flags_if condition) |
| 49 |
if (${condition}) |
| 50 |
add_compile_flags(${ARGN}) |
| 51 |
endif() |
| 52 |
endmacro() |
| 53 |
|
| 54 |
# For each specified flag, add that flag to 'LIBCXXABI_COMPILE_FLAGS' if the |
| 55 |
# flag is supported by the C++ compiler. |
| 56 |
macro(add_compile_flags_if_supported) |
| 57 |
foreach(flag ${ARGN}) |
| 58 |
mangle_name("${flag}" flagname) |
| 59 |
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") |
| 60 |
add_compile_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag}) |
| 61 |
endforeach() |
| 62 |
endmacro() |
| 63 |
|
| 64 |
# For each specified flag, add that flag to 'LIBCXXABI_COMPILE_FLAGS' if the |
| 65 |
# flag is supported by the C compiler. |
| 66 |
macro(add_c_compile_flags_if_supported) |
| 67 |
foreach(flag ${ARGN}) |
| 68 |
mangle_name("${flag}" flagname) |
| 69 |
check_c_compiler_flag("${flag}" "C_SUPPORTS_${flagname}_FLAG") |
| 70 |
add_compile_flags_if(C_SUPPORTS_${flagname}_FLAG ${flag}) |
| 71 |
endforeach() |
| 72 |
endmacro() |
| 73 |
|
| 74 |
# Add a list of flags to 'LIBCXXABI_LINK_FLAGS'. |
| 75 |
macro(add_link_flags) |
| 76 |
foreach(f ${ARGN}) |
| 77 |
list(APPEND LIBCXXABI_LINK_FLAGS ${f}) |
| 78 |
endforeach() |
| 79 |
endmacro() |
| 80 |
|
| 81 |
# If 'condition' is true then add the specified list of flags to |
| 82 |
# 'LIBCXXABI_LINK_FLAGS' |
| 83 |
macro(add_link_flags_if condition) |
| 84 |
if (${condition}) |
| 85 |
add_link_flags(${ARGN}) |
| 86 |
endif() |
| 87 |
endmacro() |
| 88 |
|
| 89 |
# For each specified flag, add that flag to 'LIBCXXABI_LINK_FLAGS' if the |
| 90 |
# flag is supported by the C++ compiler. |
| 91 |
macro(add_link_flags_if_supported) |
| 92 |
foreach(flag ${ARGN}) |
| 93 |
mangle_name("${flag}" flagname) |
| 94 |
check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") |
| 95 |
add_link_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag}) |
| 96 |
endforeach() |
| 97 |
endmacro() |
| 98 |
|
| 99 |
# Add a list of libraries or link flags to 'LIBCXXABI_LIBRARIES'. |
| 100 |
macro(add_library_flags) |
| 101 |
foreach(lib ${ARGN}) |
| 102 |
list(APPEND LIBCXXABI_LIBRARIES ${lib}) |
| 103 |
endforeach() |
| 104 |
endmacro() |
| 105 |
|
| 106 |
# if 'condition' is true then add the specified list of libraries and flags |
| 107 |
# to 'LIBCXXABI_LIBRARIES'. |
| 108 |
macro(add_library_flags_if condition) |
| 109 |
if(${condition}) |
| 110 |
add_library_flags(${ARGN}) |
| 111 |
endif() |
| 112 |
endmacro() |