From 84cc01b8f0172250846ee2a03bdedc50055e9339 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 14 Mar 2020 20:12:33 +0000 Subject: [PATCH 1/5] Remove LTO from the Makefile Can also be done by adding to CXXFLAGS The CMake one will be kept around because it uses an actual CMake feature. --- Makefile | 4 ---- README.md | 1 - 2 files changed, 5 deletions(-) diff --git a/Makefile b/Makefile index aa2206db..5cc0406d 100644 --- a/Makefile +++ b/Makefile @@ -15,10 +15,6 @@ else FILENAME_DEF = CSE2_debug.exe endif -ifeq ($(LTO), 1) - ALL_CXXFLAGS += -flto -endif - ifeq ($(JAPANESE), 1) BUILD_DIRECTORY = game_japanese diff --git a/README.md b/README.md index f92c92e1..23138ace 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,6 @@ Name | Function --------|-------- `RELEASE=1` | Compile a release build (optimised, stripped, etc.) `STATIC=1` | Produce a statically-linked executable (so you don't need to bundle DLL files) -`LTO=1` | Enable link-time optimisation `JAPANESE=1` | Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation) `FIX_BUGS=1` | Fix various bugs in the game `DEBUG_SAVE=1` | Re-enable the dummied-out 'Debug Save' option, and the ability to drag-and-drop save files onto the window From 216aec7caf5bfd0e85153f38ac9186726868703a Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 14 Mar 2020 20:19:48 +0000 Subject: [PATCH 2/5] Clean-up CMake LTO Honestly, considering the user can enable LTO by setting CMAKE_INTERPROCEDURAL_OPTIMIZATION, I might remove this option too... --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 36e066a3..4ef3d7c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,12 +209,12 @@ set_target_properties(CSE2 PROPERTIES # Enable link-time optimisation if available if(LTO) - if((${CMAKE_VERSION} VERSION_EQUAL 3.9) OR (${CMAKE_VERSION} VERSION_GREATER 3.9)) - include(CheckIPOSupported) - check_ipo_supported(RESULT result) - if(result) - set_target_properties(CSE2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) - endif() + include(CheckIPOSupported) + + check_ipo_supported(RESULT result) + + if(result) + set_target_properties(CSE2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) endif() endif() From cadfeab385214a8b233f1669b019e44dedf7e133 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 14 Mar 2020 20:26:59 +0000 Subject: [PATCH 3/5] Neaten-up the CMake file --- CMakeLists.txt | 77 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ef3d7c4..db59d387 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,17 @@ cmake_minimum_required(VERSION 3.12) + +############# +# Constants # +############# + set(ASSETS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets") + +########### +# Options # +########### + 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 dummied-out 'Debug Save' option, and the ability to drag-and-drop save files onto the window" OFF) @@ -9,21 +19,13 @@ option(DEBUG_SAVE "Re-enable the dummied-out 'Debug Save' option, and the abilit option(LTO "Enable link-time optimisation" OFF) option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library" OFF) + +######### +# Setup # +######### + project(CSE2 LANGUAGES C CXX) -if(MSVC AND MSVC_LINK_STATIC_RUNTIME) - # 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) - if(${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif() - endforeach() -endif() - -## -# CSE2 -## - add_executable(CSE2 "src/ArmsItem.cpp" "src/ArmsItem.h" @@ -150,7 +152,11 @@ add_executable(CSE2 "src/WindowsWrapper.h" ) -# Handle options + +################### +# Option handling # +################### + if(JAPANESE) set(BUILD_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/game_japanese") target_compile_definitions(CSE2 PRIVATE JAPANESE) @@ -166,6 +172,32 @@ if(DEBUG_SAVE) target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE) endif() +if(LTO) + include(CheckIPOSupported) + + check_ipo_supported(RESULT result) + + if(result) + set_target_properties(CSE2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) + endif() +endif() + +# This is messy as hell, and has been replaced by CMAKE_MSVC_RUNTIME_LIBRARY, +# but that's a very recent CMake addition, so we're still doing it this way for now +if(MSVC AND MSVC_LINK_STATIC_RUNTIME) + # 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) + if(${flag_var} MATCHES "/MD") + string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") + endif() + endforeach() +endif() + + +########## +# Tweaks # +########## + # Make some tweaks if we're targetting Windows #if(WIN32) target_sources(CSE2 PRIVATE "${ASSETS_DIRECTORY}/resources/CSE2.rc") @@ -181,6 +213,11 @@ if(MSVC) target_compile_options(CSE2 PRIVATE "/utf-8") endif() + +################## +# Misc. settings # +################## + # Force strict C90 set_target_properties(CSE2 PROPERTIES C_STANDARD 90 @@ -207,16 +244,10 @@ set_target_properties(CSE2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BUILD_DIRECTORY} ) -# Enable link-time optimisation if available -if(LTO) - include(CheckIPOSupported) - check_ipo_supported(RESULT result) - - if(result) - set_target_properties(CSE2 PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE) - endif() -endif() +################ +# Dependencies # +################ # Link libraries target_link_libraries(CSE2 PRIVATE ddraw.lib dsound.lib Version.lib ShLwApi.Lib Imm32.lib WinMM.lib dxguid.lib) From 4ef83526c0cff97069dd3a28778a03325e9fb32c Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 14 Mar 2020 21:59:42 +0000 Subject: [PATCH 4/5] More CMake cleanup --- CMakeLists.txt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db59d387..b201debd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,8 @@ option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library" OFF) project(CSE2 LANGUAGES C CXX) -add_executable(CSE2 +add_executable(CSE2 WIN32 + "${ASSETS_DIRECTORY}/resources/CSE2.rc" "src/ArmsItem.cpp" "src/ArmsItem.h" "src/Back.cpp" @@ -198,12 +199,6 @@ endif() # Tweaks # ########## -# Make some tweaks if we're targetting Windows -#if(WIN32) - target_sources(CSE2 PRIVATE "${ASSETS_DIRECTORY}/resources/CSE2.rc") - set_target_properties(CSE2 PROPERTIES WIN32_EXECUTABLE YES) # Disable the console window -#endif() - # Make some tweaks if we're using MSVC if(MSVC) # Disable warnings that normally fire up on MSVC when using "unsafe" functions instead of using MSVC's "safe" _s functions From e96619141bef8da194dd693b547db9e338fb10d0 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Sat, 14 Mar 2020 22:02:06 +0000 Subject: [PATCH 5/5] Update Travis file to use CXXFLAGS --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0802dd6f..eaa9960e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -121,7 +121,7 @@ install: script: # Build - - $mingw make -j ${JOBS} FIX_BUGS=${FIX_BUGS} JAPANESE=${JAPANESE} RELEASE=1 WARNINGS=1 WARNINGS_ALL=1 WINDOWS=1 STATIC=1 + - $mingw make -j ${JOBS} FIX_BUGS=${FIX_BUGS} JAPANESE=${JAPANESE} RELEASE=1 WINDOWS=1 STATIC=1 CXXFLAGS="-Wall -Wextra -pedantic" after_success: # Send success notification to Discord through DISCORD_WEBHOOK_URL