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.
7 include(CheckCXXCompilerFlag)
10 unset(add_flag_if_supported)
12 # Add a specified list of flags to both 'LIBCXXABI_COMPILE_FLAGS' and
13 # 'LIBCXXABI_LINK_FLAGS'.
15 foreach(value ${ARGN})
16 list(APPEND LIBCXXABI_COMPILE_FLAGS ${value})
17 list(APPEND LIBCXXABI_LINK_FLAGS ${value})
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)
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)
33 mangle_name("${flag}" flagname)
34 check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
35 add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag})
39 # Add a list of flags to 'LIBCXXABI_COMPILE_FLAGS'.
40 macro(add_compile_flags)
42 list(APPEND LIBCXXABI_COMPILE_FLAGS ${f})
46 # If 'condition' is true then add the specified list of flags to
47 # 'LIBCXXABI_COMPILE_FLAGS'
48 macro(add_compile_flags_if condition)
50 add_compile_flags(${ARGN})
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)
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})
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)
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})
74 # Add a list of flags to 'LIBCXXABI_LINK_FLAGS'.
77 list(APPEND LIBCXXABI_LINK_FLAGS ${f})
81 # If 'condition' is true then add the specified list of flags to
82 # 'LIBCXXABI_LINK_FLAGS'
83 macro(add_link_flags_if condition)
85 add_link_flags(${ARGN})
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)
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})
99 # Add a list of libraries or link flags to 'LIBCXXABI_LIBRARIES'.
100 macro(add_library_flags)
102 list(APPEND LIBCXXABI_LIBRARIES ${lib})
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)
110 add_library_flags(${ARGN})