Verify that FFTW can be used with shared libraries
authorRoland Schulz <roland@utk.edu>
Sat, 10 Nov 2012 12:00:52 +0000 (07:00 -0500)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Thu, 15 Nov 2012 17:29:58 +0000 (18:29 +0100)
Fixes #740

Change-Id: If55f9bde72b1b2ce783c2a86a9bf0170a159c266

cmake/FindFFTW.cmake

index d233df14ace03568a290b11b13db5aa345f65565..4571ed507b73e2a938961c9285fe1449e3a206cb 100644 (file)
@@ -74,6 +74,14 @@ if (${FFTW}_FOUND)
       break()
     endif(${FFTW}_HAVE_${SIMD_FCT})
   endforeach()
+  #Verify FFTW is compiled with fPIC (necessary for shared libraries)
+  if (CMAKE_OBJDUMP AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND BUILD_SHARED_LIBS)
+      execute_process(COMMAND ${CMAKE_OBJDUMP} --reloc ${${FFTW}_LIBRARY} OUTPUT_VARIABLE ${FFTW}_OBJDUMP)
+      if (${${FFTW}_OBJDUMP} MATCHES "R_X86_64" #Should always be true for static libraries. Checks that objdump works properly and that the library isn't dynamic
+              AND NOT ${${FFTW}_OBJDUMP} MATCHES "R_X86_64_PLT32")
+          message(FATAL_ERROR "The FFTW library ${${FFTW}_LIBRARY} cannot be used with shared libraries. Provide a different FFTW library by setting ${FFTW}_LIBRARY. If you don't have a different one, recompile FFTW with \"--enable-shared\" or \"--with-pic\". Or disable shared libraries for Gromacs by setting BUILD_SHARED_LIBS to \"no\". Note: Disabling shared libraries requires up to 10x as much disk space.")
+      endif ()
+  endif ()
   set(CMAKE_REQUIRED_LIBRARIES)
 endif (${FFTW}_FOUND)
 set(${FFTW}_HAVE_SIMD FALSE CACHE BOOL "If ${${FFTW}_PKG} was built with SIMD support")