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 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-08-08 12:42:39 +02:00
parent 510e7a24f3
commit fec8a2c4bd
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 5 additions and 1 deletions

View File

@ -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()