feat: release build possibility
This commit is contained in:
@ -1,6 +1,12 @@
|
|||||||
cmake_minimum_required(VERSION 3.16)
|
cmake_minimum_required(VERSION 3.16)
|
||||||
project(CodingGame LANGUAGES C CXX)
|
project(CodingGame LANGUAGES C CXX)
|
||||||
|
|
||||||
|
# ---------- Build-type defaults (only affects single-config generators like Ninja/Make) ----------
|
||||||
|
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---------- Dependencies ----------
|
||||||
if (UNIX)
|
if (UNIX)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
@ -20,10 +26,6 @@ elseif (MSVC) # vcpkg
|
|||||||
find_package(glm CONFIG REQUIRED)
|
find_package(glm CONFIG REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Add -ggdb to debug builds
|
|
||||||
# set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb")
|
|
||||||
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb")
|
|
||||||
|
|
||||||
add_executable(CodingGame
|
add_executable(CodingGame
|
||||||
src/IO/parser.cpp
|
src/IO/parser.cpp
|
||||||
src/IO/file_manager.cpp
|
src/IO/file_manager.cpp
|
||||||
@ -54,7 +56,15 @@ target_link_libraries(CodingGame PRIVATE
|
|||||||
glm::glm
|
glm::glm
|
||||||
)
|
)
|
||||||
|
|
||||||
# Debug flags
|
# ---------- Visibility (helps optimizer & smaller binaries on Release) ----------
|
||||||
|
# Only affects non-Windows compilers
|
||||||
|
set_target_properties(CodingGame PROPERTIES
|
||||||
|
CXX_VISIBILITY_PRESET hidden
|
||||||
|
VISIBILITY_INLINES_HIDDEN YES
|
||||||
|
)
|
||||||
|
|
||||||
|
# ---------- Per-config flags ----------
|
||||||
|
# Debug flags (your original intent, kept)
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/Zi>)
|
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/Zi>)
|
||||||
target_link_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
|
target_link_options(CodingGame PRIVATE $<$<CONFIG:Debug>:/DEBUG:FULL>)
|
||||||
@ -62,6 +72,44 @@ else()
|
|||||||
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:-ggdb>)
|
target_compile_options(CodingGame PRIVATE $<$<CONFIG:Debug>:-ggdb>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Release flags
|
||||||
|
if (MSVC)
|
||||||
|
# /O2: optimize speed, /GL: whole program opt (LTCG), /DNDEBUG: disable asserts
|
||||||
|
target_compile_options(CodingGame PRIVATE
|
||||||
|
$<$<CONFIG:Release>:/O2>
|
||||||
|
$<$<CONFIG:Release>:/DNDEBUG>
|
||||||
|
$<$<CONFIG:RelWithDebInfo>:/O2>
|
||||||
|
)
|
||||||
|
# Link-time codegen & extra linker opts for smaller/faster binaries
|
||||||
|
target_link_options(CodingGame PRIVATE
|
||||||
|
$<$<CONFIG:Release>:/LTCG /OPT:ICF /OPT:REF>
|
||||||
|
$<$<CONFIG:RelWithDebInfo>:/LTCG /OPT:ICF /OPT:REF>
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
# GCC/Clang
|
||||||
|
# -O3 for max opts, -ffast-math optional but can be risky; we keep it OFF by default.
|
||||||
|
option(CODINGGAME_USE_MARCH_NATIVE "Enable -march=native on Release for this machine" ON)
|
||||||
|
target_compile_options(CodingGame PRIVATE
|
||||||
|
$<$<CONFIG:Release>:-O3>
|
||||||
|
$<$<AND:$<CONFIG:Release>,$<BOOL:${CODINGGAME_USE_MARCH_NATIVE}>>:-march=native>
|
||||||
|
$<$<CONFIG:Release>:-DNDEBUG>
|
||||||
|
$<$<CONFIG:RelWithDebInfo>:-O3 -g>
|
||||||
|
)
|
||||||
|
# Linker: enable LTO when available; optionally strip symbols on non-Apple
|
||||||
|
include(CheckIPOSupported) # IPO == LTO in CMake terms
|
||||||
|
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_msg)
|
||||||
|
if(ipo_supported)
|
||||||
|
set_property(TARGET CodingGame PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
|
||||||
|
set_property(TARGET CodingGame PROPERTY INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT APPLE)
|
||||||
|
# -s strips symbols at link stage (use only for pure Release)
|
||||||
|
target_link_options(CodingGame PRIVATE $<$<CONFIG:Release>:-s>)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---------- Windows: copy runtime DLLs ----------
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
add_custom_command(TARGET CodingGame POST_BUILD
|
add_custom_command(TARGET CodingGame POST_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||||||
|
Reference in New Issue
Block a user