From 4c272adbe1d67af4779f4e72d9562457ed851dac Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Mon, 24 Oct 2016 11:45:18 -0400
Subject: Android: Link position-independent executables with proper flags

Add `-fPIE -pie` to the default executable link flags when
`CMAKE_POSITION_INDEPENDENT_CODE` is enabled.  This is required by
Android 16 and above for executables to run on the device.

Closes: #16382
---
 Modules/Platform/Android/abi-common.cmake | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Modules/Platform/Android/abi-common.cmake b/Modules/Platform/Android/abi-common.cmake
index 533bd90..3b0eb01 100644
--- a/Modules/Platform/Android/abi-common.cmake
+++ b/Modules/Platform/Android/abi-common.cmake
@@ -8,6 +8,10 @@ if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE
   set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 endif()
 
+if(CMAKE_POSITION_INDEPENDENT_CODE)
+  string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -fPIE -pie")
+endif()
+
 string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -Wl,--gc-sections")
 
 if(NOT _ANDROID_ABI_INIT_EXE_LDFLAGS_NO_nocopyreloc)
-- 
cgit v0.12