ref: d40376ff3500d86f8b3989060793d46d09c06eb6
parent: 01abc0541a9840b835ed934f4ecac7d1d5a1a650
author: Gabriel Ravier <gabravier@gmail.com>
date: Tue Oct 29 06:03:13 EDT 2019
Removed bin2h mentions in CMakeLists, moved warnings options and FORCE_LOCAL_LIBS into a seperate block where the descriptions were improved and added warnings to DoConfig Signed-off-by: Gabriel Ravier <gabravier@gmail.com>
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,13 +9,14 @@
option(JAPANESE "Enable the Japanese-language build" 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(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}")
@@ -323,10 +324,8 @@
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()
@@ -512,6 +511,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
@@ -8,7 +8,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)
--
⑨