diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f9da6bb3d..b68e9ddedc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,17 +172,6 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|AMD64") add_definitions(-D_M_X86=1) add_definitions(-D_M_X86_64=1) check_and_add_flag(HAVE_SSE2 -msse2) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") - if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) - CHECK_C_COMPILER_FLAG("-no-pie" NO_PIE_UPSTREAM) - if(NO_PIE_UPSTREAM) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie") - endif() - CHECK_C_COMPILER_FLAG("-nopie" NO_PIE_PATCHED) - if(NO_PIE_PATCHED) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nopie") - endif() - endif() elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") set(_M_ARM 1) set(_M_ARM_64 1) @@ -233,6 +222,19 @@ else() if(FLAG_C_FOMIT_FRAME_POINTER) add_compile_options($<$:-fomit-frame-pointer>) endif() + + if(NOT ANDROID AND _M_X86_64) + # PIE is required on Android, but not supported with the x86_64 jit currently + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie") + check_c_compiler_flag("-no-pie" NO_PIE_UPSTREAM) + if(NO_PIE_UPSTREAM) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -no-pie") + endif() + check_c_compiler_flag("-nopie" NO_PIE_PATCHED) + if(NO_PIE_PATCHED) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nopie") + endif() + endif() endif() if(CMAKE_SYSTEM_NAME MATCHES "Windows")