Merge pull request #2366 from blattms/makes-mixing-incompatible-gcc-nvcc-fail

Make mixing incompatible host compiler/device compiler versions fail.
This commit is contained in:
Arne Morten Kvarving 2020-02-26 09:00:34 +01:00 committed by GitHub
commit 42b290133a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,12 +18,37 @@ project(opm-simulators C CXX)
cmake_minimum_required (VERSION 2.8)
find_package(CUDA)
# Make sure we are using the same compiler underneath
# NVCC as for the rest. In the case that NVCC does not support
# that compiler it will error out. Unfortunately this will only
# work CMake >= 3.8. We found no way to make FindCUDA.cmake error
# out. It seems to ignore CMAKE_NVCC_FLAGS and CMAKE. Additionally
# our way of specifying cuda source files never worked for CMake
# version < 3.8. Hence we deactivate cuda for these versions.
if(NOT CMAKE_DISABLE_FIND_PACKAGE_CUDA AND
CMAKE_VERSION VERSION_GREATER_EQUAL 3.8)
if(NOT DEFINED ENV{CUDAHOSTCXX} AND
(NOT CMAKE_CUDA_FLAGS OR NOT CMAKE_CUDA_FLAGS MATCHES ".*-ccbin .*"))
set(CMAKE_CUDA_FLAGS "-ccbin ${CMAKE_CXX_COMPILER} ${CMAKE_CUDA_FLAGS}")
endif()
include(CheckLanguage)
# Unfortunately check_language(CUDA) will only check whether there is
# a nvcc compiler. It will not check whether compilation with the above
# option works. Since the OPTIONAL flag of enable_language is currently
# ignored CMake will error out below if the options do not work.
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA OPTIONAL)
endif()
# While the documentation says that it is deprecated, FindCUDA seems the
# only easy way to determine the cublas and cusparse libraries.
# Hence we call it unconditionally
find_package(CUDA)
endif()
if(CUDA_FOUND)
include_directories(${CUDA_INCLUDE_DIRS})
enable_language(CUDA)
set(HAVE_CUDA 1)
include_directories(${CUDA_INCLUDE_DIRS})
endif()
option(SIBLING_SEARCH "Search for other modules in sibling directories?" ON)
@ -320,7 +345,7 @@ endif()
# must link libraries after target 'flow' has been defined
if(CUDA_FOUND)
target_link_libraries( opmsimulators ${CUDA_cublas_LIBRARY} )
target_link_libraries( opmsimulators ${CUDA_cusparse_LIBRARY} )
target_link_libraries( opmsimulators PUBLIC ${CUDA_cusparse_LIBRARY} )
target_link_libraries( opmsimulators PUBLIC ${CUDA_cublas_LIBRARY} )
endif()