ref: 68fceb63c4ac10158a2b07d2f78cf5b47df235ab
parent: 4e99c97feebccb72327445689f1e827af12c58c4
parent: f6c19c5501f40c437f17d9a3354bd4996b8da3b0
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Oct 29 07:44:13 EDT 2019
Merge pull request #63 from GabrielRavier/addWarnings2 Add warnings
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,14 +11,44 @@
set(BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/game")
set(ASSETS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets")
-option(JAPANESE "Enable the Japanese-language build" OFF)
+option(JAPANESE "Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)" OFF)
option(FIX_BUGS "Fix various bugs in the game" OFF)
option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the window" OFF)
-option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF)
set(RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer")
+option(WARNINGS "Enable common compiler warnings (for gcc-compatible compilers and MSVC only)" OFF)
+option(ALL_WARNINGS "Enable ALL compiler warnings (for clang and MSVC only)" OFF)
+option(FATAL_WARNINGS "Stop compilation on any compiler warning (for gcc-compatible compilers and MSVC only)" OFF)
+option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF)
+
project(CSE2 LANGUAGES C CXX)
+message(STATUS "Compiler ID : ${CMAKE_CXX_COMPILER_ID}")
+
+# Has to be placed after "project()"
+if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ # Using Clang (this is a match so that we also get "AppleClang" which is the Apple-provided Clang
+ set(COMPILER_IS_CLANG true)
+ message(STATUS "Compiling with clang")
+endif()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ # Using GCC
+ set(COMPILER_IS_GCC true)
+ message(STATUS "Compiling with gcc")
+endif()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
+ # Using Intel C++
+ set(COMPILER_IS_ICC true)
+ message(STATUS "Compiling with ICC")
+endif()
+
+if (COMPILER_IS_CLANG OR COMPILER_IS_GCC OR COMPILER_IS_ICC)
+ set(COMPILER_IS_GCC_COMPATIBLE true)
+ message(STATUS "Compiling with a GCC-compatible compiler")
+endif()
+
if(MSVC)
# Statically-link the CRT (vcpkg static libs do this)
foreach(flag_var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
@@ -251,6 +281,60 @@
target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE)
endif()
+if (WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ # Force to always compile with /W4 on MSVC
+
+ # Can't do this with target_compile_options
+ # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
+ # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ # else()
+ # target_compile_options(CSE2 PRIVATE /W4)
+ # endif()
+
+ target_compile_options(CSE2 PRIVATE /W4)
+ elseif(COMPILER_IS_GCC_COMPATIBLE)
+ target_compile_options(CSE2 PRIVATE -Wall -Wextra -pedantic)
+ else()
+ message(WARNING "Could not activate warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
+if (ALL_WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ # Force to always compile with /Wall on MSVC
+
+ # Can't do this with target_compile_options
+ # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
+ # string(REGEX REPLACE "/W[0-4]" "/Wall" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ # else()
+ # target_compile_options(CSE2 PRIVATE /Wall)
+ # endif()
+
+ target_compile_options(CSE2 PRIVATE /Wall)
+ elseif(COMPILER_IS_CLANG)
+ target_compile_options(CSE2 PRIVATE -Weverything)
+ else()
+ message(WARNING "Could not activate all warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
+if (FATAL_WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ target_compile_options(CSE2 PRIVATE /WX)
+ elseif(COMPILER_IS_GCC_COMPATIBLE)
+ target_compile_options(CSE2 PRIVATE -Werror)
+ else()
+ message(WARNING "Could not activate fatal warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
if(RENDERER MATCHES "OpenGL3")
target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL3.cpp")
elseif(RENDERER MATCHES "SDLTexture")
@@ -288,6 +372,9 @@
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=Release
+ -DWARNINGS=${WARNINGS}
+ -DALL_WARNINGS=${ALL_WARNINGS}
+ -DFATAL_WARNINGS=${FATAL_WARNINGS}
INSTALL_COMMAND
${CMAKE_COMMAND} --build . --config Release --target install
)
@@ -431,6 +518,11 @@
##
# DoConfig
##
+
+# Set warning options for DoConfig
+set(WARNINGS ${WARNINGS} FORCE BOOL)
+set(ALL_WARNINGS ${ALL_WARNINGS} FORCE BOOL)
+set(FATAL_WARNINGS ${FATAL_WARNINGS} FORCE BOOL)
add_subdirectory("DoConfig")
--- a/DoConfig/CMakeLists.txt
+++ b/DoConfig/CMakeLists.txt
@@ -12,7 +12,87 @@
project(DoConfig LANGUAGES CXX)
+message(STATUS "Compiler ID : ${CMAKE_CXX_COMPILER_ID}")
+
+# Has to be placed after "project()"
+if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ # Using Clang (this is a match so that we also get "AppleClang" which is the Apple-provided Clang
+ set(COMPILER_IS_CLANG true)
+ message(STATUS "Compiling with clang")
+endif()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ # Using GCC
+ set(COMPILER_IS_GCC true)
+ message(STATUS "Compiling with gcc")
+endif()
+
+if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
+ # Using Intel C++
+ set(COMPILER_IS_ICC true)
+ message(STATUS "Compiling with ICC")
+endif()
+
+if (COMPILER_IS_CLANG OR COMPILER_IS_GCC OR COMPILER_IS_ICC)
+ set(COMPILER_IS_GCC_COMPATIBLE true)
+ message(STATUS "Compiling with a GCC-compatible compiler")
+endif()
+
add_executable(DoConfig "DoConfig.cpp" "icon.rc")
+
+if (WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ # Force to always compile with /W4 on MSVC
+
+ # Can't do this with target_compile_options
+ # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
+ # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ # else()
+ # target_compile_options(CSE2 PRIVATE /W4)
+ # endif()
+
+ target_compile_options(DoConfig PRIVATE /W4)
+ elseif(COMPILER_IS_GCC_COMPATIBLE)
+ target_compile_options(DoConfig PRIVATE -Wall -Wextra -pedantic)
+ else()
+ message(WARNING "Could not activate warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
+if (ALL_WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ # Force to always compile with /Wall on MSVC
+
+ # Can't do this with target_compile_options
+ # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
+ # string(REGEX REPLACE "/W[0-4]" "/Wall" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ # else()
+ # target_compile_options(CSE2 PRIVATE /Wall)
+ # endif()
+
+ target_compile_options(DoConfig PRIVATE /Wall)
+ elseif(COMPILER_IS_CLANG)
+ target_compile_options(DoConfig PRIVATE -Weverything)
+ else()
+ message(WARNING "Could not activate all warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
+if (FATAL_WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ target_compile_options(DoConfig PRIVATE /WX)
+ elseif(COMPILER_IS_GCC_COMPATIBLE)
+ target_compile_options(DoConfig PRIVATE -Werror)
+ else()
+ message(WARNING "Could not activate fatal warnings ! (Unsupported compiler)")
+ endif()
+endif()
# Windows tweak
if(WIN32)
--- a/Makefile
+++ b/Makefile
@@ -43,6 +43,23 @@
CXXFLAGS += -DDEBUG_SAVE
endif
+ifeq ($(WARNINGS), 1)
+ CXXFLAGS += -Wall -Wextra -pedantic
+endif
+
+ifeq ($(ALL_WARNINGS), 1)
+ ifneq ($(findstring clang,$(CXX),)
+ # Use clang-specific flag -Weverything
+ CXXFLAGS += -Weverything
+ else
+ @echo Couldn\'t activate all warnings (Unsupported compiler)
+ endif
+endif
+
+ifeq ($(FATAL_WARNINGS), 1)
+ CXXFLAGS += -Werror
+endif
+
CXXFLAGS += -std=c++98 -MMD -MP -MF $@.d `$(PKG_CONFIG) sdl2 --cflags` `$(PKG_CONFIG) freetype2 --cflags`
ifeq ($(STATIC), 1)
--- a/README.md
+++ b/README.md
@@ -62,11 +62,14 @@
`-DJAPANESE=ON` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)
`-DFIX_BUGS=ON` | Fix various bugs in the game
`-DDEBUG_SAVE=ON` | Re-enable the ability to drag-and-drop save files onto the window
-`-DFORCE_LOCAL_LIBS=ON` | Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones
`-DRENDERER=OpenGL3` | Use the hardware-accelerated OpenGL 3.2 renderer
`-DRENDERER=SDLTexture` | Use the hardware-accelerated SDL2 Texture API renderer (default)
`-DRENDERER=SDLSurface` | Use the software-rendered SDL2 Surface API renderer
`-DRENDERER=Software` | Use the handwritten software renderer
+`-DWARNINGS=ON` | Enable common compiler warnings (for gcc-compatible compilers and MSVC only)
+`-DALL_WARNINGS=ON` | Enable ALL compiler warnings (for clang and MSVC only)
+`-DFATAL_WARNINGS=ON` | Stop compilation on any compiler warning (for gcc-compatible compilers and MSVC only)
+`-DFORCE_LOCAL_LIBS=ON` | Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones
Then compile CSE2 with this command:
@@ -92,6 +95,9 @@
`FIX_BUGS=1` | Fix various bugs in the game
`WINDOWS=1` | Build for Windows
`DEBUG_SAVE=1` | Re-enable the ability to drag-and-drop save files onto the window
+`WARNINGS=1` | Enable common warnings
+`ALL_WARNINGS=1` | Enable ALL warnings (clang/MSVC only)
+`FATAL_WARNINGS=1` | Make all warnings errors
`RENDERER=OpenGL3` | Use the hardware-accelerated OpenGL 3.2 renderer
`RENDERER=SDLTexture` | Use the hardware-accelerated SDL2 Texture API renderer (default)
`RENDERER=SDLSurface` | Use the software-rendered SDL2 Surface API renderer
--- a/bin2h/CMakeLists.txt
+++ b/bin2h/CMakeLists.txt
@@ -14,6 +14,88 @@
C_EXTENSIONS OFF
)
+message(STATUS "Compiler ID : ${CMAKE_C_COMPILER_ID}")
+
+# Has to be placed after "project()"
+if (CMAKE_C_COMPILER_ID MATCHES "Clang")
+ # Using Clang (this is a match so that we also get "AppleClang" which is the Apple-provided Clang
+ set(COMPILER_IS_CLANG true)
+ message(STATUS "Compiling with clang")
+endif()
+
+if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ # Using GCC
+ set(COMPILER_IS_GCC true)
+ message(STATUS "Compiling with gcc")
+endif()
+
+if (CMAKE_C_COMPILER_ID STREQUAL "Intel")
+ # Using Intel C++
+ set(COMPILER_IS_ICC true)
+ message(STATUS "Compiling with ICC")
+endif()
+
+if (COMPILER_IS_CLANG OR COMPILER_IS_GCC OR COMPILER_IS_ICC)
+ set(COMPILER_IS_GCC_COMPATIBLE true)
+ message(STATUS "Compiling with a GCC-compatible compiler")
+endif()
+
+if (WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ # Force to always compile with /W4 on MSVC
+
+ # Can't do this with target_compile_options
+ # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
+ # string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ # else()
+ # target_compile_options(CSE2 PRIVATE /W4)
+ # endif()
+
+ target_compile_options(bin2h PRIVATE /W4)
+ elseif(COMPILER_IS_GCC_COMPATIBLE)
+ target_compile_options(bin2h PRIVATE -Wall -Wextra -pedantic)
+ else()
+ message(WARNING "Could not activate warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
+if (ALL_WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ # Force to always compile with /Wall on MSVC
+
+ # Can't do this with target_compile_options
+ # if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
+ # string(REGEX REPLACE "/W[0-4]" "/Wall" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ # else()
+ # target_compile_options(CSE2 PRIVATE /Wall)
+ # endif()
+
+ target_compile_options(bin2h PRIVATE /Wall)
+ elseif(COMPILER_IS_CLANG)
+ target_compile_options(bin2h PRIVATE -Weverything)
+ else()
+ message(WARNING "Could not activate all warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
+if (FATAL_WARNINGS)
+ # HACK : Replace this with CMake provided stuff when possible (when CMake makes avoiding this possible (it isn't currently))
+
+ if (MSVC)
+ target_compile_options(CSE2 PRIVATE /WX)
+ target_compile_options(bin2h PRIVATE /WX)
+ elseif(COMPILER_IS_GCC_COMPATIBLE)
+ target_compile_options(CSE2 PRIVATE -Werror)
+ target_compile_options(bin2h PRIVATE -Werror)
+ else()
+ message(WARNING "Could not activate fatal warnings ! (Unsupported compiler)")
+ endif()
+endif()
+
# MSVC tweak
if(MSVC)
target_compile_definitions(bin2h PRIVATE _CRT_SECURE_NO_WARNINGS) # Disable warnings that normally fire up on MSVC when using "unsafe" functions instead of using MSVC's "safe" _s functions
--
⑨