build: add -Dpie option

It is becoming increasingly common for distributions to want to enable
PIE for all binaries and zig currently does not provide any way to do
so aside from patching the build.zig.
This commit is contained in:
Isaac Freund
2023-03-08 14:21:33 +01:00
committed by Andrew Kelley
parent 06b263825a
commit 3e99afdbfe
2 changed files with 9 additions and 0 deletions

View File

@@ -827,6 +827,12 @@ else()
set(ZIG_STATIC_ARG "")
endif()
if(CMAKE_POSITION_INDEPENDENT_CODE)
set(ZIG_PIE_ARG="-Dpie")
else()
set(ZIG_PIE_ARG="")
endif()
set(ZIG_BUILD_ARGS
--zig-lib-dir "${CMAKE_SOURCE_DIR}/lib"
"-Dconfig_h=${ZIG_CONFIG_H_OUT}"
@@ -835,6 +841,7 @@ set(ZIG_BUILD_ARGS
${ZIG_STATIC_ARG}
${ZIG_NO_LIB_ARG}
${ZIG_SINGLE_THREADED_ARG}
${ZIG_PIE_ARG}
"-Dtarget=${ZIG_TARGET_TRIPLE}"
"-Dcpu=${ZIG_TARGET_MCPU}"
"-Dversion-string=${RESOLVED_ZIG_VERSION}"