From 864528bb7b8c2ad44069f1ee09b5ed08d5865cd3 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 16 Aug 2014 20:46:55 -0700 Subject: Use the POSITION_INDEPENDENT_CODE target property when available --- CMakeLists.txt | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 408ba364..29d359e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -248,13 +248,15 @@ ELSE() ADD_DEFINITIONS(-Werror) ENDIF() - # Force enable PIC if available. The static common library will be linked - # into the dynamic openal library, which requires all its code to be - # position-independent, and CMake doesn't automatically enable PIC for - # static library targets (Windows code is always position-independent). - CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH) - IF(HAVE_FPIC_SWITCH AND NOT WIN32) - ADD_DEFINITIONS(-fPIC) + # Force enable -fPIC for CMake versions before 2.8.9 (later versions have + # the POSITION_INDEPENDENT_CODE target property). The static common library + # will be linked into the dynamic openal library, which requires all its + # code to be position-independent. + IF(CMAKE_VERSION VERSION_LESS "2.8.9" AND NOT WIN32) + CHECK_C_COMPILER_FLAG(-fPIC HAVE_FPIC_SWITCH) + IF(HAVE_FPIC_SWITCH) + ADD_DEFINITIONS(-fPIC) + ENDIF() ENDIF() # We want RelWithDebInfo to actually include debug stuff (define _DEBUG @@ -1015,6 +1017,9 @@ CONFIGURE_FILE( # Build a common library with reusable helpers ADD_LIBRARY(common STATIC ${COMMON_OBJS}) +IF(NOT LIBTYPE STREQUAL "STATIC") + SET_PROPERTY(TARGET common PROPERTY POSITION_INDEPENDENT_CODE TRUE) +ENDIF() # Build main library ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS}) -- cgit v1.2.3