-
Notifications
You must be signed in to change notification settings - Fork 398
build: Switch from FindCUDA to FindCUDAToolkit (#2072) #2073
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |||||||||||||||||||||||||||
| # SPDX-License-Identifier: BSD-3-Clause | ||||||||||||||||||||||||||||
| # https://github.com/AcademySoftwareFoundation/OpenShadingLanguage | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| cmake_minimum_required(VERSION 3.15) | ||||||||||||||||||||||||||||
| cmake_minimum_required(VERSION 3.19) # Same as top-level CMakeLists.txt | ||||||||||||||||||||||||||||
| project(examplecuda LANGUAGES CXX) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (NOT CMAKE_BUILD_TYPE) | ||||||||||||||||||||||||||||
|
|
@@ -19,12 +19,16 @@ include(check_is_enabled) | |||||||||||||||||||||||||||
| include(checked_find_package) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| find_package(OSL REQUIRED) | ||||||||||||||||||||||||||||
| find_package(CUDA REQUIRED) | ||||||||||||||||||||||||||||
| find_package(CUDAToolkit REQUIRED) | ||||||||||||||||||||||||||||
| checked_find_package(LLVM 7.0 REQUIRED) | ||||||||||||||||||||||||||||
| checked_find_package(Imath 3.1 REQUIRED) | ||||||||||||||||||||||||||||
| checked_find_package(OpenImageIO 2.4 REQUIRED) | ||||||||||||||||||||||||||||
| checked_find_package(OptiX REQUIRED) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| set(CUDA_TOOLKIT_ROOT_DIR ${CUDAToolkit_ROOT_DIR}) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| set(CUDA_TOOLKIT_ROOT_DIR ${CUDAToolkit_ROOT_DIR}) | |
| # Derive a usable CUDA toolkit root directory from CUDAToolkit variables. | |
| set(CUDA_TOOLKIT_ROOT_DIR "") | |
| if (CUDAToolkit_LIBRARY_ROOT) | |
| # Use the library root directly when available. | |
| set(CUDA_TOOLKIT_ROOT_DIR "${CUDAToolkit_LIBRARY_ROOT}") | |
| elseif (CUDAToolkit_BIN_DIR) | |
| # Fall back to the parent of the bin directory. | |
| get_filename_component(CUDA_TOOLKIT_ROOT_DIR "${CUDAToolkit_BIN_DIR}" DIRECTORY) | |
| elseif (CUDAToolkit_ROOT) | |
| # As a last resort, use the generic CUDAToolkit root, if defined. | |
| set(CUDA_TOOLKIT_ROOT_DIR "${CUDAToolkit_ROOT}") | |
| endif () |
Copilot
AI
Feb 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuda_compile_ptx() invokes ${CUDA_NVCC_EXECUTABLE}, but CUDAToolkit_NVCC_EXECUTABLE may be unset on systems that have CUDA runtime libraries/headers but no nvcc installed. Add a configure-time fallback/check (e.g., find_program(CUDA_NVCC_EXECUTABLE NAMES nvcc ...) and message(FATAL_ERROR ...) if still not found) so this fails during configuration rather than at build time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CUDA_TOOLKIT_ROOT_DIRis later treated as a full toolkit root (used for--cuda-path=...,.../binnvcc lookup, and.../lib64paths). Setting it fromCUDAToolkit_LIBRARY_ROOTcan be inconsistent with those uses on toolkits where the library root is not the same as the toolkit root. Consider preferringCUDAToolkit_TARGET_DIR(or deriving fromCUDAToolkit_BIN_DIR) forCUDA_TOOLKIT_ROOT_DIR, and usingCUDAToolkit_LIBRARY_ROOTonly for library searches.