You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2018/03/19 20:20:40 UTC
[2/9] mesos git commit: CMake: Enabled compiler warnings.
CMake: Enabled compiler warnings.
We had previously been using the default sets of warnings, but now we
use the same warnings as on Autotools. This meant disabling two common
possible-loss-of-data warnings on Windows that are not part of the
GNU/Clang default warnings.
This also replaces the use of `string(APPEND CMAKE_CXX_FLAGS)` with
the canonical command `add_compile_options`. Although generally the
use of `target_compile_options` is preferred, it would currently
result in a lot more churn, and the build already supports setting
these flags globally.
Review: https://reviews.apache.org/r/66008
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5cb10176
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5cb10176
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5cb10176
Branch: refs/heads/master
Commit: 5cb1017617f90878fa9c26546ed0e73b74a74017
Parents: 0c18ca1
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Thu Mar 8 14:56:22 2018 -0800
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Mon Mar 19 12:34:06 2018 -0700
----------------------------------------------------------------------
cmake/CompilationConfigure.cmake | 50 ++++++++++++++++++++++++++---------
1 file changed, 37 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/5cb10176/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 9eab0d6..7419024 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -217,21 +217,46 @@ if (WIN32)
endif ()
endif ()
+# GLOBAL WARNINGS.
+##################
+if (CMAKE_CXX_COMPILER_ID MATCHES GNU
+ OR CMAKE_CXX_COMPILER_ID MATCHES Clang) # Also matches AppleClang.
+ # TODO(andschwa): Add `-Wextra`, `-Wpedantic`, `-Wconversion`.
+ add_compile_options(
+ -Wall
+ -Wsign-compare)
+elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
+ # TODO(andschwa): Switch to `/W4` and re-enable possible-loss-of-data warnings.
+ #
+ # The last two warnings are disabled (well, put into `/W4`) because
+ # there is no easy equivalent to enable them for GCC/Clang without
+ # also fixing all the warnings from `-Wconversion`.
+ add_compile_options(
+ # Like `-Wall`; `/W4` is more like `-Wall -Wextra`.
+ /W3
+ # Disable permissiveness.
+ /permissive-
+ # C4244 is a possible loss of data warning for integer conversions.
+ /w44244
+ # C4267 is a possible loss of data warning when converting from `size_t`.
+ /w44267)
+endif ()
+
# POSIX CONFIGURATION.
######################
if (NOT WIN32)
# Warn about use of format functions that can produce security issues.
- string(APPEND CMAKE_CXX_FLAGS " -Wformat-security")
+ add_compile_options(-Wformat-security)
# Protect many of the functions with stack guards. The exact flag
# depends on compiler support.
CHECK_CXX_COMPILER_FLAG(-fstack-protector-strong STRONG_STACK_PROTECTORS)
CHECK_CXX_COMPILER_FLAG(-fstack-protector STACK_PROTECTORS)
if (STRONG_STACK_PROTECTORS)
- string(APPEND CMAKE_CXX_FLAGS " -fstack-protector-strong")
+ add_compile_options(-fstack-protector-strong)
elseif (STACK_PROTECTORS)
- string(APPEND CMAKE_CXX_FLAGS " -fstack-protector")
+ add_compile_options(-fstack-protector)
else ()
message(
WARNING
@@ -259,7 +284,7 @@ if (ENABLE_GC_UNUSED)
set(CMAKE_REQUIRED_FLAGS "-ffunction-sections -fdata-sections -Wl,--gc-sections")
CHECK_CXX_COMPILER_FLAG("" GC_FUNCTION_SECTIONS)
if (GC_FUNCTION_SECTIONS)
- string(APPEND CMAKE_CXX_FLAGS " -ffunction-sections -fdata-sections")
+ add_compile_options(-ffunction-sections -fdata-sections)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,--gc-sections")
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,--gc-sections")
else ()
@@ -282,14 +307,11 @@ string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Linux" LINUX)
if (WIN32)
# COFF/PE and friends are somewhat limited in the number of sections they
# allow for an object file. We use this to avoid those problems.
- string(APPEND CMAKE_CXX_FLAGS " /bigobj /vd2")
-
- # Disable permissiveness.
- string(APPEND CMAKE_CXX_FLAGS " /permissive-")
+ add_compile_options(/bigobj /vd2)
# Fix Warning C4530: C++ exception handler used, but unwind semantics are not
# enabled.
- string(APPEND CMAKE_CXX_FLAGS " /EHsc")
+ add_compile_options(/EHsc)
# Build against the multi-threaded version of the C runtime library (CRT).
if (BUILD_SHARED_LIBS)
@@ -310,13 +332,15 @@ if (WIN32)
set(OPENSSL_MSVC_STATIC_RT TRUE)
endif ()
+ # Enable multi-threaded compilation for `cl.exe`.
+ add_compile_options(/MP)
+
+ # Force use of Unicode C and C++ Windows APIs.
+ add_definitions(-DUNICODE -D_UNICODE)
+
# NOTE: We APPEND ${CRT} rather than REPLACE so it gets picked up by
# dependencies.
foreach (lang C CXX)
- # Enable multi-threaded and UNICODE compilation.
- # NOTE: We do not add CRT here because dependencies will use it incorrectly.
- string(APPEND CMAKE_${lang}_FLAGS " /MP -DUNICODE -D_UNICODE")
-
# Debug library for debug configuration, release otherwise.
# Handle single-configuration generators such as Ninja.