Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# language governing permissions and limitations under the Apache License.
#

cmake_minimum_required(VERSION 3.14)
cmake_minimum_required(VERSION 3.17)

project(OpenSubdiv)

Expand Down Expand Up @@ -383,7 +383,7 @@ if(NOT NO_OPENCL)
endif()
endif()
if(NOT NO_CUDA)
find_package(CUDA 4.0)
find_package(CUDAToolkit 4.0)
endif()
if(NOT NO_GLFW AND NOT NO_OPENGL AND NOT ANDROID AND NOT IOS)
find_package(GLFW 3.0.0)
Expand Down Expand Up @@ -600,37 +600,43 @@ else()
endif()
endif()

if(CUDA_FOUND)
if(CUDAToolkit_FOUND)
add_definitions(
-DOPENSUBDIV_HAS_CUDA
-DCUDA_ENABLE_DEPRECATED=0
)
set(OSD_GPU TRUE)

# Enable CUDA language support
enable_language(CUDA)

if (UNIX)
list( APPEND CUDA_NVCC_FLAGS -Xcompiler -fPIC )
# Use OSD_CUDA_NVCC_FLAGS to specify --gpu-architecture or other CUDA
# compilation options. The overrides here are only for compatibility
# with older OpenSubdiv releases and obsolete CUDA versions.
if (NOT DEFINED OSD_CUDA_NVCC_FLAGS)
if (CUDA_VERSION_MAJOR LESS 6)
if (CUDAToolkit_VERSION_MAJOR LESS 6)
set( OSD_CUDA_NVCC_FLAGS --gpu-architecture compute_11 )
elseif (CUDA_VERSION_MAJOR LESS 8)
elseif (CUDAToolkit_VERSION_MAJOR LESS 8)
set( OSD_CUDA_NVCC_FLAGS --gpu-architecture compute_20 )
endif()
endif()
endif()

if (DEFINED OSD_CUDA_NVCC_FLAGS)
list( APPEND CUDA_NVCC_FLAGS ${OSD_CUDA_NVCC_FLAGS})
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${OSD_CUDA_NVCC_FLAGS}")
endif()

if (UNIX)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -fPIC")
endif()

else()
if (NOT NO_CUDA)
message(WARNING
"CUDA was not found : support for CUDA parallel compute kernels "
"will be disabled in Osd. If you have the CUDA SDK installed, please "
"refer to the FindCUDA.cmake shared module in your cmake installation.")
"make sure it's in your PATH or set CMAKE_CUDA_COMPILER.")
endif()
endif()

Expand Down Expand Up @@ -811,16 +817,18 @@ endmacro()
# Macro for adding a cuda executable if cuda is found and a regular
# executable otherwise.
macro(osd_add_possibly_cuda_executable target folder)
if(CUDA_FOUND)
cuda_add_executable(${target} ${ARGN})
else()
add_executable(${target} ${ARGN})

if(CUDAToolkit_FOUND)
# Link against CUDA runtime library (shared by default)
target_link_libraries(${target} CUDA::cudart)
set_property(TARGET ${target} PROPERTY CUDA_RUNTIME_LIBRARY Shared)
endif()

set_target_properties(${target} PROPERTIES FOLDER ${folder})

# Workaround link dependencies for cuda examples on platforms with GLX
if(CUDA_FOUND AND OpenGL_GLX_FOUND)
if(CUDAToolkit_FOUND AND OpenGL_GLX_FOUND)
target_link_libraries(${target} OpenGL::GLX)
endif()

Expand All @@ -838,11 +846,14 @@ endmacro()
# Macro for adding a cuda library if cuda is found and a regular
# library otherwise.
macro(osd_add_possibly_cuda_library target folder)
if(CUDA_FOUND)
cuda_add_library(${target} ${ARGN})
else()
add_library(${target} ${ARGN})

if(CUDAToolkit_FOUND)
# Link against CUDA runtime library (shared by default)
target_link_libraries(${target} CUDA::cudart)
set_property(TARGET ${target} PROPERTY CUDA_RUNTIME_LIBRARY Shared)
endif()

set_target_properties(${target} PROPERTIES FOLDER ${folder})

if(APPLE)
Expand Down
10 changes: 7 additions & 3 deletions opensubdiv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ if (NOT NO_LIB)
)
endif()

if( CUDA_FOUND )
include_directories( "${CUDA_INCLUDE_DIRS}" )
if( CUDAToolkit_FOUND )
# CUDA include directories are still needed for .cpp files that include CUDA headers
get_target_property(CUDA_INCLUDE_DIRS CUDA::cudart INTERFACE_INCLUDE_DIRECTORIES)
if(CUDA_INCLUDE_DIRS)
include_directories( "${CUDA_INCLUDE_DIRS}" )
endif()
endif()


Expand Down Expand Up @@ -420,7 +424,7 @@ if (NOT NO_LIB)
if(CLEW_FOUND)
target_compile_definitions(${osd_target} INTERFACE OPENSUBDIV_HAS_CLEW)
endif()
if(CUDA_FOUND)
if(CUDAToolkit_FOUND)
target_compile_definitions(${osd_target} INTERFACE OPENSUBDIV_HAS_CUDA)
endif()
if(DXSDK_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion opensubdiv/osd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ set(CUDA_PUBLIC_HEADERS
cudaVertexBuffer.h
)

if( CUDA_FOUND )
if( CUDAToolkit_FOUND )
list(APPEND GPU_SOURCE_FILES
cudaEvaluator.cpp
cudaPatchTable.cpp
Expand Down
Loading