Yes, I wrote these here for my OptiX 7 examples: https://github.com/NVIDIA/OptiX_Apps/tree/master/3rdparty/CMake
They look for the default OptiX installation folders, but if you install SDKs to a different location like me, you can use an environment variable OPTIX7_PATH
, OPTIX71_PATH
, and OPTIX72_PATH
to let the scripts look there first.
In the most recent commits there, I moved the find_package(OptiX<version>)
to the top-level CMakeList.txt which generates the solution with all projects. That way it looks for all shipping OptiX 7 versions and individual examples use the newest found OptiX 7 version by selecting just the include directory.
https://github.com/NVIDIA/OptiX_Apps/blob/master/CMakeLists.txt#L78
Before that, the individual examples’ CMakeLists.txt used find_package(OptiX<version>)
themselves to decide which OptiX 7 version to use. I left that in as comment for example here:
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/intro_runtime/CMakeLists.txt#L35
Below that line you see how it’s using the individual OptiX<version>_FOUND
CMake variables which have been set by the resp. FindOptiX<version>.cmake
scripts to select the newest found version.
So currently you could pick an OptiX 7 version explicitly by just changing that selection to your desired include directory version or by removing the find_package( ) calls from the top-level CMakeLists.txt and uncomment the previous method. (The sub-directory of the intro_motion_blur example is not added when OptiX72_FOUND is not set, so that check would need to be removed from the CMakeList.txt in the apps
folder.)
When having projects with older OptiX versions, you would need to use its own FindOptiX.cmake variant, because the APIs were not header-only and need to find and set the link libraries as well, but it’s similarly simple.
The OptiX 5.1.0 based ancestors of these introduction samples contain a FindOptiX.cmake which is a little more involved because of the different library names among OptiX 5 and 6 versions:
https://github.com/nvpro-samples/optix_advanced_samples/blob/master/src/CMake/FindOptiX.cmake
I normally used a smaller version of that for my own projects. Attached is one which finds OptiX 6.5.0 if the environment variable OPTIX_PATH
is not set. Or change the hardcoded default 6.5.0
in there.
FindOptiX.txt (3.7 KB)
(Rename to *.cmake. The forum doesn’t allow that extension in attachments.)
I never used the optixu libraries of the SDKs, and the script doesn’t add that to the OPTIX_LIBRARIES, but all code required for that is left inside the *.cmake as comment if you need that.
The include_directories()
section of the CMakeLists.txt of the project would then need the ${OPTIX_INCLUDE_DIR}
and the target_link_libraries()
would need the ${OPTIX_LIBRARIES} among all other dependencies.