CMake/Modules/Platform/Android/abi-common.cmake
Brad King 4c272adbe1 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
2016-10-24 11:45:18 -04:00

20 lines
544 B
CMake

string(APPEND _ANDROID_ABI_INIT_CFLAGS
" -funwind-tables"
" -no-canonical-prefixes"
)
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE
AND NOT CMAKE_SYSTEM_VERSION VERSION_LESS 16)
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)
string(APPEND _ANDROID_ABI_INIT_EXE_LDFLAGS " -Wl,-z,nocopyreloc")
endif()