aboutsummaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-08-16 20:46:55 -0700
committerChris Robinson <[email protected]>2014-08-16 20:46:55 -0700
commit864528bb7b8c2ad44069f1ee09b5ed08d5865cd3 (patch)
tree258b5679a3bb8bfc079cf087afe96b2f3faed888 /CMakeLists.txt
parent4a7e04add3e70b0dc1741bcad15f6c1058ca80d5 (diff)
Use the POSITION_INDEPENDENT_CODE target property when available
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt19
1 files changed, 12 insertions, 7 deletions
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})