changeset 150:3cb226f48495

- make cmake based builds check if compiler has -fPIC flag, in order to silence warnings if not (thanks Franklin Mathieu)
author cslag
date Sat, 17 Sep 2016 14:15:02 +0200
parents c12120a1fbc0
children dac66f0107ea
files CMakeLists.txt
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/CMakeLists.txt	Sat Sep 17 14:10:53 2016 +0200
+++ b/CMakeLists.txt	Sat Sep 17 14:15:02 2016 +0200
@@ -41,6 +41,9 @@
   enable_language(CXX)
 endif()
 
+include(CheckCCompilerFlag)
+check_c_compiler_flag("-fPIC -Werror" COMPILER_HAS_FPIC)
+
 if(MSVC)
   enable_language(ASM_MASM)
   #if(CMAKE_SIZEOF_VOID_P MATCHES 8)
@@ -52,10 +55,12 @@
   #set(CMAKE_ASM_MASM_SOURCE_FILE_EXTENSIONS asm)
   #set(CMAKE_ASM_MASM_COMPILE_OBJECT "<CMAKE_ASM_MASM_COMPILER> <FLAGS> /c /Fo <OBJECT> <SOURCE>")
 elseif(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
-  # when used in shared libraries, -fPIC is required by several architectures
-  # and platforms (observed on AMD64, Solaris/Sparc).
-  # we enable it per default here.
-  add_definitions("-fPIC")
+  if(COMPILER_HAS_FPIC)
+    # when used in shared libraries, -fPIC is required by several architectures
+    # and platforms (observed on AMD64, Solaris/Sparc).
+    # we enable it per default here.
+    add_definitions("-fPIC")
+  endif()
   # enable gcc as front-end to assembler for .S files
   set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}")
   set(CMAKE_ASM_COMPILER_ARG1 "${CPPFLAGS} -c")
@@ -67,7 +72,9 @@
   enable_language(ASM)
 else()
   if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
-  add_definitions("-fPIC")
+  if(COMPILER_HAS_FPIC)
+    add_definitions("-fPIC")
+  endif()
   # enable gcc as front-end to assembler for .S files
   set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}")
   set(CMAKE_ASM_COMPILER_ARG1 "${CPPFLAGS} -c")