Converting VS Property-Sheet into CMake settings

I described two different ways to build a CMakeLists.txt with OptiX device code.
You did not use one or the other but merged the two different methods.

You set your project to use the CMake LANGUAGE CUDA feature with project(${PROJECT_NAME} LANGUAGES CXX CUDA) and put a *.cu file into that project (the and you generated custom build rules OptiX device code *.cu files (also the with my CMake macro NVCUDA_COMPILE_MODULE.

These two things are mutually exclusive!

The double appearance of in OPTIX_SOURCES and OPTIX_SHADER is intentional, as the file needed to be included in add_executable anyway and splitting the files into two variables didn’t work with the source_group function. As far as I can tell, this shouldn’t be the cause why it’s not working, though (at least didn’t help anything with my issue, as far as I can tell).

Don’t do that! You effectively told the project that it should compile *.cu files inside the application to object code again with the LANGUAGE CUDA feature while also compiling it with a custom build rule. You cannot have both if that is OptiX device code.

You also didn’t set any of the native CUDA compilation rules required for the LANGUAGE CUDA feature.

It boils down to this question:
Do you have any native CUDA kernels you want to use inside that application with the CUDA host API?
(Means kernel launches with the chevron operator <<<>>> )

  • If not, do NOT set LANGUAGE CUDA.
    Compare that to my examples’ CMakeLists.txt like this:
    Note the project( intro_runtime ) which is not using LANGUAGE at all and compiles all OptiX device code using the custom build rules generated by my NVCUDA_COMPILE_MODULE.

  • If yes, do NOT use the NVCUDA_COMPILE_MODULE macro to generate custom build rules for the OptiX compilation.
    Instead you must use the CMake Object Library feature to isolate the OptiX device code from the CUDA native code. (That also means that cannot be the same file like your
    For that copy the CMakeLists.txt code from this post:
    and add the necessary find_package() instructions for OptiX and your other dependencies.

Do not touch anything inside the CUDA Visual Studio Integration sheets of your *.vcxproj.

1 Like