The CMakeLists.txt inside the advanced examples are only building static OptiX device code. For that, they either create custom build rules with the nvcuda_compile_module.cmake macro resp. use the more modern method with the CMake “Object Library” to separate the OptiX device code from native CUDA kernel code. Both are using NVCC for the static part of the device code.
When you want to build OptiX device code input modules as *.ptx or better as *.optixir by using NVRTC, there isn’t really a need to configure something in CMake for those runtime translated files.
The OptiX SDK contains all necessary source code showing that runtime translation already. If you search for functions starting with the nvrtc prefix inside the source code, you’ll find the necessary NVRTC API calls.
What the OptiX SDK does inside the CMakeLists.txt is configuring some NVRTC compiler build flags into defines for that, but that is not strictly necessary and could be hardcoded inside the source code as well. If the device code comes from files, you would also need to know the file names inside the host code which could be configured inside CMakeLists.txt as well, but I wouldn’t translate static code with NVRTC then.
This post explains what to look for inside the SDK code: https://forums.developer.nvidia.com/t/nvrtc-include-pathes/224224/2
The drawback with translating OptiX device code into modules is, that the target system must have the CUDA Toolkit headers and the OptiX SDK headers installed, as well as all your headers you use inside the OptiX device code of your renderer.
On the other hand, NVRTC is compiling faster than NVCC (about 3x last time I measured that) because it doesn’t write files. If you use that to translate shader code dynamically from some runtime generated *.cu sources, that’s a good method. I implemented a whole shader engine that way in the past. When possible you can also cache the translated module to avoid recompiling it again on program start when the input source hasn’t changed.
This post show some (old SM version) NVRTC options and include path configurations: https://forums.developer.nvidia.com/t/optix-compile-error-in-ptxstring/70636/2
While the OptiX SDK headers can be downloaded automatically from github in the meantime, to support open-source projects better, the full CUDA Toolkit installation is required due to licensing.
Your program will also need the redistributable NVRTC compiler library and its standard library to be included in the shipping target. Look for the two DLLs named with “nvrtc” inside the CUDA/<version>/bin folder inside your CUDA Toolkit installation.