build: use POSITION_INDEPENDENT_CODE CMake property

Use the POSITION_INDEPENDENT_CODE target property to indicate that we
should be building with -fPIC or the equivalent flag based on the
toolchain that we are using.  This makes the check more portable and
simplifies the flags management.  Because we don't want this setting to
propagate in the case of an in-tree build, set the property on the
targets we construct explicitly rather than setting
CMAKE_POSITION_INDEPENDENT_CODE to ON globally.

git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@305174 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ac2c3a6..d4a68fc 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -77,7 +77,6 @@
 endif()
 
 # Setup flags.
-add_compile_flags_if_supported(-fPIC)
 add_link_flags_if_supported(-nodefaultlibs)
 
 set(LIBCXXABI_SHARED_LINK_FLAGS)
@@ -110,11 +109,12 @@
 
 # Add a object library that contains the compiled source files.
 add_library(cxxabi_objects OBJECT ${LIBCXXABI_SOURCES} ${LIBCXXABI_HEADERS})
-
 set_target_properties(cxxabi_objects
-  PROPERTIES
-    COMPILE_FLAGS "${LIBCXXABI_COMPILE_FLAGS}"
-  )
+                      PROPERTIES
+                        COMPILE_FLAGS
+                          "${LIBCXXABI_COMPILE_FLAGS}"
+                        POSITION_INDEPENDENT_CODE
+                          ON)
 
 set(LIBCXXABI_TARGETS)
 
@@ -123,12 +123,17 @@
   add_library(cxxabi_shared SHARED $<TARGET_OBJECTS:cxxabi_objects>)
   target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES})
   set_target_properties(cxxabi_shared
-    PROPERTIES
-      LINK_FLAGS    "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}"
-      OUTPUT_NAME   "c++abi"
-      VERSION       "1.0"
-      SOVERSION     "1"
-    )
+                        PROPERTIES
+                          LINK_FLAGS
+                            "${LIBCXXABI_LINK_FLAGS} ${LIBCXXABI_SHARED_LINK_FLAGS}"
+                          OUTPUT_NAME
+                            "c++abi"
+                          POSITION_INDEPENDENT_CODE
+                            ON
+                          SOVERSION
+                            "1"
+                          VERSION
+                            "1.0")
   list(APPEND LIBCXXABI_TARGETS "cxxabi_shared")
 endif()
 
@@ -137,10 +142,13 @@
   add_library(cxxabi_static STATIC $<TARGET_OBJECTS:cxxabi_objects>)
   target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES})
   set_target_properties(cxxabi_static
-    PROPERTIES
-      LINK_FLAGS    "${LIBCXXABI_LINK_FLAGS}"
-      OUTPUT_NAME   "c++abi"
-  )
+                        PROPERTIES
+                          LINK_FLAGS
+                            "${LIBCXXABI_LINK_FLAGS}"
+                          OUTPUT_NAME
+                            "c++abi"
+                          POSITION_INDEPENDENT_CODE
+                            ON)
   list(APPEND LIBCXXABI_TARGETS "cxxabi_static")
 endif()