Fixed CMake 2.8.12+ CUDA dylib bugs and warnings on OS X
authorErik Lindahl <erik@kth.se>
Tue, 17 Jun 2014 15:26:33 +0000 (17:26 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 18 Jun 2014 12:17:03 +0000 (14:17 +0200)
This patch fixes up a number of minor compilation issues
with CUDA on OS X. The __STRICT_ANSI__ define has been
added to make CUDA work with gcc version 4.8 and 4.9,
a dummy variable has been added to the dummy c++ gpu utils
file to avoid warnings about empty objects, and we now
properly handle both RPATH (newer CMake) and INSTALL_NAME_DIR
(older CMake) without warnings. CMake-2.8.12 introduced
a bug that caused Gromacs executables to be malformed since
the rpath to the CUDA libraries was added twice. This is
caused by fairly deep internal changes in CMake, but it has
been worked around by removing the rpath (which FindCUDA.cmake
only adds on OS X) manually for CMake>2.8.11.

Fixes #1471.

Change-Id: I8b01204dc07678bc305821162f20db65e0e7b88d

CMakeLists.txt
cmake/gmxManageGPU.cmake
cmake/gmxManageNvccConfig.cmake
src/gmxlib/CMakeLists.txt
src/gmxlib/gpu_utils/dummy.cpp
src/kernel/CMakeLists.txt
src/mdlib/CMakeLists.txt
src/tools/CMakeLists.txt

index e69ee1ef7252419f847b6de7b8eb5724caaca814..8729bc2abdef7cbd0c4aaa42267cf4ee9f664f3d 100644 (file)
@@ -1195,14 +1195,18 @@ else(GMX_DEFAULT_SUFFIX)
 endif(GMX_DEFAULT_SUFFIX)
 set(SUFFIX_QUIETLY TRUE CACHE INTERNAL "")
 
-##################################################################
-# Shared library settings - Darwin uses INSTALL_NAME_DIR instead!
-##################################################################
-if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
+################################################################
+# Shared library settings
+################################################################
+if((NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") OR ((CMAKE_SYSTEM_VERSION VERSION_GREATER 8.0) AND (CMAKE_VERSION VERSION_GREATER 2.8.11)))
     set(CMAKE_SKIP_BUILD_RPATH  FALSE)
     set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
     set(CMAKE_INSTALL_RPATH "\\\$ORIGIN/../${GMXLIB}")
     set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+    set(CMAKE_MACOSX_RPATH 1)
+else()
+    # We are on Darwin/OSX, and cmake cannot handle proper RPATHs
+    set(CMAKE_INSTALL_NAME_DIR "${LIB_INSTALL_DIR}")
 endif()
 
 #COPYING file: Only necessary for binary distributions.
index 3c4109406175b506f32824e4a504a09a46c9ae5a..b8a610b56f7b1a20f94d9c59c64dec8f97014b0b 100644 (file)
@@ -70,6 +70,22 @@ if(GMX_GPU OR GMX_GPU_AUTO)
     else()
         find_package(CUDA 3.2 ${FIND_CUDA_QUIETLY})
     endif()
+    # Cmake 2.8.12 (and CMake 3.0) introduced a new bug where the cuda
+    # library dir is added twice as an rpath on APPLE, which in turn causes
+    # the install_name_tool to wreck the binaries when it tries to remove this
+    # path. Since this is set inside the cuda module, we remove the extra rpath
+    # added in the library string - an rpath is not a library anyway, and at
+    # least for Gromacs this works on all CMake versions. This should be
+    # reasonably future-proof, since newer versions of CMake appear to handle
+    # the rpath automatically based on the provided library path, meaning
+    # the explicit rpath specification is no longer needed.
+    if(APPLE AND (CMAKE_VERSION VERSION_GREATER 2.8.11))
+        foreach(elem ${CUDA_LIBRARIES})
+            if(elem MATCHES "-Wl,.*")
+                list(REMOVE_ITEM CUDA_LIBRARIES ${elem})
+            endif()
+        endforeach(elem)
+    endif()
 endif()
 
 # Depending on the current vale of GMX_GPU and GMX_GPU_AUTO:
index 3c1c9bc08cf9de0c11b70888aa747678a15abfe0..398566801660b062fe2888ee65d5d670e536bdab 100644 (file)
@@ -125,6 +125,12 @@ if (NOT DEFINED CUDA_NVCC_FLAGS_SET)
         mark_as_advanced(CUDA_HOST_COMPILER CUDA_HOST_COMPILER_OPTIONS)
     endif()
 
+    if(APPLE AND CMAKE_C_COMPILER_ID MATCHES "GNU")
+        # Some versions of gcc-4.8 and gcc-4.9 produce errors (in particular on OS X)
+        # if we do not use -D__STRICT_ANSI__. It is harmless, so we might as well add it for all versions.
+        set(CUDA_HOST_COMPILER_OPTIONS "${CUDA_HOST_COMPILER_OPTIONS}-D__STRICT_ANSI__;")
+    endif()
+
     # on Linux we need to add -fPIC when building shared gmx libs
     # Note: will add -fPIC for any compiler that supports it as it shouldn't hurt
     if(BUILD_SHARED_LIBS)
index debfceb691c71638309190dbc16ce60a1b5acb87..12715e707a2ec061787b29269d514438a539390e 100644 (file)
@@ -117,7 +117,7 @@ target_link_libraries(gmx ${FFT_LIBRARIES} ${LINEAR_ALGEBRA_LIBRARIES} ${GMX_GPU
 if(USE_VERSION_H)
        add_dependencies(gmx gmx_version) 
 endif()
-set_target_properties(gmx PROPERTIES OUTPUT_NAME "gmx${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION} INSTALL_NAME_DIR "${LIB_INSTALL_DIR}"
+set_target_properties(gmx PROPERTIES OUTPUT_NAME "gmx${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION}
     COMPILE_FLAGS "${OpenMP_C_FLAGS}" COMPILE_DEFINITIONS "TMPI_EXPORTS")
 
 install(TARGETS gmx DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries)
index 7e9fa44d2ef86d3b5d0484d332837fec271f3a56..42d4303e5374eae37a8a3934bf8c3db99221a22a 100644 (file)
@@ -1,3 +1,6 @@
 /* This source file has the sole purpose to force C++ linking of the gpu_utils
  * static archive, otherwise the exception handling code generated inside
  * memtestG80 will cause undefined symbols at linking. */
+
+/* Avoid warnings about empty object files */
+int gpu_utils_dummy;
index e2125333387440d266eb0e6e77f23e8adb635511..fea8282ef4fade62c8a764455b21dae78f277236 100644 (file)
@@ -76,7 +76,7 @@ set(MDRUN_SOURCES
 
 add_library(gmxpreprocess ${GMXPREPROCESS_SOURCES})
 target_link_libraries(gmxpreprocess md)
-set_target_properties(gmxpreprocess PROPERTIES OUTPUT_NAME "gmxpreprocess${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION} INSTALL_NAME_DIR "${LIB_INSTALL_DIR}"
+set_target_properties(gmxpreprocess PROPERTIES OUTPUT_NAME "gmxpreprocess${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION}
     COMPILE_FLAGS "${OpenMP_C_FLAGS}")
 
 
index 650b947c28c9845c286f76c64c38d3f4b3104b1b..da13fbf0a57ee27d37626beb175879d3d00aae24 100644 (file)
@@ -67,7 +67,7 @@ if(GMX_BUILD_OWN_FFTW)
     # disabling GMX_BUILD_OWN_FFTW changes dependencies correctly.
     add_dependencies(md gmxfftw)
 endif()
-set_target_properties(md PROPERTIES OUTPUT_NAME "${MD_PREFIX}md${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION} INSTALL_NAME_DIR "${LIB_INSTALL_DIR}"
+set_target_properties(md PROPERTIES OUTPUT_NAME "${MD_PREFIX}md${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION}
     COMPILE_FLAGS "${OpenMP_C_FLAGS}")
 
 install(TARGETS md DESTINATION ${LIB_INSTALL_DIR} COMPONENT libraries)
index 3f79876a1fc15e3ed7bbe02fc3d576f6d0bc75fb..89a04be2e57b7ea113fc89ddfb5e3150e29b7b11 100644 (file)
@@ -71,7 +71,7 @@ add_library(gmxana
 
 
 target_link_libraries(gmxana md ${GSL_LIBRARIES})
-set_target_properties(gmxana PROPERTIES OUTPUT_NAME "gmxana${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION} INSTALL_NAME_DIR "${LIB_INSTALL_DIR}"
+set_target_properties(gmxana PROPERTIES OUTPUT_NAME "gmxana${GMX_LIBS_SUFFIX}" SOVERSION ${SOVERSION}
     COMPILE_FLAGS "${OpenMP_C_FLAGS}")
 
 # List of programs with single corresponding .c source file,