Skip to content

Commit d4e09c7

Browse files
renesugarwesm
authored andcommitted
ARROW-1615 Added BUILD_WARNING_LEVEL and BUILD_WARNING_FLAGS to Setup…
…CxxFlags.cmake Author: Rene Sugar <rene.sugar@gmail.com> Closes apache#1145 from renesugar/ARROW-1615 and squashes the following commits: 71a615e [Rene Sugar] ARROW-1615 Add -Wno-vla-extension and change non-checkin builds back to -Wall 1895843 [Rene Sugar] ARROW-1615 Add -Wno-cast-align 5fe4e8e [Rene Sugar] ARROW-1615 Move -Wno-shorten-64-to-32 after -Wconversion 9d3c7ec [Rene Sugar] ARROW-1615 Identify compiler version for clang-802 plus more warning entries 5ebaf86 [Rene Sugar] ARROW-1615 Moved version specific warning entry 971e61a [Rene Sugar] ARROW-1615 Fixed version specific warning entry 6cf2497 [Rene Sugar] ARROW-1615 Added more version specific Clang warning entries 50def43 [Rene Sugar] ARROW-1615 Updated build warning level terminology ea906eb [Rene Sugar] ARROW-1615 Check compiler version before disabling some warnings 159e189 [Rene Sugar] ARROW-1615 Include CompilerInfo before SetupCxxFlags in arrow/python 8359c96 [Rene Sugar] ARROW-1615 Added BUILD_WARNING_LEVEL and BUILD_WARNING_FLAGS to SetupCxxFlags.cmake
1 parent f8cf91d commit d4e09c7

File tree

4 files changed

+113
-5
lines changed

4 files changed

+113
-5
lines changed

cpp/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ include(BuildUtils)
229229
# Compiler flags
230230
############################################################
231231

232+
# Determine compiler version
233+
include(CompilerInfo)
234+
232235
if (ARROW_NO_DEPRECATED_API)
233236
add_definitions(-DARROW_NO_DEPRECATED_API)
234237
endif()
@@ -253,9 +256,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARROW_CXXFLAGS}")
253256

254257
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
255258

256-
# Determine compiler version
257-
include(CompilerInfo)
258-
259259
if ("${COMPILER_FAMILY}" STREQUAL "clang")
260260
# Using Clang with ccache causes a bunch of spurious warnings that are
261261
# purportedly fixed in the next version of ccache. See the following for details:

cpp/cmake_modules/CompilerInfo.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ elseif("${COMPILER_VERSION_FULL}" MATCHES ".*clang-7")
6363
set(COMPILER_FAMILY "clang")
6464
set(COMPILER_VERSION "3.7.0svn")
6565

66+
# clang on Mac OS X, XCode 8.
67+
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*clang-802")
68+
set(COMPILER_FAMILY "clang")
69+
set(COMPILER_VERSION "3.9.0svn")
70+
6671
# clang on Mac OS X, XCode 8.
6772
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*clang-8")
6873
set(COMPILER_FAMILY "clang")

