Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to FindCUDAToolkit #1329

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
43 changes: 14 additions & 29 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.12)
cmake_minimum_required(VERSION 3.23)

project(OpenSubdiv)

Expand Down Expand Up @@ -370,7 +370,8 @@ if(NOT NO_OPENCL)
endif()
endif()
if(NOT NO_CUDA)
find_package(CUDA 4.0)
enable_language(CUDA)
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 @@ -587,29 +588,19 @@ else()
endif()
endif()

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

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)
set( OSD_CUDA_NVCC_FLAGS --gpu-architecture compute_11 )
elseif (CUDA_VERSION_MAJOR LESS 8)
set( OSD_CUDA_NVCC_FLAGS --gpu-architecture compute_20 )
endif()
endif()
if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES "all")
endif()

if (DEFINED OSD_CUDA_NVCC_FLAGS)
list( APPEND CUDA_NVCC_FLAGS ${OSD_CUDA_NVCC_FLAGS})
if (UNIX)
list( APPEND CUDAFLAGS -Xcompiler -fPIC )
endif()

else()
Expand Down Expand Up @@ -798,17 +789,12 @@ 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})
endif()

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

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

if(CMAKE_COMPILER_IS_ICC)
Expand All @@ -825,10 +811,9 @@ 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})
add_library(${target} ${ARGN})
if(CUDAToolkit_FOUND)
target_link_libraries(${target} CUDA::cudart)
endif()
set_target_properties(${target} PROPERTIES FOLDER ${folder})

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For more details about OpenSubdiv, see [Pixar Graphics Technologies](http://grap

| Lib | Min Version | Note |
| ----------------------------- | ----------- | ---------- |
| [CMake](http://www.cmake.org) | 3.12 | *Required* |
| [CMake](http://www.cmake.org) | 3.23 | *Required* |

* Osd optional requirements:

Expand Down
4 changes: 2 additions & 2 deletions examples/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ if(OPENCL_FOUND)
)
endif()

if(CUDA_FOUND)
include_directories("${CUDA_INCLUDE_DIRS}")
if(CUDAToolkit_FOUND)
include_directories("${CUDAToolkit_INCLUDE_DIRS}")

list(APPEND EXAMPLES_COMMON_SOURCE_FILES
cudaDeviceContext.cpp
Expand Down
6 changes: 3 additions & 3 deletions opensubdiv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ if (NOT NO_LIB)
)
endif()

if( CUDA_FOUND )
include_directories( "${CUDA_INCLUDE_DIRS}" )
if( CUDAToolkit_FOUND )
include_directories( "${CUDAToolkit_INCLUDE_DIRS}" )
endif()


Expand Down Expand Up @@ -410,7 +410,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 @@ -331,7 +331,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