From 7ed0286e8cd40367ab6ba7f100e3b30d9d1ae383 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 28 Jan 2026 01:27:02 +0100 Subject: opt: Implement build stripping and platform-specific size optimizations Adds a 'STRIP_ALL' mode to minimize binary size for the final build, and refines size optimization flags for macOS. - **STRIP_ALL Mode**: Added a 'DEMO_STRIP_ALL' CMake option that defines 'STRIP_ALL'. In this mode, command-line parsing is bypassed (forcing fullscreen), debug labels/error callbacks are removed from WebGPU, and non-essential code (like iostream) is stripped. - **macOS Optimizations**: Updated CMake to use '-dead_strip' instead of GNU '--gc-sections' on Apple platforms to resolve linker errors and improve dead code elimination. - **Documentation**: Updated HOWTO.md to document the new 'Final / Strip Build' process and FETCH_DEPS.md for optimized wgpu-native build guidance. - **Task 7 & 8**: Marks these tasks as completed in PROJECT_CONTEXT.md. --- CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index fc4ea81..1238a8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.16) project(demo64k LANGUAGES C CXX) option(DEMO_SIZE_OPT "Enable size optimization flags" OFF) +option(DEMO_STRIP_ALL "Strip all unnecessary code for final build" OFF) + +if (DEMO_STRIP_ALL) + add_definitions(-DSTRIP_ALL) + set(DEMO_SIZE_OPT ON) +endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -53,6 +59,9 @@ if (DEMO_SIZE_OPT) if (MSVC) target_compile_options(demo64k PRIVATE /Os /GS-) target_link_options(demo64k PRIVATE /OPT:REF /OPT:ICF /INCREMENTAL:NO) + elseif (APPLE) + target_compile_options(demo64k PRIVATE -Os) + target_link_options(demo64k PRIVATE -Wl,-dead_strip) else() target_compile_options(demo64k PRIVATE -Os -ffunction-sections -fdata-sections) target_link_options(demo64k PRIVATE -Wl,--gc-sections -s) -- cgit v1.2.3