From f67d2dc9c717099025f5d986e3ab3b6a622afeea Mon Sep 17 00:00:00 2001 From: Jiangjin Wang Date: Tue, 12 Mar 2024 20:11:04 -0700 Subject: [PATCH] Migrate to FindCUDAToolkit - FindCUDA has been deprecated since CMake 3.10, and disabled by default since CMake 3.27. [^1] - Raise CMAKE_MINIMUM_REQUIRED to 3.23 for CMAKE_CUDA_ARCHITECTURES support. [^2] [^1]: https://cmake.org/cmake/help/latest/policy/CMP0146.html [^2]: https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html --- CMakeLists.txt | 43 +++++++++++----------------------- README.md | 2 +- examples/common/CMakeLists.txt | 4 ++-- opensubdiv/CMakeLists.txt | 6 ++--- opensubdiv/osd/CMakeLists.txt | 2 +- 5 files changed, 21 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8620cf3df..ed26b8a8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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() @@ -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) @@ -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}) diff --git a/README.md b/README.md index 8d9bf06bf..c91e3e06f 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/examples/common/CMakeLists.txt b/examples/common/CMakeLists.txt index cf8b9f468..5e50a180d 100644 --- a/examples/common/CMakeLists.txt +++ b/examples/common/CMakeLists.txt @@ -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 diff --git a/opensubdiv/CMakeLists.txt b/opensubdiv/CMakeLists.txt index 2ab3f34a6..703edd0b4 100644 --- a/opensubdiv/CMakeLists.txt +++ b/opensubdiv/CMakeLists.txt @@ -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() @@ -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) diff --git a/opensubdiv/osd/CMakeLists.txt b/opensubdiv/osd/CMakeLists.txt index 654697a74..871a806f3 100755 --- a/opensubdiv/osd/CMakeLists.txt +++ b/opensubdiv/osd/CMakeLists.txt @@ -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