cmake: Cache results of CXX flag tests.
Avoid re-testing to improve cmake build and regen speed. Change-Id: I8e2fe6601036cc7d176cdc3738616261a2da408b
This commit is contained in:
parent
81c73fc78e
commit
54f155986d
@ -9,16 +9,32 @@ cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
# String used to cache failed CXX flags.
|
||||
set(LIBWEBM_FAILED_CXX_FLAGS)
|
||||
|
||||
# Checks C++ compiler for support of $cxx_flag. Adds $cxx_flag to
|
||||
# $CMAKE_CXX_FLAGS when the compile test passes. Caches $c_flag in
|
||||
# $LIBWEBM_FAILED_CXX_FLAGS when the test fails.
|
||||
function (add_cxx_flag_if_supported cxx_flag)
|
||||
unset(FLAG_SUPPORTED CACHE)
|
||||
message("Checking compiler flag support for: " ${cxx_flag})
|
||||
CHECK_CXX_COMPILER_FLAG("${cxx_flag}" FLAG_SUPPORTED)
|
||||
if (FLAG_SUPPORTED)
|
||||
set(CMAKE_CXX_FLAGS "${cxx_flag} ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
|
||||
unset(CXX_FLAG_FOUND CACHE)
|
||||
string(FIND "${CMAKE_CXX_FLAGS}" "${cxx_flag}" CXX_FLAG_FOUND)
|
||||
unset(CXX_FLAG_FAILED CACHE)
|
||||
string(FIND "${LIBWEBM_FAILED_CXX_FLAGS}" "${cxx_flag}" CXX_FLAG_FAILED)
|
||||
|
||||
if (${CXX_FLAG_FOUND} EQUAL -1 AND ${CXX_FLAG_FAILED} EQUAL -1)
|
||||
unset(CXX_FLAG_SUPPORTED CACHE)
|
||||
message("Checking CXX compiler flag support for: " ${cxx_flag})
|
||||
check_cxx_compiler_flag("${cxx_flag}" CXX_FLAG_SUPPORTED)
|
||||
if (CXX_FLAG_SUPPORTED)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${cxx_flag}" CACHE STRING ""
|
||||
FORCE)
|
||||
else ()
|
||||
set(LIBWEBM_FAILED_CXX_FLAGS "${LIBWEBM_FAILED_CXX_FLAGS} ${cxx_flag}"
|
||||
CACHE STRING "" FORCE)
|
||||
endif ()
|
||||
endif ()
|
||||
endfunction ()
|
||||
|
||||
# Set warning levels.
|
||||
if (MSVC)
|
||||
add_cxx_flag_if_supported("/W4")
|
||||
# Disable MSVC warnings that suggest making code non-portable.
|
||||
@ -29,9 +45,9 @@ if (MSVC)
|
||||
else ()
|
||||
add_cxx_flag_if_supported("-Wall")
|
||||
add_cxx_flag_if_supported("-Wextra")
|
||||
add_cxx_flag_if_supported("-Wnarrowing")
|
||||
add_cxx_flag_if_supported("-Wno-deprecated")
|
||||
add_cxx_flag_if_supported("-Wshorten-64-to-32")
|
||||
add_cxx_flag_if_supported("-Wnarrowing")
|
||||
if (ENABLE_WERROR)
|
||||
add_cxx_flag_if_supported("-Werror")
|
||||
endif ()
|
||||
|
Loading…
x
Reference in New Issue
Block a user