Add warnings to cmake compilation (#1721)

* Add warnings to cmake compilation

Use the same set of warning flags that are used for qmake compilation.

See comments in #1718.

* Add condition for warning flags not supported by GCC 5.5

Satisfy Travis build by adding the unrecognised warning flags only when
the compiler version is greater or equal 7.0. Maybe those flags are
available in previous versions, but I don't know when they were introduced.

Tested with GCC 7.3.

* CMake option for enabling GCC warnings

This option follows the qmake configuration, where the same all_warnings
option exist. This allows users to select compiling with or without
warnings using "cmake -DALL_WARNINGS=ON" or OFF.
This commit is contained in:
Manuel
2019-02-13 17:53:12 +01:00
committed by Martin Kleusberg
parent c224d04607
commit e9145a0c8e

View File

@@ -17,6 +17,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}"
OPTION(ENABLE_TESTING "Enable the unit tests" OFF)
OPTION(FORCE_INTERNAL_ANTLR "Don't use the distribution's Antlr library even if there is one" OFF)
OPTION(FORCE_INTERNAL_QSCINTILLA "Don't use the distribution's QScintilla library even if there is one" OFF)
OPTION(ALL_WARNINGS "Enable some useful warning flags" OFF)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
@@ -367,6 +368,16 @@ add_executable(${PROJECT_NAME}
${SQLB_RESOURCES_RCC}
${SQLB_MISC})
# Warnings
if (ALL_WARNINGS AND CMAKE_COMPILER_IS_GNUCC)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion)
target_compile_options(${PROJECT_NAME} PRIVATE -Wdouble-promotion -Wformat=2 -Wlogical-op -Wuseless-cast)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 7.0)
target_compile_options(${PROJECT_NAME} PRIVATE -Wnull-dereference -Wduplicated-cond -Wduplicated-branches)
endif()
endif()
add_dependencies(${PROJECT_NAME} qhexedit qcustomplot)
if(NOT ANTLR2_FOUND)
add_dependencies(${PROJECT_NAME} antlr)