From b8bb1181d123c930e78d6e5b1db9d9a2c7244401 Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 8 Aug 2022 13:15:58 +0200 Subject: [PATCH] CMakeLists.txt: Disable UPX when position-dependent executables are not supported by the compiler Signed-off-by: Username404 --- CMakeLists.txt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dd8a3b..14d66cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,12 +161,17 @@ option(NO_SELF_PACKER "Disables usage of a self-packer") if (NOT (UPPERCASE_BUILD_TYPE STREQUAL "DEBUG" OR UPPERCASE_BUILD_TYPE STREQUAL "RELWITHDEBINFO" OR NO_SELF_PACKER OR DEFINED EMSCRIPTEN OR MINGW)) include(FindSelfPackers) if (SELF_PACKER_FOR_EXECUTABLE MATCHES upx) # UPX version d61edc9 or higher is required when using a cross-compiler to target the musl C library - set(SELF_PACKER_FOR_EXECUTABLE_FLAGS ${SELF_PACKER_FOR_EXECUTABLE_FLAGS} --ultra-brute --best) - if (USER_DEFINED_PIE AND CMAKE_POSITION_INDEPENDENT_CODE) - message(NOTICE "-- Could NOT manually enable PIE (UPX is in use)") + if (CMAKE_CXX_LINK_NO_PIE_SUPPORTED) + set(SELF_PACKER_FOR_EXECUTABLE_FLAGS ${SELF_PACKER_FOR_EXECUTABLE_FLAGS} --ultra-brute --best) + if (USER_DEFINED_PIE AND CMAKE_POSITION_INDEPENDENT_CODE) + message(NOTICE "-- Could NOT manually enable PIE (UPX is in use)") + endif() + set(CMAKE_POSITION_INDEPENDENT_CODE FALSE) + set_target_properties(${EXENAME} PROPERTIES POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) + else() + set(SELF_PACKER_FOR_EXECUTABLE "SELF_PACKER_FOR_EXECUTABLE-NOTFOUND") + message(NOTICE "UPX usage has been disabled because position-dependent executables are unsupported by the current compiler") endif() - set(CMAKE_POSITION_INDEPENDENT_CODE FALSE) - set_target_properties(${EXENAME} PROPERTIES POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) endif() if (NOT SELF_PACKER_FOR_EXECUTABLE STREQUAL "SELF_PACKER_FOR_EXECUTABLE-NOTFOUND") add_custom_command(TARGET ${EXENAME} POST_BUILD COMMAND "${SELF_PACKER_FOR_EXECUTABLE}" ${SELF_PACKER_FOR_EXECUTABLE_FLAGS} $ VERBATIM)