CMake: Let static libraries optionally be built with Position Independent Code.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 05 Jan 2016 01:26:32 -0500
changeset 10013 9f758c4d746a
parent 10012 ed02c7a84612
child 10014 906340c8c820
CMake: Let static libraries optionally be built with Position Independent Code.
CMakeLists.txt
--- a/CMakeLists.txt	Tue Jan 05 01:25:54 2016 -0500
+++ b/CMakeLists.txt	Tue Jan 05 01:26:32 2016 -0500
@@ -310,6 +310,8 @@
 set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
 set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
 
+dep_option(SDL_STATIC_PIC      "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
+
 # General source files
 file(GLOB SOURCE_FILES
   ${SDL2_SOURCE_DIR}/src/*.c
@@ -1461,6 +1463,9 @@
 message(STATUS "")
 message(STATUS " Build Shared Library: ${SDL_SHARED}")
 message(STATUS " Build Static Library: ${SDL_STATIC}")
+if(SDL_STATIC)
+    message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}")
+endif()
 message(STATUS "")
 if(UNIX)
   message(STATUS "If something was not detected, although the libraries")
@@ -1503,6 +1508,7 @@
   set (BUILD_SHARED_LIBS FALSE)
   add_library(SDL2-static STATIC ${SOURCE_FILES})
   set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
+  set_target_properties(SDL2-static PROPERTIES POSITION_INDEPENDENT_CODE ${SDL_STATIC_PIC})
   if(MSVC)
     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
     set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")