Skip to content

Commit

Permalink
Apply default build configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
carstene1ns committed Mar 4, 2022
1 parent ea79af5 commit 41efb7d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(EasyRPG_Player VERSION 0.7.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules")
include(ConfigureWindows)
include(PlayerFindPackage)
include(PlayerBuildType)

# C++14 is required
set(CMAKE_CXX_STANDARD 14)
Expand Down Expand Up @@ -595,10 +596,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
target_sources(${PROJECT_NAME} PRIVATE src/external/picojson.h)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${PROJECT_NAME} PUBLIC _DEBUG=1)
endif()

# Endianess check
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
include(TestBigEndian)
Expand Down Expand Up @@ -881,15 +878,13 @@ if(${PLAYER_BUILD_EXECUTABLE} AND ${PLAYER_TARGET_PLATFORM} STREQUAL "SDL2")
set_target_properties("${EXE_NAME}" PROPERTIES OUTPUT_NAME "EasyRPG Player")
else()
set(EXE_NAME ${PROJECT_NAME}_exe)
add_executable(${EXE_NAME} WIN32 "src/main.cpp")
add_executable(${EXE_NAME} "src/main.cpp")
set_target_properties(${EXE_NAME} PROPERTIES OUTPUT_NAME "easyrpg-player")
endif()

if(WIN32)
# Open console for Debug builds
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set_target_properties(${EXE_NAME} PROPERTIES WIN32_EXECUTABLE FALSE)
endif()
set_target_properties(${EXE_NAME} PROPERTIES WIN32_EXECUTABLE $<NOT:CONFIG:Debug>)

# Add resources
target_sources(${EXE_NAME} PRIVATE "resources/player.rc")
Expand Down
26 changes: 26 additions & 0 deletions builds/cmake/Modules/PlayerBuildType.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Allow user override and multi-configuration generators
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
# Set build type if none was specified, git checkouts default to debug
set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "Debug")
endif()
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
else()
message(STATUS "Build type is set to ${CMAKE_BUILD_TYPE}.")
endif()

# Ensure needed debugging flags are passed
add_compile_definitions($<$<CONFIG:Debug>:_DEBUG>$<$<CONFIG:Release,MinSizeRel,RelWithDebInfo>:NDEBUG>)

# Since dkp is disabling default flags, add optimizing here
if(NINTENDO_WII OR NINTENDO_3DS OR NINTENDO_SWITCH)
foreach(lang C CXX ASM)
string(APPEND CMAKE_${lang}_FLAGS_DEBUG " -g -O0")
string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL " -Os")
string(APPEND CMAKE_${lang}_FLAGS_RELEASE " -O3")
string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO " -g -O2")
endforeach()
endif()

0 comments on commit 41efb7d

Please sign in to comment.