110ed6c36SEric Fiselier# HandleLibcxxFlags - A set of macros used to setup the flags used to compile 210ed6c36SEric Fiselier# and link libc++. These macros add flags to the following CMake variables. 310ed6c36SEric Fiselier# - LIBCXX_COMPILE_FLAGS: flags used to compile libc++ 410ed6c36SEric Fiselier# - LIBCXX_LINK_FLAGS: flags used to link libc++ 510ed6c36SEric Fiselier# - LIBCXX_LIBRARIES: libraries to link libc++ to. 610ed6c36SEric Fiselier 710ed6c36SEric Fiselierinclude(CheckCXXCompilerFlag) 8*0af67d16SNikolas Klauserinclude(HandleFlags) 910ed6c36SEric Fiselier 1010ed6c36SEric Fiselierunset(add_flag_if_supported) 1110ed6c36SEric Fiselier 1210ed6c36SEric Fiselier# Add a specified list of flags to both 'LIBCXX_COMPILE_FLAGS' and 1310ed6c36SEric Fiselier# 'LIBCXX_LINK_FLAGS'. 1410ed6c36SEric Fiseliermacro(add_flags) 1510ed6c36SEric Fiselier foreach(value ${ARGN}) 1610ed6c36SEric Fiselier list(APPEND LIBCXX_COMPILE_FLAGS ${value}) 1710ed6c36SEric Fiselier list(APPEND LIBCXX_LINK_FLAGS ${value}) 1810ed6c36SEric Fiselier endforeach() 1910ed6c36SEric Fiselierendmacro() 2010ed6c36SEric Fiselier 2110ed6c36SEric Fiselier# If the specified 'condition' is true then add a list of flags to both 2210ed6c36SEric Fiselier# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'. 2310ed6c36SEric Fiseliermacro(add_flags_if condition) 2410ed6c36SEric Fiselier if (${condition}) 2510ed6c36SEric Fiselier add_flags(${ARGN}) 2610ed6c36SEric Fiselier endif() 2710ed6c36SEric Fiselierendmacro() 2810ed6c36SEric Fiselier 2910ed6c36SEric Fiselier# Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_LINK_FLAGS 3010ed6c36SEric Fiselier# if that flag is supported by the current compiler. 3110ed6c36SEric Fiseliermacro(add_flags_if_supported) 3210ed6c36SEric Fiselier foreach(flag ${ARGN}) 3310ed6c36SEric Fiselier mangle_name("${flag}" flagname) 34b3df14b6SPetr Hosek check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") 35b3df14b6SPetr Hosek add_flags_if(CXX_SUPPORTS_${flagname}_FLAG ${flag}) 3610ed6c36SEric Fiselier endforeach() 3710ed6c36SEric Fiselierendmacro() 3810ed6c36SEric Fiselier 3910ed6c36SEric Fiselier# Add a list of flags to 'LIBCXX_LINK_FLAGS'. 4010ed6c36SEric Fiseliermacro(add_link_flags) 4110ed6c36SEric Fiselier foreach(f ${ARGN}) 4210ed6c36SEric Fiselier list(APPEND LIBCXX_LINK_FLAGS ${f}) 4310ed6c36SEric Fiselier endforeach() 4410ed6c36SEric Fiselierendmacro() 4510ed6c36SEric Fiselier 4610ed6c36SEric Fiselier# Add a list of libraries or link flags to 'LIBCXX_LIBRARIES'. 4710ed6c36SEric Fiseliermacro(add_library_flags) 4810ed6c36SEric Fiselier foreach(lib ${ARGN}) 4910ed6c36SEric Fiselier list(APPEND LIBCXX_LIBRARIES ${lib}) 5010ed6c36SEric Fiselier endforeach() 5110ed6c36SEric Fiselierendmacro() 5210ed6c36SEric Fiselier 5310ed6c36SEric Fiselier# if 'condition' is true then add the specified list of libraries and flags 5410ed6c36SEric Fiselier# to 'LIBCXX_LIBRARIES'. 5510ed6c36SEric Fiseliermacro(add_library_flags_if condition) 5610ed6c36SEric Fiselier if(${condition}) 5710ed6c36SEric Fiselier add_library_flags(${ARGN}) 5810ed6c36SEric Fiselier endif() 5910ed6c36SEric Fiselierendmacro() 6010ed6c36SEric Fiselier 6168924e6bSLouis Dionne# For each specified flag, add that link flag to the provided target. 6268924e6bSLouis Dionne# The flags are added with the given visibility, i.e. PUBLIC|PRIVATE|INTERFACE. 6368924e6bSLouis Dionnefunction(target_add_link_flags_if_supported target visibility) 6468924e6bSLouis Dionne foreach(flag ${ARGN}) 6568924e6bSLouis Dionne mangle_name("${flag}" flagname) 66b3df14b6SPetr Hosek check_cxx_compiler_flag("${flag}" "CXX_SUPPORTS_${flagname}_FLAG") 67b3df14b6SPetr Hosek if (CXX_SUPPORTS_${flagname}_FLAG) 6868924e6bSLouis Dionne target_link_libraries(${target} ${visibility} ${flag}) 6968924e6bSLouis Dionne endif() 7068924e6bSLouis Dionne endforeach() 7168924e6bSLouis Dionneendfunction() 72