cmake: Move cxx flag testing/setup into its own file.
- Move CXX flags stuff into build/cxx_flags.cmake. - include CMake modules where they're used. - Add ENABLE_WERROR flag-- enables warnings as errors. - Add -Wshorten-64-to-32 and -Wnarrowing to CXX flags. Change-Id: I5d93a39a3eff6ae81f9e094927b8f0cb9f36bbb0
This commit is contained in:
parent
2aee04fb23
commit
f47cbd50e9
@ -7,10 +7,8 @@
|
||||
## be found in the AUTHORS file in the root of the source tree.
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(LIBWEBM CXX)
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/build/msvc_runtime.cmake")
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckCXXSourceCompiles)
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/build/msvc_runtime.cmake")
|
||||
|
||||
set(LIBWEBM_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
@ -18,27 +16,18 @@ set(LIBWEBM_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
option(ENABLE_WEBMTS "Enables WebM PES/TS support." ON)
|
||||
option(ENABLE_TESTS "Enables tests." OFF)
|
||||
option(ENABLE_IWYU "Enables include-what-you-use support." OFF)
|
||||
option(ENABLE_WERROR "Enable warnings as errors." OFF)
|
||||
set(GTEST_SRC_DIR "${LIBWEBM_SRC_DIR}/../googletest" CACHE PATH
|
||||
"Path to Googletest git repository.")
|
||||
|
||||
# This directory is where libwebm will build googletest dependencies.
|
||||
set(GTEST_BUILD_DIR "${CMAKE_BINARY_DIR}/googletest_build")
|
||||
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/build/cxx_flags.cmake")
|
||||
if (ENABLE_TESTS OR ENABLE_WEBMTS)
|
||||
include("${CMAKE_CURRENT_SOURCE_DIR}/build/cxx11_tests.cmake")
|
||||
endif ()
|
||||
|
||||
# Set warning levels.
|
||||
if (MSVC)
|
||||
set(CMAKE_CXX_FLAGS "/W4 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
|
||||
# Disable MSVC warnings that suggest making code non-portable.
|
||||
set(CMAKE_CXX_FLAGS "/wd4996 ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
|
||||
else ()
|
||||
set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
|
||||
set(CMAKE_CXX_FLAGS "-Wno-deprecated ${CMAKE_CXX_FLAGS}" CACHE
|
||||
STRING "" FORCE)
|
||||
endif ()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-D__STDC_CONSTANT_MACROS ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-D__STDC_FORMAT_MACROS ${CMAKE_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "-D__STDC_LIMIT_MACROS ${CMAKE_CXX_FLAGS}")
|
||||
@ -201,4 +190,3 @@ if (ENABLE_IWYU)
|
||||
message(STATUS " See README.libwebm for more information.")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
|
@ -7,6 +7,9 @@
|
||||
## be found in the AUTHORS file in the root of the source tree.
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckCXXSourceCompiles)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR
|
||||
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR
|
||||
CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
@ -134,5 +137,3 @@ if (NOT HAVE_UNIQUE_PTR
|
||||
set(ENABLE_WEBMTS OFF)
|
||||
message(WARNING "C++11 feature(s) not supported, tests and webmts disabled.")
|
||||
endif ()
|
||||
|
||||
|
||||
|
37
build/cxx_flags.cmake
Normal file
37
build/cxx_flags.cmake
Normal file
@ -0,0 +1,37 @@
|
||||
## Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
||||
##
|
||||
## Use of this source code is governed by a BSD-style license
|
||||
## that can be found in the LICENSE file in the root of the source
|
||||
## tree. An additional intellectual property rights grant can be found
|
||||
## in the file PATENTS. All contributing project authors may
|
||||
## be found in the AUTHORS file in the root of the source tree.
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
|
||||
function (add_cxx_flag_if_supported cxx_flag)
|
||||
unset(FLAG_SUPPORTED CACHE)
|
||||
CHECK_CXX_COMPILER_FLAG("${cxx_flag}" FLAG_SUPPORTED)
|
||||
if (FLAG_SUPPORTED)
|
||||
set(CMAKE_CXX_FLAGS "${cxx_flag} ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE)
|
||||
endif ()
|
||||
endfunction ()
|
||||
|
||||
# Set warning levels.
|
||||
if (MSVC)
|
||||
add_cxx_flag_if_supported("/W4")
|
||||
# Disable MSVC warnings that suggest making code non-portable.
|
||||
add_cxx_flag_if_supported("/wd4996")
|
||||
if (ENABLE_WERROR)
|
||||
add_cxx_flag_if_supported("/WX")
|
||||
endif ()
|
||||
else ()
|
||||
add_cxx_flag_if_supported("-Wall")
|
||||
add_cxx_flag_if_supported("-Wextra")
|
||||
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 ()
|
||||
endif ()
|
Loading…
x
Reference in New Issue
Block a user