1 # HandleLibcxxFlags - A set of macros used to setup the flags used to compile
2 # and link libc++. These macros add flags to the following CMake variables.
3 # - LIBCXX_COMPILE_FLAGS: flags used to compile libc++
4 # - LIBCXX_LINK_FLAGS: flags used to link libc++
5 # - LIBCXX_LIBRARIES: libraries to link libc++ to.
7 include(CheckCXXCompilerFlag)
10 unset(add_flag_if_supported)
12 # Add a specified list of flags to both 'LIBCXX_COMPILE_FLAGS' and
13 # 'LIBCXX_LINK_FLAGS'.
15 foreach(value ${ARGN})
16 list(APPEND LIBCXX_COMPILE_FLAGS ${value})
17 list(APPEND LIBCXX_LINK_FLAGS ${value})
21 # If the specified 'condition' is true then add a list of flags to both
22 # 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'.
23 macro(add_flags_if condition)
29 # Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_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 'LIBCXX_LINK_FLAGS'.
42 list(APPEND LIBCXX_LINK_FLAGS ${f})
46 # Add a list of libraries or link flags to 'LIBCXX_LIBRARIES'.
47 macro(add_library_flags)
49 list(APPEND LIBCXX_LIBRARIES ${lib})
53 # if 'condition' is true then add the specified list of libraries and flags
54 # to 'LIBCXX_LIBRARIES'.
55 macro(add_library_flags_if condition)
57 add_library_flags(${ARGN})
61 # For each specified flag, add that link flag to the provided target.
62 # The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE.
63 function(target_add_link_flags_if_supported target visibility)
65 mangle_name("${flag}" flagname)
66 check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG")
67 if (CXX_SUPPORTS_${flagname}_FLAG)
68 target_link_libraries(${target} ${visibility} ${flag})