aboutsummaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-05-07 19:51:42 -0700
committerChris Robinson <[email protected]>2014-05-07 19:51:42 -0700
commitbd88e1743a65209b34863b542939b0239b25edaa (patch)
tree5f9d67e463c9c9ff44ed5170838d8556b12180e9 /CMakeLists.txt
parenta2bddb7b40960b3a8680afa0ab31e99d204dece1 (diff)
Build a common static lib for reusable code
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt18
1 files changed, 15 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aae35f5f..ace3633c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -227,6 +227,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)
+ ENDIF()
+
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O2 -D_DEBUG" CACHE STRING
"Flags used by the compiler during Release with Debug Info builds."
FORCE)
@@ -930,8 +939,11 @@ CONFIGURE_FILE(
"${OpenAL_BINARY_DIR}/openal.pc"
@ONLY)
-# Build a library
-ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${COMMON_OBJS} ${OPENAL_OBJS} ${ALC_OBJS})
+# Build a common library with reusable helpers
+ADD_LIBRARY(common STATIC ${COMMON_OBJS})
+
+# Build main library
+ADD_LIBRARY(${LIBNAME} ${LIBTYPE} ${OPENAL_OBJS} ${ALC_OBJS})
SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_BUILD_LIBRARY AL_ALEXT_PROTOTYPES)
IF(WIN32 AND ALSOFT_NO_UID_DEFS)
SET_PROPERTY(TARGET ${LIBNAME} APPEND PROPERTY COMPILE_DEFINITIONS AL_NO_UID_DEFS)
@@ -970,7 +982,7 @@ IF(WIN32 AND NOT LIBTYPE STREQUAL "STATIC")
SET_TARGET_PROPERTIES(${LIBNAME} PROPERTIES PREFIX "")
ENDIF()
-TARGET_LINK_LIBRARIES(${LIBNAME} ${EXTRA_LIBS})
+TARGET_LINK_LIBRARIES(${LIBNAME} common ${EXTRA_LIBS})
# Add an install target here
INSTALL(TARGETS ${LIBNAME}