From: Erik Lindahl Date: Tue, 17 Jun 2014 15:26:33 +0000 (+0200) Subject: Fixed CMake 2.8.12+ CUDA dylib bugs and warnings on OS X X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=d9d2b0aa743becd6f40864c478e83007689f8cd5;p=alexxy%2Fgromacs.git Fixed CMake 2.8.12+ CUDA dylib bugs and warnings on OS X 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e69ee1ef72..8729bc2abd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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. diff --git a/cmake/gmxManageGPU.cmake b/cmake/gmxManageGPU.cmake index 3c41094061..b8a610b56f 100644 --- a/cmake/gmxManageGPU.cmake +++ b/cmake/gmxManageGPU.cmake @@ -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: diff --git a/cmake/gmxManageNvccConfig.cmake b/cmake/gmxManageNvccConfig.cmake index 3c1c9bc08c..3985668016 100644 --- a/cmake/gmxManageNvccConfig.cmake +++ b/cmake/gmxManageNvccConfig.cmake @@ -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) diff --git a/src/gmxlib/CMakeLists.txt b/src/gmxlib/CMakeLists.txt index debfceb691..12715e707a 100644 --- a/src/gmxlib/CMakeLists.txt +++ b/src/gmxlib/CMakeLists.txt @@ -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) diff --git a/src/gmxlib/gpu_utils/dummy.cpp b/src/gmxlib/gpu_utils/dummy.cpp index 7e9fa44d2e..42d4303e53 100644 --- a/src/gmxlib/gpu_utils/dummy.cpp +++ b/src/gmxlib/gpu_utils/dummy.cpp @@ -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; diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index e212533338..fea8282ef4 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -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}") diff --git a/src/mdlib/CMakeLists.txt b/src/mdlib/CMakeLists.txt index 650b947c28..da13fbf0a5 100644 --- a/src/mdlib/CMakeLists.txt +++ b/src/mdlib/CMakeLists.txt @@ -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) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 3f79876a1f..89a04be2e5 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -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,