I have downloaded and installed OptiX 8.0 and Cuda 12.0 and want to use them in my CMake based project. My understanding is that for OptiX I need only add the include directory, Cuda can be used with the find_package command:
In one of my files, I included “optix.h”.
When I go and compile this (Win 11 / VS 2022), I get an error
C:\ProgramData\NVIDIA Corporation\OptiX SDK 8.0.0\include\optix_host.h(35,10): fatal error C1083: Cannot open include file: ‘cuda.h’: No such file or directory
I cannot find any information about how to actually use OptiX 8.0 in my own project and the SDK uses find_package(OptiX), which doesn’t work at all.
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.
(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
)