Skip to content

Commit

Permalink
ARROW-1615 Added BUILD_WARNING_LEVEL and BUILD_WARNING_FLAGS to Setup…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
renesugar authored and wesm committed Sep 29, 2017
1 parent f8cf91d commit d4e09c7
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ include(BuildUtils)
# Compiler flags
############################################################

# Determine compiler version
include(CompilerInfo)

if (ARROW_NO_DEPRECATED_API)
add_definitions(-DARROW_NO_DEPRECATED_API)
endif()
Expand All @@ -253,9 +256,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARROW_CXXFLAGS}")

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

# Determine compiler version
include(CompilerInfo)

if ("${COMPILER_FAMILY}" STREQUAL "clang")
# Using Clang with ccache causes a bunch of spurious warnings that are
# purportedly fixed in the next version of ccache. See the following for details:
Expand Down
5 changes: 5 additions & 0 deletions cpp/cmake_modules/CompilerInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ elseif("${COMPILER_VERSION_FULL}" MATCHES ".*clang-7")
set(COMPILER_FAMILY "clang")
set(COMPILER_VERSION "3.7.0svn")

# clang on Mac OS X, XCode 8.
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*clang-802")
set(COMPILER_FAMILY "clang")
set(COMPILER_VERSION "3.9.0svn")

# clang on Mac OS X, XCode 8.
elseif("${COMPILER_VERSION_FULL}" MATCHES ".*clang-8")
set(COMPILER_FAMILY "clang")
Expand Down
105 changes: 104 additions & 1 deletion cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,110 @@ if (MSVC)
set(CXX_COMMON_FLAGS "/W3")
endif()
else()
set(CXX_COMMON_FLAGS "-Wall -std=c++11")
# Common flags set below with warning level
set(CXX_COMMON_FLAGS "")
endif()

# Build warning level (CHECKIN, EVERYTHING, etc.)

# if no build warning level is specified, default to development warning level
if (NOT BUILD_WARNING_LEVEL)
set(BUILD_WARNING_LEVEL Production)
endif(NOT BUILD_WARNING_LEVEL)

string(TOUPPER ${BUILD_WARNING_LEVEL} UPPERCASE_BUILD_WARNING_LEVEL)

if ("${UPPERCASE_BUILD_WARNING_LEVEL}" STREQUAL "CHECKIN")
# Pre-checkin builds
if ("${COMPILER_FAMILY}" STREQUAL "msvc")
string(REPLACE "/W3" "" CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS}")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /W3")
# Treat all compiler warnings as errors
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /WX")
elseif ("${COMPILER_FAMILY}" STREQUAL "clang")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Weverything -Wno-c++98-compat \
-Wno-c++98-compat-pedantic -Wno-deprecated -Wno-weak-vtables -Wno-padded \
-Wno-unused-parameter -Wno-undef -Wno-documentation-deprecated-sync \
-Wno-shadow -Wno-switch-enum -Wno-documentation -Wno-exit-time-destructors \
-Wno-global-constructors -Wno-weak-template-vtables -Wno-undefined-reinterpret-cast \
-Wno-implicit-fallthrough -Wno-old-style-cast -Wno-unreachable-code-return \
-Wno-float-equal -Wno-missing-prototypes -Wno-non-virtual-dtor \
-Wno-unused-macros -Wno-covered-switch-default -Wno-unreachable-code-break \
-Wno-extra-semi -Wno-cast-align -Wno-vla-extension -Wno-shift-sign-overflow \
-Wno-used-but-marked-unused -Wno-missing-variable-declarations \
-Wno-gnu-zero-variadic-macro-arguments -Wconversion -Wno-sign-conversion \
-Wno-disabled-macro-expansion -Wc++11-narrowing -Wnarrowing -Wno-shorten-64-to-32")

# Version numbers where warnings are introduced
if ("${COMPILER_VERSION}" VERSION_GREATER "3.3")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-gnu-folding-constant")
endif()
if ("${COMPILER_VERSION}" VERSION_GREATER "3.6")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-reserved-id-macro")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-range-loop-analysis")
endif()
if ("${COMPILER_VERSION}" VERSION_GREATER "3.7")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-double-promotion")
endif()
if ("${COMPILER_VERSION}" VERSION_GREATER "3.8")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-undefined-func-template")
endif()

# Treat all compiler warnings as errors
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wunknown-warning-option -Werror")
elseif ("${COMPILER_FAMILY}" STREQUAL "gcc")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall -Wconversion -Wno-sign-conversion")
# Treat all compiler warnings as errors
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wunknown-warning-option -Werror")
else()
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
endif()
elseif ("${UPPERCASE_BUILD_WARNING_LEVEL}" STREQUAL "EVERYTHING")
# Pedantic builds for fixing warnings
if ("${COMPILER_FAMILY}" STREQUAL "msvc")
string(REPLACE "/W3" "" CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS}")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /Wall")
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
# /wdnnnn disables a warning where "nnnn" is a warning number
# Treat all compiler warnings as errors
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /WX")
elseif ("${COMPILER_FAMILY}" STREQUAL "clang")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic")
# Treat all compiler warnings as errors
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Werror")
elseif ("${COMPILER_FAMILY}" STREQUAL "gcc")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall -Wpedantic -Wextra -Wno-unused-parameter")
# Treat all compiler warnings as errors
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Werror")
else()
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
endif()
else()
# Production builds (warning are not treated as errors)
if ("${COMPILER_FAMILY}" STREQUAL "msvc")
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
# TODO: Enable /Wall and disable individual warnings until build compiles without errors
# /wdnnnn disables a warning where "nnnn" is a warning number
string(REPLACE "/W3" "" CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS}")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} /W3")
elseif ("${COMPILER_FAMILY}" STREQUAL "clang")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall")
elseif ("${COMPILER_FAMILY}" STREQUAL "gcc")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wall")
else()
message(FATAL_ERROR "Unknown compiler. Version info:\n${COMPILER_VERSION_FULL}")
endif()
endif()

# if build warning flags is set, add to CXX_COMMON_FLAGS
if (BUILD_WARNING_FLAGS)
# Use BUILD_WARNING_FLAGS with BUILD_WARNING_LEVEL=everything to disable
# warnings (use with Clang's -Weverything flag to find potential errors)
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} ${BUILD_WARNING_FLAGS}")
endif(BUILD_WARNING_FLAGS)

if (NOT ("${COMPILER_FAMILY}" STREQUAL "msvc"))
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -std=c++11")
endif()

# Only enable additional instruction sets if they are supported
Expand Down
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ endif(CCACHE_FOUND)
############################################################

include(BuildUtils)
include(SetupCxxFlags)
include(CompilerInfo)
include(SetupCxxFlags)

# Add common flags
set(CMAKE_CXX_FLAGS "${CXX_COMMON_FLAGS} ${CMAKE_CXX_FLAGS}")
Expand Down

0 comments on commit d4e09c7

Please sign in to comment.