From 1204d3dfcc13ba6feba0e0a68938dea3567ff6f3 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 14 Sep 2016 01:15:18 -0400 Subject: [PATCH] Add -fPIC for builds except for 32-bit x86 and Windows --- CMakeLists.txt | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e91bd12..ff66a422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,10 +36,27 @@ set(CRYPTOPP_DATA_DIR "" CACHE PATH "Crypto++ test data directory") # Stop hiding the damn output... set(CMAKE_VERBOSE_MAKEFILE on) -# Enable PIC for all targets except 32-bit x86 -#if (CMAKE_SYSTEM_PROCESSOR) -# set (CMAKE_CXX_FLAGS "$CMAKE_CXX_FLAGS -fPIC") -#endif() +# Enable PIC for all targets except Windows and 32-bit x86. +# Avoid on 32-bit x86 due to register pressures. +if (NOT (WINDOWS OR WINDOWS_STORE OR WINDOWS_PHONE)) + + set (UNAME_CMD "uname") + set (UNAME_ARG "-m") + execute_process(COMMAND ${UNAME_CMD} ${UNAME_ARG} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + RESULT_VARIABLE UNAME_RESULT + OUTPUT_VARIABLE UNAME_MACHINE) + + # Use Regex; match i386, i486, i586 and i686 + if (NOT (${UNAME_MACHINE} MATCHES "i.86")) + # message(STATUS "Setting -fPIC for machine ${UNAME_MACHINE}") + if (CMAKE_VERSION VERSION_LESS 2.8.12) + add_definitions(-fPIC) + else() + add_compile_options(-fPIC) + endif() + endif() +endif() # Don't use RPATH's. The resulting binary could fail a security audit. if (NOT CMAKE_VERSION VERSION_LESS 2.8.12)