After getting the first version of a Raytracing Code up and running by starting from an SDK example, I would like to migrate to a project setup that uses OTK’s ShaderUtil instead of the built-in sutil, especially because I would like to use the Self-Intersection handling.
My idea is to add the OTK repo as submodule and use FindOptiX.cmake, embed_cuda.cmake and BuildConfig.cmake to create and link the executable. To my frustration this has not been going very smoothly. I might well lack some basic knowledge of CMake. Is this a general approach that you find to be suitable?
Do you know of a project that is set up like this so I could study the CMakeLists.txt files?
So far I set some build flags and added the subdirectory in the root CMakeLists.txt:
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
# Add OptiX Toolkit
set(OTK_BUILD_EXAMPLES OFF CACHE BOOL "Build OTK examples")
set(OTK_BUILD_TESTS OFF CACHE BOOL "Build OTK tests")
set(OTK_LIBRARIES "ShaderUtil" CACHE STRING "OTK libraries to build")
set(OTK_USE_VCPKG OFF CACHE BOOL "Use vcpkg to find dependencies")
set(OptiX_INSTALL_DIR "/home/rafael/SDK/NVIDIA-OptiX-SDK-8.0.0-linux64-x86_64")
add_subdirectory(external/otk)
project(PlanetaryRaytracer LANGUAGES CXX CUDA)
add_subdirectory(src)
And try to include the necessary .cmake files at the level of the source code:
You need to set your CMAKE_MODULE_PATH so that your cmake scripts can access the modules within OTK. You Something like this in your app’s CMakeLists.txt:
I added the correct directory to the CMAKE module path, so the files can be included. However, I still struggle to use the OptiXToolkit Library.
I also added list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/external/otk/CMake") so that CMake finds the configured file OptiXToolkitConfig.cmake.
But when I execute find_package(OptixToolkit required) I still get errors that some include commands in OptiXToolkitConfig.cmake fail. E.g. include("${_prefix}/cmake/OptiXToolkit/CudaTargets.cmake").
I don’t see any of these files generated in my build folder, so I still feel that I did something fundamentally wrong.
Here is the full file:
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
# Add OptiX Toolkit
set(OTK_BUILD_EXAMPLES OFF CACHE BOOL "Build OTK examples")
set(OTK_BUILD_TESTS OFF CACHE BOOL "Build OTK tests")
set(OTK_LIBRARIES "ShaderUtil" CACHE STRING "OTK libraries to build")
set(OTK_USE_VCPKG OFF CACHE BOOL "Use vcpkg to find dependencies")
set(OptiX_INSTALL_DIR "/home/rafael/SDK/NVIDIA-OptiX-SDK-8.0.0-linux64-x86_64")
add_subdirectory(external/otk)
project(PlanetaryRaytracer LANGUAGES CXX CUDA)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/otk/CMake")
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_BINARY_DIR}/external/otk/CMake")
message(STATUS "Find OptiX and CUDA")
find_package( OptiX REQUIRED )
if(NOT TARGET CUDA::cuda_driver)
find_package( CUDAToolkit 11.0 REQUIRED )
endif()
message(STATUS "OptiX and CUDA found")
find_package( OptiXToolkit REQUIRED )
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 14)
add_subdirectory(src)
The relative pack to the cloned OptiXToolkit is ./external/otk
You shouldnt need to find optixtoolkit. find_package is usually used to find external dependencies. OTK is not an external dependency here (it is part of your internal build so you can directly reference its libraries and you know the paths to its headers). OTK is also not set up for this in any case – there is no FindOptiXToolkit.cmake module or config file
otkExternalApp.zip (6.4 KB)
Attached is a minimal example. I took the optix-toolkit/examples/Simple/OtkHello/ example, moved it outside of otk, stripped out any dependencies on the otk example infrastructure, and built it against an external otk clone.
It uses embed_cudato load otk’s shader_utiland it uses cmake c++ linking to link against otk’s Memory library.
To test it:
unzip otkExternalApp.zip
cd otkExternalApp/external
git clone git@github.com:NVIDIA/optix-toolkit.git
git submodule update --init --recursive
cd ..
mkdir build
cd build
ccmake .. # set your optix install dir
make
./bin/otkHello
Thank you very much for the example! I got everything working now. Some of the issues i had in my version were that i tried to link OptiXToolkit::Util which i didn’t need and is only build with the examples and a missing C language specifier.