Skip to content

cmake: Add ZIG_RELEASE_SAFE option to build as ReleaseSafe #23217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -938,12 +938,24 @@ 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("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
list(APPEND ZIG_BUILD_ARGS -Doptimize=ReleaseSmall)
else()
# 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()

if(ZIG_STATIC AND NOT MSVC)
Expand Down
Loading