cpp/cmake_modules/SetupCxxFlags.cmake

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,110 @@ if (MSVC)
4848
set(CXX_COMMON_FLAGS "/W3")
4949
endif()
5050
else()
51-
set(CXX_COMMON_FLAGS "-Wall -std=c++11")
51+
# Common flags set below with warning level
52+
set(CXX_COMMON_FLAGS "")
53+
endif()
54+
55+
# Build warning level (CHECKIN, EVERYTHING, etc.)
56+
57+
# if no build warning level is specified, default to development warning level
58+
if (NOT BUILD_WARNING_LEVEL)
59+
set(BUILD_WARNING_LEVEL Production)
60+
endif(NOT BUILD_WARNING_LEVEL)
61+
62+
string(TOUPPER ${BUILD_WARNING_LEVEL} UPPERCASE_BUILD_WARNING_LEVEL)
63+
64+
if ("${UPPERCASE_BUILD_WARNING_LEVEL}" STREQUAL "CHECKIN")
65+
# Pre-checkin builds
66+
if ("${COMPILER_FAMILY}" STREQUAL "msvc")
67+
string(REPLACE "/W3" "" CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS}")
68+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /W3")
69+
# Treat all compiler warnings as errors
70+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /WX")
71+
elseif ("${COMPILER_FAMILY}" STREQUAL "clang")
72+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Weverything -Wno-c++98-compat \
73+
-Wno-c++98-compat-pedantic -Wno-deprecated -Wno-weak-vtables -Wno-padded \
74+
-Wno-unused-parameter -Wno-undef -Wno-documentation-deprecated-sync \
75+
-Wno-shadow -Wno-switch-enum -Wno-documentation -Wno-exit-time-destructors \
76+
-Wno-global-constructors -Wno-weak-template-vtables -Wno-undefined-reinterpret-cast \
77+
-Wno-implicit-fallthrough -Wno-old-style-cast -Wno-unreachable-code-return \
78+
-Wno-float-equal -Wno-missing-prototypes -Wno-non-virtual-dtor \
79+
-Wno-unused-macros -Wno-covered-switch-default -Wno-unreachable-code-break \
80+
-Wno-extra-semi -Wno-cast-align -Wno-vla-extension -Wno-shift-sign-overflow \
81+
-Wno-used-but-marked-unused -Wno-missing-variable-declarations \
82+
-Wno-gnu-zero-variadic-macro-arguments -Wconversion -Wno-sign-conversion \
83+
-Wno-disabled-macro-expansion -Wc++11-narrowing -Wnarrowing -Wno-shorten-64-to-32")
84+
85+
# Version numbers where warnings are introduced
86+
if ("${COMPILER_VERSION}" VERSION_GREATER "3.3")
87+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-gnu-folding-constant")
88+
endif()
89+
if ("${COMPILER_VERSION}" VERSION_GREATER "3.6")
90+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-reserved-id-macro")
91+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-range-loop-analysis")
92+
endif()
93+
if ("${COMPILER_VERSION}" VERSION_GREATER "3.7")
94+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-double-promotion")
95+
endif()
96+
if ("${COMPILER_VERSION}" VERSION_GREATER "3.8")
97+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-undefined-func-template")
98+
endif()
99+
100+
# Treat all compiler warnings as errors
101+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wunknown-warning-option -Werror")
102+
elseif ("${COMPILER_FAMILY}" STREQUAL "gcc")
103+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall -Wconversion -Wno-sign-conversion")
104+
# Treat all compiler warnings as errors
105+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wunknown-warning-option -Werror")
106+
else()
107+
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
108+
endif()
109+
elseif ("${UPPERCASE_BUILD_WARNING_LEVEL}" STREQUAL "EVERYTHING")
110+
# Pedantic builds for fixing warnings
111+
if ("${COMPILER_FAMILY}" STREQUAL "msvc")
112+
string(REPLACE "/W3" "" CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS}")
113+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /Wall")
114+
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
115+
# /wdnnnn disables a warning where "nnnn" is a warning number
116+
# Treat all compiler warnings as errors
117+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /WX")
118+
elseif ("${COMPILER_FAMILY}" STREQUAL "clang")
119+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic")
120+
# Treat all compiler warnings as errors
121+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Werror")
122+
elseif ("${COMPILER_FAMILY}" STREQUAL "gcc")
123+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall -Wpedantic -Wextra -Wno-unused-parameter")
124+
# Treat all compiler warnings as errors
125+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Werror")
126+
else()
127+
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
128+
endif()
129+
else()
130+
# Production builds (warning are not treated as errors)
131+
if ("${COMPILER_FAMILY}" STREQUAL "msvc")
132+
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
133+
# TODO: Enable /Wall and disable individual warnings until build compiles without errors
134+
# /wdnnnn disables a warning where "nnnn" is a warning number
135+
string(REPLACE "/W3" "" CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS}")
136+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /W3")
137+
elseif ("${COMPILER_FAMILY}" STREQUAL "clang")
138+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall")
139+
elseif ("${COMPILER_FAMILY}" STREQUAL "gcc")
140+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall")
141+
else()
142+
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
143+
endif()
144+
endif()
145+
146+
# if build warning flags is set, add to CXX_COMMON_FLAGS
147+
if (BUILD_WARNING_FLAGS)
148+
# Use BUILD_WARNING_FLAGS with BUILD_WARNING_LEVEL=everything to disable
149+
# warnings (use with Clang's -Weverything flag to find potential errors)
150+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} ${BUILD_WARNING_FLAGS}")
151+
endif(BUILD_WARNING_FLAGS)
152+
153+
if (NOT ("${COMPILER_FAMILY}" STREQUAL "msvc"))
154+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -std=c++11")
52155
endif()
53156

54157
# Only enable additional instruction sets if they are supported

python/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ endif(CCACHE_FOUND)
7272
############################################################
7373

7474
include(BuildUtils)
75-
include(SetupCxxFlags)
7675
include(CompilerInfo)
76+
include(SetupCxxFlags)
7777

7878
# Add common flags
7979
set(CMAKE_CXX_FLAGS "${CXX_COMMON_FLAGS} ${CMAKE_CXX_FLAGS}")

0 commit comments

Comments
 (0)