How to include OptiX 8.0 in CMake project?

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.

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.

FindCUDAToolkit.cmake replaced the legacy FindCUDA.cmake which is deprecated since CMake 3.10 and shouldn’t be used anymore.

(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.)

  # ... other include directories

target_link_libraries( my_project_name
  # ... other libs

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.
Specifically look at all CMakeLists.txt files using the scripts inside this folder: