From fec8a2c4bd22f03b87467af47e4841e39931101c Mon Sep 17 00:00:00 2001 From: Username404 Date: Mon, 8 Aug 2022 12:42:39 +0200 Subject: [PATCH] CMakeLists.txt: Notify the user when CMAKE_POSITION_INDEPENDENT_CODE was defined on the command line although UPX is in use Signed-off-by: Username404 --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1288473..ed8a818 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) include(CheckPIESupported) check_pie_supported(LANGUAGES CXX) +set(USER_DEFINED_PIE (DEFINED CMAKE_POSITION_INDEPENDENT_CODE)) if (CMAKE_CXX_LINK_PIE_SUPPORTED) - if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE) + if (NOT USER_DEFINED_PIE) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) endif() else() @@ -161,6 +162,9 @@ if (NOT (UPPERCASE_BUILD_TYPE STREQUAL "DEBUG" OR UPPERCASE_BUILD_TYPE STREQUAL 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)") + endif() set(CMAKE_POSITION_INDEPENDENT_CODE FALSE) set_target_properties(${EXENAME} PROPERTIES POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE}) endif()