First attempt at making warnings work
Signed-off-by: Gabriel Ravier <gabravier@gmail.com>
This commit is contained in:
parent
c2daebe38a
commit
44d6dac407
4 changed files with 190 additions and 0 deletions
|
@ -9,12 +9,39 @@ set(ASSETS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets")
|
||||||
|
|
||||||
option(JAPANESE "Enable the Japanese-language build" OFF)
|
option(JAPANESE "Enable the Japanese-language build" OFF)
|
||||||
option(FIX_BUGS "Fix various bugs in the game" OFF)
|
option(FIX_BUGS "Fix various bugs in the game" OFF)
|
||||||
|
option(WARNINGS "Enable common warnings" OFF)
|
||||||
|
option(ALL_WARNINGS "Enable ALL warnings (clang/MSVC-only)" OFF)
|
||||||
|
option(FATAL_WARNINGS "Stop compilation on any warnings" OFF)
|
||||||
option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the window" 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)
|
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")
|
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")
|
||||||
|
|
||||||
project(CSE2 LANGUAGES C CXX)
|
project(CSE2 LANGUAGES C CXX)
|
||||||
|
|
||||||
|
# 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)
|
if(MSVC)
|
||||||
# Statically-link the CRT (vcpkg static libs do this)
|
# 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)
|
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)
|
||||||
|
@ -247,6 +274,62 @@ if(DEBUG_SAVE)
|
||||||
target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE)
|
target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE)
|
||||||
endif()
|
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)
|
||||||
|
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()
|
||||||
|
|
||||||
if(RENDERER MATCHES "OpenGL3")
|
if(RENDERER MATCHES "OpenGL3")
|
||||||
target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL3.cpp")
|
target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL3.cpp")
|
||||||
elseif(RENDERER MATCHES "SDLTexture")
|
elseif(RENDERER MATCHES "SDLTexture")
|
||||||
|
@ -281,6 +364,9 @@ ExternalProject_Add(bin2h
|
||||||
CMAKE_ARGS
|
CMAKE_ARGS
|
||||||
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
||||||
-DCMAKE_BUILD_TYPE=Release
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
-DWARNINGS=${WARNINGS}
|
||||||
|
-DALL_WARNINGS=${ALL_WARNINGS}
|
||||||
|
-DFATAL_WARNINGS=${FATAL_WARNINGS}
|
||||||
INSTALL_COMMAND
|
INSTALL_COMMAND
|
||||||
${CMAKE_COMMAND} --build . --config Release --target install
|
${CMAKE_COMMAND} --build . --config Release --target install
|
||||||
)
|
)
|
||||||
|
|
17
Makefile
17
Makefile
|
@ -43,6 +43,23 @@ ifeq ($(DEBUG_SAVE), 1)
|
||||||
CXXFLAGS += -DDEBUG_SAVE
|
CXXFLAGS += -DDEBUG_SAVE
|
||||||
endif
|
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`
|
CXXFLAGS += -std=c++98 -MMD -MP -MF $@.d `$(PKG_CONFIG) sdl2 --cflags` `$(PKG_CONFIG) freetype2 --cflags`
|
||||||
|
|
||||||
ifeq ($(STATIC), 1)
|
ifeq ($(STATIC), 1)
|
||||||
|
|
|
@ -63,6 +63,9 @@ Name | Function
|
||||||
`-DFIX_BUGS=ON` | Fix various bugs in the game
|
`-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
|
`-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
|
`-DFORCE_LOCAL_LIBS=ON` | Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones
|
||||||
|
`-DWARNINGS=ON` | Enable common warnings
|
||||||
|
`-DALL_WARNINGS=ON` | Enable ALL warnings (clang/MSVC-only)
|
||||||
|
`-DFATAL_WARNINGS=ON` | Make all warnings errors
|
||||||
`-DRENDERER=OpenGL3` | Use the hardware-accelerated OpenGL 3.2 renderer
|
`-DRENDERER=OpenGL3` | Use the hardware-accelerated OpenGL 3.2 renderer
|
||||||
`-DRENDERER=SDLTexture` | Use the hardware-accelerated SDL2 Texture API renderer (default)
|
`-DRENDERER=SDLTexture` | Use the hardware-accelerated SDL2 Texture API renderer (default)
|
||||||
`-DRENDERER=SDLSurface` | Use the software-rendered SDL2 Surface API renderer
|
`-DRENDERER=SDLSurface` | Use the software-rendered SDL2 Surface API renderer
|
||||||
|
@ -92,6 +95,9 @@ Name | Function
|
||||||
`FIX_BUGS=1` | Fix various bugs in the game
|
`FIX_BUGS=1` | Fix various bugs in the game
|
||||||
`WINDOWS=1` | Build for Windows
|
`WINDOWS=1` | Build for Windows
|
||||||
`DEBUG_SAVE=1` | Re-enable the ability to drag-and-drop save files onto the window
|
`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=OpenGL3` | Use the hardware-accelerated OpenGL 3.2 renderer
|
||||||
`RENDERER=SDLTexture` | Use the hardware-accelerated SDL2 Texture API renderer (default)
|
`RENDERER=SDLTexture` | Use the hardware-accelerated SDL2 Texture API renderer (default)
|
||||||
`RENDERER=SDLSurface` | Use the software-rendered SDL2 Surface API renderer
|
`RENDERER=SDLSurface` | Use the software-rendered SDL2 Surface API renderer
|
||||||
|
|
|
@ -6,6 +6,30 @@ endif()
|
||||||
|
|
||||||
project(bin2h LANGUAGES C)
|
project(bin2h LANGUAGES C)
|
||||||
|
|
||||||
|
# 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(bin2h "bin2h.c")
|
add_executable(bin2h "bin2h.c")
|
||||||
|
|
||||||
set_target_properties(bin2h PROPERTIES
|
set_target_properties(bin2h PROPERTIES
|
||||||
|
@ -14,6 +38,63 @@ set_target_properties(bin2h PROPERTIES
|
||||||
C_EXTENSIONS OFF
|
C_EXTENSIONS OFF
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
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
|
# MSVC tweak
|
||||||
if(MSVC)
|
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
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue