Merge branch 'accurate' into portable

This commit is contained in:
Clownacy 2020-03-14 20:11:42 +00:00
commit a0f7ce8d9f
3 changed files with 8 additions and 134 deletions

View file

@ -9,11 +9,8 @@ set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should u
set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'") set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'")
option(LTO "Enable link-time optimisation" OFF) option(LTO "Enable link-time optimisation" OFF)
option(NATIVE_OPTIMIZATIONS "Enable processor-specific optimisations (executable might not work on other architectures) (GCC-compatible compilers only)" OFF) option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library" OFF)
option(WARNINGS "Enable common compiler warnings (for GCC-compatible compilers and MSVC only)" OFF)
option(WARNINGS_ALL "Enable ALL compiler warnings (for Clang and MSVC only)" OFF)
option(WARNINGS_FATAL "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) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF)
list(APPEND CMAKE_MODULE_PATH list(APPEND CMAKE_MODULE_PATH
@ -22,33 +19,7 @@ list(APPEND CMAKE_MODULE_PATH
project(CSE2 LANGUAGES C CXX) project(CSE2 LANGUAGES C CXX)
message(STATUS "Compiler ID : ${CMAKE_CXX_COMPILER_ID}") if(MSVC AND MSVC_LINK_STATIC_RUNTIME)
# 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) # 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)
if(${flag_var} MATCHES "/MD") if(${flag_var} MATCHES "/MD")
@ -284,60 +255,6 @@ 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 (WARNINGS_ALL)
# 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(WARNINGS_FATAL)
# 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(BACKEND_RENDERER MATCHES "OpenGL3") if(BACKEND_RENDERER MATCHES "OpenGL3")
target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL3.cpp") target_sources(CSE2 PRIVATE "src/Backends/Rendering/OpenGL3.cpp")
elseif(BACKEND_RENDERER MATCHES "OpenGLES2") elseif(BACKEND_RENDERER MATCHES "OpenGLES2")
@ -469,25 +386,6 @@ if(LTO)
endif() endif()
endif() endif()
# Enable -march=native if available
if(NATIVE_OPTIMIZATIONS)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) # GCC flag
if(COMPILER_SUPPORTS_MARCH_NATIVE)
target_compile_options(CSE2 PRIVATE -march=native)
else()
CHECK_CXX_COMPILER_FLAG("-xHost" COMPILER_SUPPORTS_XHOST) # ICC (Linux) flag
CHECK_CXX_COMPILER_FLAG("/QxHost" COMPILER_SUPPORTS_QXHOST) # ICC (Windows) flag
if(COMPILER_SUPPORTS_XHOST)
target_compile_options(CSE2 PRIVATE -xHost)
elseif(COMPILER_SUPPORTS_QXHOST)
target_compile_options(CSE2 PRIVATE /QxHost)
else()
message(WARNING "Couldn't activate native optimizations ! (Unsupported compiler)")
endif()
endif()
endif()
# Find dependencies # Find dependencies
if(NOT FORCE_LOCAL_LIBS) if(NOT FORCE_LOCAL_LIBS)

View file

@ -60,26 +60,6 @@ ifeq ($(DEBUG_SAVE), 1)
DEFINES += -DDEBUG_SAVE DEFINES += -DDEBUG_SAVE
endif endif
ifeq ($(WARNINGS), 1)
ALL_CFLAGS += -Wall -Wextra -pedantic
ALL_CXXFLAGS += -Wall -Wextra -pedantic
endif
ifeq ($(WARNINGS_ALL), 1)
ifneq ($(findstring clang,$(CXX)),)
# Use Clang-specific flag -Weverything
ALL_CFLAGS += -Weverything
ALL_CXXFLAGS += -Weverything
else
$(warning Couldn't activate all warnings (unsupported compiler))
endif
endif
ifeq ($(WARNINGS_FATAL), 1)
ALL_CFLAGS += -Werror
ALL_CXXFLAGS += -Werror
endif
ALL_CFLAGS += -std=c99 -MMD -MP -MF $@.d ALL_CFLAGS += -std=c99 -MMD -MP -MF $@.d
CSE2_CFLAGS += $(shell $(PKGCONFIG) sdl2 --cflags) $(shell $(PKGCONFIG) freetype2 --cflags) -Iexternal CSE2_CFLAGS += $(shell $(PKGCONFIG) sdl2 --cflags) $(shell $(PKGCONFIG) freetype2 --cflags) -Iexternal

View file

@ -61,7 +61,6 @@ You can also add the following flags:
Name | Function Name | Function
--------|-------- --------|--------
`-DLTO=ON` | Enable link-time optimisation `-DLTO=ON` | Enable link-time optimisation
`-DNATIVE_OPTIMIZATIONS=ON` | Enable processor-specific optimisations (executable might not work on other architectures) (GCC-compatible compilers only)
`-DJAPANESE=ON` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation) `-DJAPANESE=ON` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)
`-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
@ -72,12 +71,11 @@ Name | Function
`-DBACKEND_RENDERER=Software` | Use the handwritten software renderer `-DBACKEND_RENDERER=Software` | Use the handwritten software renderer
`-DBACKEND_AUDIO=SDL2` | Use the SDL2-driven software audio-mixer `-DBACKEND_AUDIO=SDL2` | Use the SDL2-driven software audio-mixer
`-DBACKEND_AUDIO=miniaudio` | Use the miniaudio-driven software audio-mixer `-DBACKEND_AUDIO=miniaudio` | Use the miniaudio-driven software audio-mixer
`-DWARNINGS=ON` | Enable common compiler warnings (for GCC-compatible compilers and MSVC only)
`-DWARNINGS_ALL=ON` | Enable ALL compiler warnings (for Clang and MSVC only)
`-DWARNINGS_FATAL=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 `-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: You can pass your own compiler flags with `-DCMAKE_C_FLAGS` and `-DCMAKE_CXX_FLAGS`.
You can then compile CSE2 with this command:
``` ```
cmake --build . --config Release cmake --build . --config Release
@ -85,7 +83,7 @@ cmake --build . --config Release
If you're a Visual Studio user, you can open the generated `CSE2.sln` file instead. If you're a Visual Studio user, you can open the generated `CSE2.sln` file instead.
Once built, the executables and assets can be found in the newly-generated `game` folder. Once built, the executables can be found in the `game_english`/`game_japanese` folder, depending on the selected language.
### Makefile ### Makefile
@ -98,7 +96,6 @@ Name | Function
`RELEASE=1` | Compile a release build (optimised, stripped, etc.) `RELEASE=1` | Compile a release build (optimised, stripped, etc.)
`STATIC=1` | Produce a statically-linked executable (good for Windows builds, so you don't need to bundle DLL files) `STATIC=1` | Produce a statically-linked executable (good for Windows builds, so you don't need to bundle DLL files)
`LTO=1` | Enable link-time optimisation `LTO=1` | Enable link-time optimisation
`NATIVE_OPTIMIZATIONS=1` | Enable processor-specific optimisations (executable might not work on other architectures)
`JAPANESE=1` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation) `JAPANESE=1` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)
`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
@ -110,9 +107,8 @@ Name | Function
`BACKEND_RENDERER=Software` | Use the hand-written software renderer `BACKEND_RENDERER=Software` | Use the hand-written software renderer
`BACKEND_AUDIO=SDL2` | Use the SDL2-driven software audio-mixer `BACKEND_AUDIO=SDL2` | Use the SDL2-driven software audio-mixer
`BACKEND_AUDIO=miniaudio` | Use the miniaudio-driven software audio-mixer `BACKEND_AUDIO=miniaudio` | Use the miniaudio-driven software audio-mixer
`WARNINGS=1` | Enable common compiler warnings
`WARNINGS_ALL=1` | Enable ALL compiler warnings (Clang only) You can pass your own compiler flags by defining `CXXFLAGS`.
`WARNINGS_FATAL=1` | Make all compiler warnings errors
Once built, the executables can be found in the `game_english`/`game_japanese` folder, depending on the selected language. Once built, the executables can be found in the `game_english`/`game_japanese` folder, depending on the selected language.