OptiX is based on CUDA and the optix_host.h
and some other headers include cuda.h
by default to be able to use CUDA driver API calls with the resp. CUDA types.
That cuda.h
header ships with the CUDA Toolkit and can be found inside its include
folder of your local CUDA toolkit installation.
That the compiler is not finding it inside your project means that the CUDA include directory is not present inside the CMake include directories.
When using CMake’s native CUDA language support via project(my_project_name LANGUAGES CXX CUDA)
things happen semi-automatically for native CUDA applications.
The include directories are added to the project when linking against the CUDA runtime API.
set(CMAKE_CUDA_RUNTIME_LIBRARY Shared)
https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_RUNTIME_LIBRARY.html
Actually after some searching, when using the CMake CUDA language feature, the CUDA Toolkit include directory is stored inside the CMake variable CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES
.
I’m not using that method for my OptiX examples but generate custom build rules for my *.cu files instead and for that I need the OptiX and CUDA include directories as CMake string variables.
For that I find the CUDA toolkit via find_package(CUDAToolkit 10.0 REQUIRED)
which searches in default locations and environment variables, esp. CUDA_PATH
.
https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html#findcudatoolkit
FindCUDAToolkit.cmake
replaced the legacy FindCUDA.cmake
which is deprecated since CMake 3.10 and shouldn’t be used anymore.
https://cmake.org/cmake/help/latest/module/FindCUDA.html#findcuda
(That find_package(CUDAToolkit 10.0 REQUIRED)
looks for at least CUDA 10.0 but will take any newer one specified with the environment variable CUDA_PATH
under Windows, which on my development system points to CUDA 12.2 currently.)
include_directories(
# ... other include directories
${CUDAToolkit_INCLUDE_DIRS}
)
target_link_libraries( my_project_name
# ... other libs
CUDA::cudart
CUDA::cuda_driver
)
Examples using CMake’s native FindCUDAToolkit.cmake
script and some custom build rules translating CUDA input code to PTX or OptiX IR can be found in my OptiX examples.
These are not using anything from the OptiX SDK than the include files, means it’s a different OptiX application framework example.
https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410/4
Specifically look at all CMakeLists.txt files using the scripts inside this folder:
https://github.com/NVIDIA/OptiX_Apps/tree/master/3rdparty/CMake