From 7474be628405fc0380f909e2d1020687ca1b28b5 Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Tue, 29 Nov 2016 19:46:38 +0100 Subject: [PATCH] - Fixed GCC/Clang compiler errors and warnings. --- src/CMakeLists.txt | 2 +- tools/drawergen/CMakeLists.txt | 40 ++++++++++++++++++++++++++++ tools/drawergen/drawergen.cpp | 2 +- tools/drawergen/ssa/ssa_function.cpp | 2 +- 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b84ed3a1..73a3074bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1506,7 +1506,7 @@ add_executable( zdoom WIN32 MACOSX_BUNDLE math/tanh.c math/fastsin.cpp zzautozend.cpp - ${CMAKE_BINARY_DIR}/src/r_drawersasm.obj + ${CMAKE_BINARY_DIR}/src/${CODEGENOBJ_SOURCES} ) set_source_files_properties( ${CODEGENOBJ_SOURCES} PROPERTIES EXTERNAL_OBJECT true GENERATED true) diff --git a/tools/drawergen/CMakeLists.txt b/tools/drawergen/CMakeLists.txt index eef5a0a94..61944953d 100644 --- a/tools/drawergen/CMakeLists.txt +++ b/tools/drawergen/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required( VERSION 2.8.7 ) +include( CheckCXXCompilerFlag ) + include(../../precompiled_headers.cmake) # Path where it looks for the LLVM compiled files on Windows @@ -54,6 +56,44 @@ else() endforeach(buildtype) endif() +if( ZD_CMAKE_COMPILER_IS_GNUCXX_COMPATIBLE ) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.5") + set( CMAKE_C_FLAGS "-Wno-unused-result ${CMAKE_C_FLAGS}" ) + set( CMAKE_CXX_FLAGS "-Wno-unused-result ${CMAKE_CXX_FLAGS}" ) + endif() + if( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" ) + if( APPLE OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "3.6" ) + set( CMAKE_CXX_FLAGS "-Wno-inconsistent-missing-override ${CMAKE_CXX_FLAGS}" ) + endif() + endif() + set( CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-missing-field-initializers -ffp-contract=off ${CMAKE_C_FLAGS}" ) + set( CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused -Wno-unused-parameter -Wno-missing-field-initializers -ffp-contract=off ${CMAKE_CXX_FLAGS}" ) + + # Use the highest C++ standard available since VS2015 compiles with C++14 + # but we only require C++11. The recommended way to do this in CMake is to + # probably to use target_compile_features, but I don't feel like maintaining + # a list of features we use. + CHECK_CXX_COMPILER_FLAG( "-std=gnu++14" CAN_DO_CPP14 ) + if ( CAN_DO_CPP14 ) + set ( CMAKE_CXX_FLAGS "-std=gnu++14 ${CMAKE_CXX_FLAGS}" ) + else () + CHECK_CXX_COMPILER_FLAG( "-std=gnu++1y" CAN_DO_CPP1Y ) + if ( CAN_DO_CPP1Y ) + set ( CMAKE_CXX_FLAGS "-std=gnu++1y ${CMAKE_CXX_FLAGS}" ) + else () + CHECK_CXX_COMPILER_FLAG( "-std=gnu++11" CAN_DO_CPP11 ) + if ( CAN_DO_CPP11 ) + set ( CMAKE_CXX_FLAGS "-std=gnu++11 ${CMAKE_CXX_FLAGS}" ) + else () + CHECK_CXX_COMPILER_FLAG( "-std=gnu++0x" CAN_DO_CPP0X ) + if ( CAN_DO_CPP0X ) + set ( CMAKE_CXX_FLAGS "-std=gnu++0x ${CMAKE_CXX_FLAGS}" ) + endif () + endif () + endif () + endif () +endif() + if( WIN32 ) if( MSVC_VERSION GREATER 1399 ) # VC 8+ adds a manifest automatically to the executable. We need to diff --git a/tools/drawergen/drawergen.cpp b/tools/drawergen/drawergen.cpp index 8896e3f7b..a37f2f26e 100644 --- a/tools/drawergen/drawergen.cpp +++ b/tools/drawergen/drawergen.cpp @@ -42,7 +42,7 @@ class Exception : public std::exception { public: Exception(const std::string &message) : message(message) { } - const char *what() const override { return message.c_str(); } + const char *what() const noexcept override { return message.c_str(); } private: std::string message; diff --git a/tools/drawergen/ssa/ssa_function.cpp b/tools/drawergen/ssa/ssa_function.cpp index ef01cec44..e21b0b229 100644 --- a/tools/drawergen/ssa/ssa_function.cpp +++ b/tools/drawergen/ssa/ssa_function.cpp @@ -27,7 +27,7 @@ #include "ssa_value.h" SSAFunction::SSAFunction(const std::string name) -: name(name), return_type(llvm::Type::getVoidTy(SSAScope::context())), func() +: func(), name(name), return_type(llvm::Type::getVoidTy(SSAScope::context())) { }