2014-07-31 22:20:20 +08:00
|
|
|
# - Adds a compiler flag if it is supported by the compiler
|
2014-08-01 21:24:56 +08:00
|
|
|
#
|
2014-07-31 22:20:20 +08:00
|
|
|
# This function checks that the supplied compiler flag is supported and then
|
|
|
|
# adds it to the corresponding compiler flags
|
2014-08-01 21:24:56 +08:00
|
|
|
#
|
2014-07-31 22:20:20 +08:00
|
|
|
# add_cxx_compiler_flag(<FLAG> [<VARIANT>])
|
2014-08-01 21:24:56 +08:00
|
|
|
#
|
|
|
|
# - Example
|
|
|
|
#
|
|
|
|
# include(AddCXXCompilerFlag)
|
2014-07-31 22:20:20 +08:00
|
|
|
# add_cxx_compiler_flag(-Wall)
|
|
|
|
# add_cxx_compiler_flag(-no-strict-aliasing RELEASE)
|
2014-08-01 21:24:56 +08:00
|
|
|
# Requires CMake 2.6+
|
|
|
|
|
2014-07-31 22:20:20 +08:00
|
|
|
if(__add_cxx_compiler_flag)
|
2014-08-01 21:24:56 +08:00
|
|
|
return()
|
|
|
|
endif()
|
2014-07-31 22:20:20 +08:00
|
|
|
set(__add_cxx_compiler_flag INCLUDED)
|
2014-08-01 21:24:56 +08:00
|
|
|
|
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
|
|
|
function(add_cxx_compiler_flag FLAG)
|
|
|
|
if(ARGV1)
|
|
|
|
set(VARIANT ${ARGV1})
|
|
|
|
string(TOLOWER ${VARIANT} VARIANT)
|
|
|
|
set(VARIANT " ${VARIANT}")
|
|
|
|
endif()
|
2014-08-22 21:36:19 +08:00
|
|
|
string(TOUPPER "HAVE_${FLAG}" SANITIZED_FLAG)
|
|
|
|
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
|
|
|
|
string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
|
2014-08-01 21:24:56 +08:00
|
|
|
check_cxx_compiler_flag(${FLAG} ${SANITIZED_FLAG})
|
|
|
|
if(${SANITIZED_FLAG})
|
2014-08-22 21:36:19 +08:00
|
|
|
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" VARIANT "${VARIANT}")
|
2014-08-01 21:24:56 +08:00
|
|
|
string(TOUPPER "${VARIANT}" VARIANT)
|
2014-10-12 06:13:00 +08:00
|
|
|
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
|
2014-08-01 21:24:56 +08:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|