From 19888f759fc8612f3627a1b9c898d0b7aa513119 Mon Sep 17 00:00:00 2001 From: LN Liberda Date: Wed, 12 Mar 2025 18:15:42 +0100 Subject: [PATCH 1/2] cmake: Add ZIG_RELEASE_SAFE option to build as ReleaseSafe --- CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea25212fec73..dc6b714ef9e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -938,12 +938,19 @@ if(ZIG_EXTRA_BUILD_ARGS) list(APPEND ZIG_BUILD_ARGS ${ZIG_EXTRA_BUILD_ARGS}) endif() +set(ZIG_RELEASE_SAFE OFF CACHE BOOL "Build Zig as ReleaseSafe (with debug assertions on)") + if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") list(APPEND ZIG_BUILD_ARGS -Doptimize=Debug) -elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast) else() - list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast -Dstrip) + if(ZIG_RELEASE_SAFE) + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSafe) + else() + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast) + endif() + if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + list(APPEND ZIG_BUILD_ARGS -Dstrip) + endif() endif() if(ZIG_STATIC AND NOT MSVC) From f2363623e1eb4c0b12b9a8f795e5ce02053ec1f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 16 Apr 2025 20:46:41 +0200 Subject: [PATCH 2/2] cmake: Map MinSizeRel to ReleaseSmall. --- CMakeLists.txt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dc6b714ef9e6..eb31d1ac9333 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -943,13 +943,18 @@ set(ZIG_RELEASE_SAFE OFF CACHE BOOL "Build Zig as ReleaseSafe (with debug assert if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") list(APPEND ZIG_BUILD_ARGS -Doptimize=Debug) else() - if(ZIG_RELEASE_SAFE) - list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSafe) + if("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSmall) else() - list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast) - endif() - if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") - list(APPEND ZIG_BUILD_ARGS -Dstrip) + # Release and RelWithDebInfo + if(ZIG_RELEASE_SAFE) + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSafe) + else() + list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseFast) + endif() + if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + list(APPEND ZIG_BUILD_ARGS -Dstrip) + endif() endif() endif()