Add support for building position-independent executables.
This commit is contained in:
@@ -22,6 +22,7 @@ set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
|
|||||||
option(WITH_TESTS "Enable building of unit tests" ON)
|
option(WITH_TESTS "Enable building of unit tests" ON)
|
||||||
option(WITH_GUI_TESTS "Enable building of GUI tests" OFF)
|
option(WITH_GUI_TESTS "Enable building of GUI tests" OFF)
|
||||||
option(WITH_LTO "Enable Link Time Optimization (LTO)" OFF)
|
option(WITH_LTO "Enable Link Time Optimization (LTO)" OFF)
|
||||||
|
option(WITH_PIE "Build as Position-independent executable (PIE)" OFF)
|
||||||
|
|
||||||
set( KEEPASSX_VERSION "0.9.0" )
|
set( KEEPASSX_VERSION "0.9.0" )
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|||||||
if(WITH_LTO)
|
if(WITH_LTO)
|
||||||
include(CheckCXXCompilerFlag)
|
include(CheckCXXCompilerFlag)
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
if(CMAKE_COMPILER_IS_GNUCC and CMAKE_COMPILER_IS_GNUCXX)
|
||||||
check_cxx_compiler_flag("-flto -fuse-linker-plugin" LTO_AVAILABLE)
|
check_cxx_compiler_flag("-flto -fuse-linker-plugin" LTO_AVAILABLE)
|
||||||
|
|
||||||
if(LTO_AVAILABLE)
|
if(LTO_AVAILABLE)
|
||||||
@@ -90,9 +91,18 @@ if(WITH_LTO)
|
|||||||
endif(LTO_AVAILABLE)
|
endif(LTO_AVAILABLE)
|
||||||
else()
|
else()
|
||||||
message(FATAL_ERROR "LTO is only supported with gcc")
|
message(FATAL_ERROR "LTO is only supported with gcc")
|
||||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
endif(CMAKE_COMPILER_IS_GNUCC and CMAKE_COMPILER_IS_GNUCXX)
|
||||||
endif(WITH_LTO)
|
endif(WITH_LTO)
|
||||||
|
|
||||||
|
if(WITH_PIE)
|
||||||
|
if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX))
|
||||||
|
add_gcc_compiler_flags("-fPIE")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "PIE is only supported with gcc and clang")
|
||||||
|
endif((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG) AND (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX))
|
||||||
|
endif(WITH_PIE)
|
||||||
|
|
||||||
if( APPLE OR MINGW )
|
if( APPLE OR MINGW )
|
||||||
set( PROGNAME KeePassX )
|
set( PROGNAME KeePassX )
|
||||||
else( APPLE OR MINGW )
|
else( APPLE OR MINGW )
|
||||||
|
|||||||
Reference in New Issue
Block a user