diff --git a/CMake/VTKmDeviceAdapters.cmake b/CMake/VTKmDeviceAdapters.cmake index 2539cd171..2d6e43cc2 100644 --- a/CMake/VTKmDeviceAdapters.cmake +++ b/CMake/VTKmDeviceAdapters.cmake @@ -134,6 +134,17 @@ if(VTKm_ENABLE_CUDA AND NOT TARGET vtkm::cuda) add_library(vtkm::cuda UNKNOWN IMPORTED GLOBAL) endif() + # Workaround issue with CUDA 8.X where virtual don't work when building + # VTK-m as shared. We don't want to force BUILD_SHARED_LIBS to a specific + # value as that could impact other projects that embed VTK-m. Instead what + # we do is make sure that libraries built by vtkm_library() are static + # if they use cuda + if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 9.0) + set_target_properties(vtkm::cuda PROPERTIES REQUIRES_STATIC_BUILDS TRUE) + else() + set_target_properties(vtkm::cuda PROPERTIES REQUIRES_STATIC_BUILDS FALSE) + endif() + set_target_properties(vtkm::cuda PROPERTIES INTERFACE_COMPILE_OPTIONS $<$:--expt-relaxed-constexpr> ) diff --git a/CMake/VTKmWrappers.cmake b/CMake/VTKmWrappers.cmake index fedbaec39..7b6713da8 100644 --- a/CMake/VTKmWrappers.cmake +++ b/CMake/VTKmWrappers.cmake @@ -282,16 +282,31 @@ function(vtkm_library) endif() set(lib_name ${VTKm_LIB_NAME}) + if(VTKm_LIB_STATIC) + set(VTKm_LIB_type STATIC) + else() + if(VTKm_LIB_SHARED) + set(VTKm_LIB_type SHARED) + endif() + #if cuda requires static libaries force + #them no matter what + if(TARGET vtkm::cuda) + get_target_property(force_static vtkm::cuda REQUIRES_STATIC_BUILDS) + if(force_static) + set(VTKm_LIB_type STATIC) + message("Forcing ${lib_name} to be built statically as we are using CUDA 8.X, which doesn't support virtuals sufficiently in dynamic libraries.") + endif() + endif() + + endif() + + if(TARGET vtkm::cuda) vtkm_compile_as_cuda(cu_srcs ${VTKm_LIB_WRAP_FOR_CUDA}) set(VTKm_LIB_WRAP_FOR_CUDA ${cu_srcs}) endif() - if(VTKm_LIB_STATIC) - set(VTKm_LIB_type STATIC) - elseif(VTKm_LIB_SHARED) - set(VTKm_LIB_type SHARED) - endif() + add_library(${lib_name} ${VTKm_LIB_type}