Converting VS Property-Sheet into CMake settings

Hello,

I’ve got two Visual Studio Property Sheets that add OptiX support to an existing renderer. I’m trying to build a project in CMake 3.29.0 for it and while the first property sheet that is responsible for adding the OptiX include paths to the project worked without any issues, the second property sheet turned out to cause trouble.

This is the content of the property sheet:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <CudaCompile>
      <GenerateRelocatableDeviceCode>true</GenerateRelocatableDeviceCode>
    </CudaCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup>
    <CudaCompile>
      <TargetMachinePlatform>64</TargetMachinePlatform>
      <GPUDebugInfo>false</GPUDebugInfo>
      <HostDebugInfo>false</HostDebugInfo>
      <FastMath>true</FastMath>
      <NvccCompilation>optix-ir</NvccCompilation>
      <Keep>true</Keep>
      <CompileOut>$(ProjectDir)../gpu-code/%(Filename)%(Extension).optixir</CompileOut>
    </CudaCompile>
    <CudaLink>
      <PerformDeviceLink>false</PerformDeviceLink>
    </CudaLink>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

And this is what I added to the cmakelists.txt to add the details:

set(CUDA_SEPARABLE_COMPILATION ON)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --machine 64 --use_fast_math --keep -optix-ir")
set(CMAKE_CUDA_COMPILER_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/gpu-code/")

However, when configuring the cmake project it just fails with this error:

E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\build\CMakeFiles\CMakeScratch\TryCompile-j9wkld>"E:\workspace\cuda\cuda\bin\nvcc.exe"  --use-local-env -ccbin "D:\visual studio\ide\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64" -x cu    -IE:\workspace\cuda\cuda\include     --keep-dir cmTC_62967\x64\Debug -use_fast_math -maxrregcount=0   --machine 64 --compile -cudart static --machine 64 --keep --optix-ir -std=c++17 --generate-code=arch=compute_52,code=[compute_52,sm_52] -Xcompiler="-Ob0 -Zi" -g  -D"CMAKE_INTDIR=\"Debug\"" -D_MBCS -D"CMAKE_INTDIR=\"Debug\"" -Xcompiler "/EHsc /W1 /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler "/FdcmTC_62967.dir\Debug\vc143.pdb" -o cmTC_62967.dir\Debug\main.obj "E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\build\CMakeFiles\CMakeScratch\TryCompile-j9wkld\main.cu" 
main.cu
nvcc fatal   : Failed to create the host compiler response file 'cmTC_6ae67/x64/Debug/main.cpp1.ii.res'

So, now I’m a bit clueless.

Do you have any ideas what might cause the issue?

Edit: it works, though, if I omit the --keep and -optix-ir flags. I also tested if --optix-ir might help, but it also causes an issue. So it’s caused by --keep and -optix-ir. How do I set those flags properly? sigh I just figured out that the Compiler Output Directory isn’t set properly either…

Thank you

Markus

First, let’s analyze what your current NVCC command line actually does. Please read all comments I added:

"E:\workspace\cuda\cuda\bin\nvcc.exe"  // If you install CUDA toolkits into versioned folders, the path would indicate which CUDA version you're actually using.
--use-local-env // OK when translating from within MSVS IDE. Does not reconfigure the MSVC environment every time.
-ccbin "D:\visual studio\ide\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64"  // OK, explicitly selects the host compiler 64 bit version.
-x cu // Not required. Let's all input files be handled as *.cu files.
-IE:\workspace\cuda\cuda\include // YES, required.
--keep-dir cmTC_62967\x64\Debug // Not required when not using --keep (see below).
-use_fast_math // YES, use the fast math library. Generates faster device code (for trigonometric functions, sqrt, reciprocals, etc) 
-maxrregcount=0 // Not required. If this option is not specified, then no maximum is assumed. Value less than the minimum registers required by ABI will be bumped up by the compiler to ABI minimum limit.
--machine 64 // YES, must be 64 bit
--compile // BUG. Remove! Only --ptx or --optix-ir must be set. This means "Compile each .c/.cc/.cpp/.cxx/.cu input file into an object file." but you do not want to compile *.cu code to object files here, instead this should only translate it to PTX or OptiX-IR intermediate sources.
-cudart static // Not required, you shouldn't do CUDA runtime calls in OptiX device code.-
--machine 64 // Yes, duplicate
--keep // Not required. This will keep all intermediate files (*.i;*.ii;*.iii, etc.) from the NVCC compilation phase and it will place them in the above --keep-dir. That is only needed for debugging CUDA compiler issues.
--optix-ir // Yes, generate OptiX-IR output.
-std=c++17 // OK, 
--generate-code=arch=compute_52,code=[compute_52,sm_52] // Generate code for Maxwell second generation GPU. OK when wanting to support all OptiX supported GPUs.
-Xcompiler="-Ob0 -Zi" // Host compiler settings.
-g // Not required, this means NVCC generates host debug code, but you're not generating any host code when translating *.cu files to OptiX module input PTX or OptiX IR. (Note that capital letter -G would mean debug device code and that is abysmally slow! Never set that unless you want to debug device code.)
-D"CMAKE_INTDIR=\"Debug\"" // Set CMake intermediate directory. Shouldn't be required
-D_MBCS // Not required, support for multi-byte chars on the host.
-D"CMAKE_INTDIR=\"Debug\"" // Duplicate from above.
-Xcompiler "/EHsc /W1 /nologo /Od /FS /Zi /RTC1 /MDd " // Host compiler options.
-Xcompiler "/FdcmTC_62967.dir\Debug\vc143.pdb" // Not required. Host compiler program database. NVCC compiles  nly device code here.
-o cmTC_62967.dir\Debug\main.obj // BUG: This is for the --compile setting when generating CUDA object code. The should be -o cmTC_62967.dir\Debug\main.optixir when using --optix-ir and -o cmTC_62967.dir\Debug\main.ptx for when using --ptx.
"E:\<very_long_path_path>\main.cu" // YES, required input file.
//  I would recommend to make path names under Windows rather short because there is a default limit of 260 characters (MAX_PATH) which can be increased with some registry setting (LongPathsEnabled).

Now, there are two ways to generate a specific NVCC command line with CMake.

One method is to build a custom build rule for each OptiX device code *.cu file. That can be done with a CMake macro which gets a list or *.cu files and a list of dependencies. I’m using this inside my OptiX examples.

This is the macro which can generate build rules for *.ptx and *.optixir output:
https://github.com/NVIDIA/OptiX_Apps/blob/master/3rdparty/CMake/nvcuda_compile_module.cmake
And this is how it’s called:
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/rtigo12/CMakeLists.txt#L202

It requires the find_package(CUDAToolkit 10.0 REQUIRED) and at least one of the find_package(OptiX* ) in the root CMakeLists.txt to be able to set the OPTIX_INCLUDE_DIR variable.

Note that this macro contains some commented-out message instructions which will print out the exact NVCC command line used for each of the input *.cu files during the CMake configuration which is helpful when testing different settings.

The other method is for applications which are using native CUDA kernels with the CUDA Runtime API and also translate OptiX device code to *.ptx or *.optixir by using the CMake LANGUAGE CUDA feature.
I that case the native CUDA files need to be compiled to object code (host and device parts) and the OptiX *.cu files which are only device code should not be in that list and must be handled differently.

CMake solves that by the Object Library feature.
I’ve posted a CMakeLists.txt which demonstrates that partitioning of the *.cu files in a project into native and OptiX module input files here:
https://forums.developer.nvidia.com/t/why-am-i-getting-optix-dir-notfound/279085/4
Read this as well:
https://forums.developer.nvidia.com/t/question-about-add-a-cu-in-my-project/284761/4

1 Like

Thank you, I’ll try it in the next days when I find the time.

Hello,

so, I tried to include the nvcuda_compile_module.cmake and use the defined function in my CMakeLists.txt. I can now configure and build the project, however, it appears that none of the specified build settings are used in the project.

SET(PROJECT_NAME A5_OptiXRaytracing)

set(OPTIX_DIRECTORY "E:/workspace/cuda/optix/" CACHE PATH "Path to the OptiX directory")

set(SOURCES Camera.cpp
			GLSLShader.cpp
			OpenGLDebugger.cpp
			Renderer.cpp
			Texture.cpp
			main.cpp
)
set(HEADERS Camera.h
			GLSLShader.h
			OpenGLDebugger.h
			Renderer.h
			Texture.h
)
set(CG_SOURCES 	cg/BufferCombo.cpp
				cg/CGRenderer.cpp
				cg/ConversionFunctions.cpp
				cg/UI.cpp
)
set(CG_HEADERS 	cg/BufferCombo.h
				cg/CGRenderer.h
				cg/ConversionFunctions.h
				cg/EnumStringConverter.h
				cg/Parameter.h
				cg/ShaderEnums.h
				cg/UI.h
				cg/UIEventHandler.h
)
set(OPTIX_SOURCES 	optix/CUDABuffer.cpp
					optix/Denoiser.cpp
					optix/OptixRenderer.cpp
					optix/OptixUtil.cpp
					optix/Raytracing.cu
)
set(OPTIX_SHADER 	optix/Raytracing.cu
)
set(SHADER_DEPENDENCIES 
)
set(OPTIX_HEADERS 	optix/CUDABuffer.h
					optix/Denoiser.h
					optix/LaunchParams.h
					optix/OptixRenderer.h
					optix/OptixUtil.h
					optix/RandomGenerator.h
					optix/SamplingArrays.cuh
)
set(SHADER_SOURCES 	shader/CanvasFragment.glsl
					shader/CanvasVertex.glsl
					shader/GenerationFragment.glsl
					shader/GenerationVertex.glsl
					shader/ShadowpassFragment.glsl
					shader/ShadowpassVertex.glsl
)


set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE debug)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

set(LIBRARIES ObjLoader ImageLoader AntTweakBar freeglut glfw)


project(${PROJECT_NAME} LANGUAGES CXX CUDA)

cmake_path(GET PROJECT_SOURCE_DIR PARENT_PATH PARENT_DIR)

set(IMGUI_SOURCES 	${PARENT_DIR}/Dependencies/imgui/imgui.cpp
					${PARENT_DIR}/Dependencies/imgui/imgui_draw.cpp
					${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_glfw.cpp
					${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_opengl3.cpp
					${PARENT_DIR}/Dependencies/imgui/misc/cpp/imgui_stdlib.cpp
					${PARENT_DIR}/Dependencies/imgui/imgui_tables.cpp
					${PARENT_DIR}/Dependencies/imgui/imgui_widgets.cpp
)

add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${CG_SOURCES} ${CG_HEADERS} ${OPTIX_SOURCES} ${OPTIX_HEADERS} ${SHADER_SOURCES} ${IMGUI_SOURCES} ${PARENT_DIR}/Dependencies/glad/glad.c)
source_group("Source Files\\headers" FILES ${HEADERS})
source_group("Source Files\\headers\\cg" FILES ${CG_HEADERS})
source_group("Source Files\\headers\\optix" FILES ${OPTIX_HEADERS})
source_group("Source Files\\src" FILES ${SOURCES})
source_group("Source Files\\src\\cg" FILES ${CG_SOURCES})
source_group("Source Files\\src\\optix" FILES ${OPTIX_SOURCES})
source_group("Source Files\\shaders" FILES ${SHADER_SOURCES})
source_group("Source Files\\imgui" FILES ${IMGUI_SOURCES})
source_group("Source Files\\glad" FILES ${PARENT_DIR}/Dependencies/glad/glad.c)
create_target_launcher(${PROJECT_NAME} WORKING_DIRECTORY ${${PROJECT_NAME}_SOURCE_DIR})

target_link_libraries(${PROJECT_NAME} ${LIBRARIES} cuda)
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Aufgaben")
install_sample(${PROJECT_NAME} ${SOURCES})

target_include_directories(A5_OptiXRaytracing PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

target_include_directories(A5_OptiXRaytracing PRIVATE "${CMAKE_SOURCE_DIR}//Dependencies//imgui")
target_include_directories(A5_OptiXRaytracing PRIVATE "${CMAKE_SOURCE_DIR}//Dependencies//magic_enum")
target_include_directories(A5_OptiXRaytracing PRIVATE "${CMAKE_SOURCE_DIR}//Dependencies//glad")

set(OPTIX_INCLUDE_DIR 	"${OPTIX_DIRECTORY}//include"
						"${OPTIX_DIRECTORY}//SDK"
						"${OPTIX_DIRECTORY}//SDK//build"
)
# target_include_directories(A5_OptiXRaytracing PRIVATE "${OPTIX_DIRECTORY}//include")
# target_include_directories(A5_OptiXRaytracing PRIVATE "${OPTIX_DIRECTORY}//SDK")
# target_include_directories(A5_OptiXRaytracing PRIVATE "${OPTIX_DIRECTORY}//SDK//build")
target_include_directories(A5_OptiXRaytracing PRIVATE ${OPTIX_INCLUDE_DIR})


NVCUDA_COMPILE_MODULE(
  SOURCES ${OPTIX_SHADER}
  DEPENDENCIES ${SHADER_DEPENDENCIES}
  TARGET_PATH "${CMAKE_BINARY_DIR}/gpu-code"
  EXTENSION ".optixir"
  GENERATED_FILES PROGRAM_MODULES
  NVCC_OPTIONS "--optix-ir" "--machine=64" "--gpu-architecture=compute_52" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" #"-I${OPTIX_INCLUDE_DIR}" "-I${CMAKE_CURRENT_SOURCE_DIR}/shaders"
)

The double appearance of Raytracing.cu 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).

The VS settings look like this:


I would have expected a different Compiler Output (obj/cubin) entry (since TARGET_PATH above is set to point to a subfolder gpu-code). Other flags (like use_fast_math) aren’t set either.

This is the generated command line:


# (Approximate command-line.  Settings inherited from host are not visible below.)
# (Please see the output window after a build for the full command-line)

# Driver API (NVCC Compilation Type is .cubin, .gpu, or .ptx)
set CUDAFE_FLAGS=--sdk_dir "C:\Program Files (x86)\Windows Kits\10\"
"E:\workspace\cuda\cuda\bin\nvcc.exe" --use-local-env -ccbin "D:\visual studio\ide\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64" -x cu   -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\FreeImage\Source" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\freeglut\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\GLTools\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\AntTweakBar\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glew\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glm\glm" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\A5_OptiXRaytracing" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\imgui" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\magic_enum" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glad" -IE:\workspace\cuda\optix\include -IE:\workspace\cuda\optix\SDK -IE:\workspace\cuda\optix\SDK\build -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glfw\include"      --keep-dir x64\Debug  -maxrregcount=0   --machine 64 --compile -cudart static  -D_WINDOWS -DFREEIMAGE_LIB -DTW_STATIC -D_CRT_SECURE_NO_WARNINGS -DFREEGLUT_LIB_PRAGMAS=0 -DFREEGLUT_STATIC -DTW_NO_LIB_PRAGMA -D"CMAKE_INTDIR=\"Debug\"" -o A5_OptiXRaytracing.dir\Debug\%(Filename).obj "%(FullPath)"

# Runtime API (NVCC Compilation Type is hybrid object or .c file)
set CUDAFE_FLAGS=--sdk_dir "C:\Program Files (x86)\Windows Kits\10\"
"E:\workspace\cuda\cuda\bin\nvcc.exe" --use-local-env -ccbin "D:\visual studio\ide\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64" -x cu   -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\FreeImage\Source" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\freeglut\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\GLTools\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\AntTweakBar\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glew\include" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glm\glm" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\A5_OptiXRaytracing" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\imgui" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\magic_enum" -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glad" -IE:\workspace\cuda\optix\include -IE:\workspace\cuda\optix\SDK -IE:\workspace\cuda\optix\SDK\build -I"E:\workspace\computergrafik-opengl-rahmenprogramm-solved-edition\CGRahmenprogramm\Dependencies\glfw\include"      --keep-dir x64\Debug  -maxrregcount=0   --machine 64 --compile -cudart static  -g  -D_WINDOWS -DFREEIMAGE_LIB -DTW_STATIC -D_CRT_SECURE_NO_WARNINGS -DFREEGLUT_LIB_PRAGMAS=0 -DFREEGLUT_STATIC -DTW_NO_LIB_PRAGMA -D"CMAKE_INTDIR=\"Debug\"" -Xcompiler "/EHsc  /nologo /Od /FS /Zi /RTC1 /MDd " -Xcompiler "/Fd[ProgramDataBaseFileName]" -o A5_OptiXRaytracing.dir\Debug\%(Filename).obj "%(FullPath)"

with additional options:

%(AdditionalOptions) -std=c++17 --generate-code=arch=compute_52,code=[compute_52,sm_52] -Xcompiler="/EHsc -Ob0 -Zi"

So, considering your previous comments on the generated command line prompt, it appears that something strange is going on (like what is creating the --keep-dir entry? Why is --compile added? etc.)

I’m pretty confused right now…

Thank you for your help

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 Raytracing.cu) and you generated custom build rules OptiX device code *.cu files (also the Raytracing.cu) with my CMake macro NVCUDA_COMPILE_MODULE.

These two things are mutually exclusive!

The double appearance of Raytracing.cu 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: https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/intro_runtime/CMakeLists.txt
    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 Raytracing.cu)
    For that copy the CMakeLists.txt code from this post:
    https://forums.developer.nvidia.com/t/why-am-i-getting-optix-dir-notfound/279085/4
    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

I don’t have any native CUDA kernels in my Raytracing.cu file.

So I went with the first bullet point and tried to stick to the example (OptiX_Apps/apps/intro_runtime/CMakeLists.txt at master · NVIDIA/OptiX_Apps · GitHub) as closely as possible (added lines for create_target_launcer etc. at the end of the file and of course adjusted the files for my project)

This is what I have changed in the CMakeLists.txt:

SET(PROJECT_NAME A5_OptiXRaytracing)

project(${PROJECT_NAME})

set(OPTIX_DIRECTORY "E:/workspace/cuda/optix/" CACHE PATH "Path to the OptiX directory")

cmake_path(GET PROJECT_SOURCE_DIR PARENT_PATH PARENT_DIR)

set(CPP_SOURCES Camera.cpp
			GLSLShader.cpp
			OpenGLDebugger.cpp
			Renderer.cpp
			Texture.cpp
			main.cpp
)
set(CPP_HEADERS Camera.h
			GLSLShader.h
			OpenGLDebugger.h
			Renderer.h
			Texture.h
)
set(CG_SOURCES 	cg/BufferCombo.cpp
				cg/CGRenderer.cpp
				cg/ConversionFunctions.cpp
				cg/UI.cpp
)
set(CG_HEADERS 	cg/BufferCombo.h
				cg/CGRenderer.h
				cg/ConversionFunctions.h
				cg/EnumStringConverter.h
				cg/Parameter.h
				cg/ShaderEnums.h
				cg/UI.h
				cg/UIEventHandler.h
)
set(OPTIX_SOURCES 	optix/CUDABuffer.cpp
					optix/Denoiser.cpp
					optix/OptixRenderer.cpp
					optix/OptixUtil.cpp
)
set(OPTIX_HEADERS 	optix/CUDABuffer.h
					optix/Denoiser.h
					optix/LaunchParams.h
					optix/OptixRenderer.h
					optix/OptixUtil.h
					optix/RandomGenerator.h
)
set(OPTIX_SHADER_SOURCES 	optix/Raytracing.cu
)
set(OPTIX_SHADER_HEADERS	optix/SamplingArrays.cuh
)
set(GLSL_SHADER 	shader/CanvasFragment.glsl
					shader/CanvasVertex.glsl
					shader/GenerationFragment.glsl
					shader/GenerationVertex.glsl
					shader/ShadowpassFragment.glsl
					shader/ShadowpassVertex.glsl
)
message("Parent Dir: ${PARENT_DIR}")
set(IMGUI_SOURCES 	${PARENT_DIR}/Dependencies/imgui/imgui.cpp
					${PARENT_DIR}/Dependencies/imgui/imgui_draw.cpp
					${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_glfw.cpp
					${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_opengl3.cpp
					${PARENT_DIR}/Dependencies/imgui/misc/cpp/imgui_stdlib.cpp
					${PARENT_DIR}/Dependencies/imgui/imgui_tables.cpp
					${PARENT_DIR}/Dependencies/imgui/imgui_widgets.cpp
)


set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE debug)

set(LIBRARIES ObjLoader ImageLoader AntTweakBar freeglut glfw)


find_package(CUDAToolkit REQUIRED)


set(USE_OPTIX_IR true)
set(OPTIX_MODULE_EXTENSION ".optixir")
set(OPTIX_PROGRAM_TARGET "--optix-ir")



source_group("Source Files\\headers" FILES ${CPP_HEADERS})
source_group("Source Files\\headers\\cg" FILES ${CG_HEADERS})
source_group("Source Files\\headers\\optix" FILES ${OPTIX_HEADERS} ${OPTIX_SHADER_HEADERS})

source_group("Source Files\\src" FILES ${CPP_SOURCES})
source_group("Source Files\\src\\cg" FILES ${CG_SOURCES})
source_group("Source Files\\src\\optix" FILES ${OPTIX_SOURCES} ${OPTIX_SHADER_SOURCES})

source_group("Source Files\\shaders" FILES ${SHADER_SOURCES})

source_group("Source Files\\imgui" FILES ${IMGUI_SOURCES})
source_group("Source Files\\glad" FILES ${PARENT_DIR}/Dependencies/glad/glad.c)




set(OPTIX_INCLUDE_DIR 	"${OPTIX_DIRECTORY}//include"
						"${OPTIX_DIRECTORY}//SDK"
						"${OPTIX_DIRECTORY}//SDK//build"
)

message("Current Source Dir: ${CMAKE_CURRENT_SOURCE_DIR}")

NVCUDA_COMPILE_MODULE(
	SOURCES ${OPTIX_SHADER_SOURCES}
	DEPENDENCIES ${OPTIX_SHADER_HEADERS}
	TARGET_PATH "${CMAKE_BINARY_DIR}/gpu-code"
	EXTENSION ${OPTIX_MODULE_EXTENSION}
	GENERATED_FILES PROGRAM_MODULES
	NVCC_OPTIONS ${OPTIX_PROGRAM_TARGET} "--machine=64" "--gpu-architecture=compute_52" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" "-I${OPTIX_INCLUDE_DIR}" "-I${CMAKE_CURRENT_SOURCE_DIR}/optix"
)

include_directories( 	"${CMAKE_CURRENT_SOURCE_DIR}"
						"${CMAKE_SOURCE_DIR}//Dependencies//imgui"
						"${CMAKE_SOURCE_DIR}//Dependencies//magic_enum"
						"${CMAKE_SOURCE_DIR}//Dependencies//glad"
						${OPTIX_INCLUDE_DIR}
)


add_definitions("-D_CRT_SECURE_NO_WARNINGS")
add_definitions("-DUSE_OPTIX_IR")


add_executable(	${PROJECT_NAME} 
				${IMGUI_SOURCES} 
				${CPP_HEADERS} 
				${CPP_SOURCES} 
				${CG_HEADERS} 
				${CG_SOURCES} 
				${OPTIX_HEADERS} 
				${OPTIX_SOURCES} 
				${OPTIX_SHADER_HEADERS} 
				${OPTIX_SHADER_SOURCES}
				${PARENT_DIR}/Dependencies/glad/glad.c
)

target_link_libraries( ${PROJECT_NAME} 	${LIBRARIES} 
										CUDA::cudart
										CUDA::cuda_driver
)

create_target_launcher(${PROJECT_NAME} WORKING_DIRECTORY ${${PROJECT_NAME}_SOURCE_DIR})
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Aufgaben")
install_sample(${PROJECT_NAME} ${SOURCES})

The project builds successfully, however, Raytracing.cu.optixir is not being generated. I checked the entire build output but there was no nvcc call or something cuda related. Also, the CUDA C/C++ entries in the project settings is gone (as intended, I suppose?)

If that is your whole CMakeLists.txt hierarchy, then you’re not including the macro itself.
Isn’t there any CMake error message when you’re configuring and generating the solution?

Please read this post I linked above again:
https://forums.developer.nvidia.com/t/why-am-i-getting-optix-dir-notfound/279085/4

You’re missing some steps described in there:
If you want to build a CMake project for OptiX from scratch, I would recommend the following:
Sync my OptiX Advanced Examples linked here.
You only need the 3rdparty/CMake folder and two CMakeLists.txt files from that.
Then to build a standalone OptiX project, you need to merge two CMakeLists.txt files:
1.) The root CMakeLists.txt file which sets up all things like the CMAKE_MODULE_PATH to find the CMake scripts without the final add_subdirectory(apps) and
2) The contents of one CMakeLists.txt of one individual example (the intro_runtime one when you want to use the CUDA Runtime API and any of the others when using the CUDA Driver API. The difference is just CUDA::cudart inside thetarget_link_library() ).
3.) Then you adjust the project name everywhere, change all the find_package() statements to what you need inside your project, and replace all source code filenames with your own and that’s about it.

The point 1 above means you’re missing line 8 and 12 from here:
https://github.com/NVIDIA/OptiX_Apps/blob/master/CMakeLists.txt#L8

You’re also missing to add the generated list of PROGRAM_MODULES (the *.optixir filenames) to the executable:
Filled here by the macro: https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/intro_runtime/CMakeLists.txt#L158
Added to the executable here: https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/intro_runtime/CMakeLists.txt#L198
so that the project knows that it actually needs to build these.

The filename of the generated module should be Raytracing.optixir (or Raytracing.ptx when building *.ptx). The macro is stripping the *.cu extension.

If you enable this message inside the macro, you will see the generated NVCC command lines inside the CMake GUI output window:
https://github.com/NVIDIA/OptiX_Apps/blob/master/3rdparty/CMake/nvcuda_compile_module.cmake#L45

If you want to see custom build commands inside the MSVS output during compilation, you need to increase the MSBuild verbosity like described here:
https://forums.developer.nvidia.com/t/redirect-nvcc-build-output-to-visual-studio-output-window/279618/2

Also, the CUDA C/C++ entries in the project settings is gone (as intended, I suppose?)

Yes. Since all *.cu files are now built with custom build rules, the CUDA Visual Studio Integration sheets are not applicable to those.

1 Like

Oh, sorry, I didn’t understand that your previous answer was linked to the post (Why am I getting OptiX_DIR-NOTFOUND? - #4 by droettger), so I just picked the first bullet point as I’m not having any native CUDA calls in my file.

The project is a submodule of a larger sample library, so I’m trying to touch the other projects as little as possible. The top-level CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.25)

if (CMAKE_MAJOR_VERSION GREATER 2)
	cmake_policy(SET CMP0053 OLD)
	cmake_policy(SET CMP0026 OLD)
endif (CMAKE_MAJOR_VERSION GREATER 2)

project(Computergrafik)

if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
   message(SEND_ERROR "In-source builds are not allowed.")
endif("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")

SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_MODULE_PATH 
  "${Computergrafik_SOURCE_DIR}/cmake"
)

#change the default installation path
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    set(CMAKE_INSTALL_PREFIX "${Computergrafik_SOURCE_DIR}/Abgabe" CACHE PATH "Computergrafik install prefix" FORCE)
endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_INSTALL_PREFIX}")
set(CPACK_GENERATOR "ZIP")
include(Dependencies)
include(Install)
include(CreateLaunchers)

add_definitions(/DFREEIMAGE_LIB /DTW_STATIC)
include_directories(${Computergrafik_SOURCE_DIR})
#disable win32 warning
add_definitions(/D_CRT_SECURE_NO_WARNINGS -DFREEGLUT_LIB_PRAGMAS=0 -DFREEGLUT_STATIC /DTW_STATIC /DTW_NO_LIB_PRAGMA)

add_subdirectory(ObjLoader)
add_subdirectory(ImageLoader)
add_subdirectory(Utils)


# Die Projekte hinzufügen
add_subdirectory(A1_Versuch1a)
add_subdirectory(A1_Versuch1b)
add_subdirectory(A1_Versuch1c)
add_subdirectory(A1_FraktaleSzene)

add_subdirectory(A3_Normalenvektoren)
add_subdirectory(A4_CubeMapping)
add_subdirectory(A5_BumpMapping)
add_subdirectory(A5_GeometryShader)
add_subdirectory(A5_PercentageCloserSoftShadows)
add_subdirectory(A5_DisplacementMapping)

include(nvcuda_compile_module.cmake)

add_subdirectory(A5_OptiXRaytracing)

#set_target_properties(A5_OptiXRaytracing PROPERTIES VS_USER_PROPS "${PROJECT_SOURCE_DIR}/A5_OptiXRaytracing/property-sheets/optix_build_settings.props")
#set_target_properties(A5_OptiXRaytracing PROPERTIES VS_USER_PROPS "${PROJECT_SOURCE_DIR}/A5_OptiXRaytracing/property-sheets/optix_settings.props")

install(DIRECTORY Texturen DESTINATION .)
install(DIRECTORY Modelle DESTINATION .)

include(CPack)

So, the function is available in the submodule. Sorry for not mentioning this, I thought the submodule environment was enough.

I added the PROGRAM_MODULES now to the executable and the build process is being started now.

However, nvcc terminates with nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified and the cmake debug output looks like this:

Current Source Dir: E:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/A5_OptiXRaytracing
NCUDA_COMPILE_MODULE DEBUG MESSAGE: E:/workspace/cuda/cuda/bin/nvcc.exe --optix-ir;--machine=64;--gpu-architecture=compute_52;--use_fast_math;--relocatable-device-code=true;--generate-line-info;-Wno-deprecated-gpu-targets;-IE:/workspace/cuda/optix/include;E:/workspace/cuda/optix/SDK;E:/workspace/cuda/optix/SDK/build;-IE:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/A5_OptiXRaytracing/optix optix/Raytracing.cu -o E:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/build/gpu-code/Raytracing.optixir

So I assume nvcc is having issues finding optix/Raytracing.cu, which surprises me, because it’s right in the CURRENT_SOURCE_DIR in the given folder (the path to the file is E:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/A5_OptiXRaytracing/optix/Raytracing.cu). I also tried to attach the CURRENT_SOURCE_DIR to the OPTIX_SHADER_SOURCES when calling NVCUDA_COMPILE_MODULE but that didn’t change anything either.

OK, now you changed something, it’s still not working and you didn’t provide the updated CMakeLists.txt and didn’t analyze the error message carefully enough.

The error message says:

Current Source Dir: E:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/A5_OptiXRaytracing

NCUDA_COMPILE_MODULE DEBUG MESSAGE:
E:/workspace/cuda/cuda/bin/nvcc.exe
 --optix-ir;
 --machine=64;
 --gpu-architecture=compute_52;
 --use_fast_math;
 --relocatable-device-code=true;
 --generate-line-info;
 -Wno-deprecated-gpu-targets;
 -IE:/workspace/cuda/optix/include;E:/workspace/cuda/optix/SDK;E:/workspace/cuda/optix/SDK/build;
 -IE:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/A5_OptiXRaytracing/optix
optix/Raytracing.cu
 -o E:/workspace/computergrafik-opengl-rahmenprogramm-solved-edition/CGRahmenprogramm/build/gpu-code/Raytracing.optixir

See the line with -IE:/workspace/cuda/optix/include;E:/workspace/cuda/optix/SDK;E:/workspace/cuda/optix/SDK/build;?

That is actually

-IE:/workspace/cuda/optix/include;
E:/workspace/cuda/optix/SDK; 
E:/workspace/cuda/optix/SDK/build;

but you probably wanted to set include directories instead like this:

-IE:/workspace/cuda/optix/include;
-IE:/workspace/cuda/optix/SDK;
-IE:/workspace/cuda/optix/SDK/build;

instead you added multiple input files in addition to the optix/Raytracing.cu to the NVCC command line and it complained about that rightfully.

The error is this:

set(OPTIX_INCLUDE_DIR 	"${OPTIX_DIRECTORY}//include"
						"${OPTIX_DIRECTORY}//SDK"
						"${OPTIX_DIRECTORY}//SDK//build"
)

which is incorrect with "-I${OPTIX_INCLUDE_DIR}" inside the NVCC command line.

My scripts assume that the OPTIX_INCLUDE_DIR is exactly the “${OPTIX_DIRECTORY}/include”, nothing else!
If you want to have additional include directories, you need to add them individually! (Shown below.)

Let’s try doing what I described multiple times.
Please read all README comments I added. There are some inconsistencies and errors inside your script.

# FindCUDA.cmake is deprecated since CMake 3.10.
# Use FindCUDAToolkit.cmake added in CMake 3.17 instead.
cmake_minimum_required(VERSION 3.17)

project( A5_OptiXRaytracing )
message("\nPROJECT_NAME = " "${PROJECT_NAME}")

# README Why are you changing the PROJECT_SOURCE_DIR here?
# That should be the source directory of the last called project() otherwise your relative file names are incorrect.
# Also note that you're not using absolute filenames inside the OptiX shader section which will screw up stepping through error messages thown by NVCC inside the Visdual Studio IDE.
# cmake_path(GET PROJECT_SOURCE_DIR PARENT_PATH PARENT_DIR)
# Verify that this points to the right 
message("PROJECT_SOURCE_DIR = " "${PROJECT_SOURCE_DIR}")

find_package(CUDAToolkit 10.0 REQUIRED)

# README Are these things handled by your root project's include(Dependencies)?
#find_package(OpenGL REQUIRED)
#find_package(GLFW REQUIRED)

set(OPTIX_DIRECTORY "E:/workspace/cuda/optix/" CACHE PATH "Path to the OptiX directory")

set(OPTIX_INCLUDE_DIR "${OPTIX_DIRECTORY}/include")
message("OPTIX_INCLUDE_DIR = " "${OPTIX_INCLUDE_DIR}")

# OptiX SDK 7.5.0 and CUDA 11.7 added support for a new OptiX IR target, which is a binary intermediate format for the module input.
# The default module build target is PTX.
set(USE_OPTIX_IR FALSE)
set(OPTIX_MODULE_EXTENSION ".ptx")
set(OPTIX_PROGRAM_TARGET "--ptx")

# README Since you didn't use any find_package(OptiX<version> REQUIRED), this assumes you're using at least OptiX 7.5.0.
# Still check the CUDA version number from the find_package(CUDAToolkit 10.0 REQUIRED) above dynamically.

# Define USE_OPTIX_IR and change the target to OptiX IR if the combination of OptiX SDK and CUDA Toolkit versions supports this mode.
if ((${CUDAToolkit_VERSION_MAJOR} GREATER 11) OR ((${CUDAToolkit_VERSION_MAJOR} EQUAL 11) AND (${CUDAToolkit_VERSION_MINOR} GREATER_EQUAL 7)))
  set(USE_OPTIX_IR TRUE)
  set(OPTIX_MODULE_EXTENSION ".optixir")
  set(OPTIX_PROGRAM_TARGET "--optix-ir")
endif()


# README If these files are NOT inside the A5_OptiXRaytracing subfolder, then you should build yourself some OTHER_PROJECT_SOURCES_PATH variables and prefix all of these with the right path.
# Something like cmake_path(GET CPP_SOURCES_PATH PARENT_PATH PARENT_DIR) maybe.

set(CPP_SOURCES
  Camera.cpp
  GLSLShader.cpp
  OpenGLDebugger.cpp
  Renderer.cpp
  Texture.cpp
  main.cpp
)

set(CPP_HEADERS
  Camera.h
  GLSLShader.h
  OpenGLDebugger.h
  Renderer.h
  Texture.h
)

set(CG_SOURCES
  cg/BufferCombo.cpp
  cg/CGRenderer.cpp
  cg/ConversionFunctions.cpp
  cg/UI.cpp
)

set(CG_HEADERS
  cg/BufferCombo.h
  cg/CGRenderer.h
  cg/ConversionFunctions.h
  cg/EnumStringConverter.h
  cg/Parameter.h
  cg/ShaderEnums.h
  cg/UI.h
  cg/UIEventHandler.h
)

set(OPTIX_SOURCES
  optix/CUDABuffer.cpp
  optix/Denoiser.cpp
  optix/OptixRenderer.cpp
  optix/OptixUtil.cpp
)

# README Are any of these includes inside the files listed in OPTIX_SHADER_SOURCES or OPTIX_SHADER_HEADERS?
# If yes, they need to appear inside OPTIX_SHADER_HEADERS as well to have the right dependencies.
set(OPTIX_HEADERS
  optix/CUDABuffer.h
  optix/Denoiser.h
  optix/LaunchParams.h
  optix/OptixRenderer.h
  optix/OptixUtil.h
  optix/RandomGenerator.h
)

# README I'm assuming the optix folder is inside the current project's sub-directory.
# Seems like it because you include "-I${CMAKE_CURRENT_SOURCE_DIR}/optix" in the NVCC command line.
# Prefix the shaders with the full path name to allow stepping through errors with F8.
set(OPTIX_SHADER_SOURCES
  ${CMAKE_CURRENT_SOURCE_DIR}/optix/Raytracing.cu
)

set(OPTIX_SHADER_HEADERS
  ${CMAKE_CURRENT_SOURCE_DIR}/optix/SamplingArrays.cuh
)

# README Since these are not appearing inside the add_executable() I assume you just want them to be inside the source group but they are not actually part of the build but translated by OpenGL at runtime?
set(GLSL_SHADER
  shader/CanvasFragment.glsl
  shader/CanvasVertex.glsl
  shader/GenerationFragment.glsl
  shader/GenerationVertex.glsl
  shader/ShadowpassFragment.glsl
  shader/ShadowpassVertex.glsl
)

message("Parent Dir: ${PARENT_DIR}")

set(IMGUI_SOURCES
  ${PARENT_DIR}/Dependencies/imgui/imgui.cpp
  ${PARENT_DIR}/Dependencies/imgui/imgui_draw.cpp
  ${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_glfw.cpp
  ${PARENT_DIR}/Dependencies/imgui/backends/imgui_impl_opengl3.cpp
  ${PARENT_DIR}/Dependencies/imgui/misc/cpp/imgui_stdlib.cpp
  ${PARENT_DIR}/Dependencies/imgui/imgui_tables.cpp
  ${PARENT_DIR}/Dependencies/imgui/imgui_widgets.cpp
)

# Checking where the *.optixir files go.
message("CMAKE_BINARY_DIR = " "${CMAKE_BINARY_DIR})

# When using OptiX SDK 7.5.0 and CUDA 11.7 or higher, the modules can either be built from OptiX IR input or from PTX input.
# OPTIX_PROGRAM_TARGET and OPTIX_MODULE_EXTENSION switch the NVCC compilation between the two options.
# README Note that I'm using compute_50 to also support first generation Maxwell. compute_52 should be fine. If you don't need to support such old GPUs, use compute_60 for Pascal and up.
# README Note that "-I${OPTIX_DIRECTORY}/SDK" "-I${OPTIX_DIRECTORY}/SDK/build" have been added. See below why this is a bad idea. These files also don't appear inside the source_groups.
NVCUDA_COMPILE_MODULE(
  SOURCES ${OPTIX_SHADER_SOURCES}
  DEPENDENCIES ${OPTIX_SHADER_HEADERS}
  TARGET_PATH "${CMAKE_BINARY_DIR}/gpu-code"
  EXTENSION "${OPTIX_MODULE_EXTENSION}"
  GENERATED_FILES PROGRAM_MODULES
  NVCC_OPTIONS "${OPTIX_PROGRAM_TARGET}" "--machine=64" "--gpu-architecture=compute_50" "--use_fast_math" "--relocatable-device-code=true" "--generate-line-info" "-Wno-deprecated-gpu-targets" "-I${OPTIX_INCLUDE_DIR}" "-I${OPTIX_DIRECTORY}/SDK" "-I${OPTIX_DIRECTORY}/SDK/build" "-I${CMAKE_CURRENT_SOURCE_DIR}/optix"
)

source_group( "cpp_headers" FILES ${CPP_HEADERS} )
source_group( "cpp_sources" FILES ${CPP_SOURCES} )
source_group( "cg_headers"  FILES ${CG_HEADERS} )
source_group( "cg_sources"  FILES ${CG_SOURCES} )
source_group( "optix_headers"  FILES ${OPTIX_HEADERS} )
source_group( "optix_sources"  FILES ${OPTIX_SOURCES} )
source_group( "optix_shader_headers"  FILES ${OPTIX_SHADER_HEADERS} )
source_group( "optix_shader_sources"  FILES ${OPTIX_SHADER_SOURCES} )
source_group( "glsl_shader"  FILES ${GLSL_SHADER} )
source_group( "imgui_sources"  FILES ${IMGUI_SOURCES} )

include_directories(
  "${CMAKE_CURRENT_SOURCE_DIR}"
  "${CMAKE_SOURCE_DIR}/Dependencies/imgui"
  "${CMAKE_SOURCE_DIR}/Dependencies/magic_enum"
  "${CMAKE_SOURCE_DIR}/Dependencies/glad"
  ${OPTIX_INCLUDE_DIR}
  # I seriously recommend to NOT reference source files from the OptiX SDK examples like this inside applications living outside the OptiX SDK framework.
  # Instead copy everything you need locally and make yout application work standalone!
  "${OPTIX_DIRECTORY}/SDK" # README Added manually.
  "${OPTIX_DIRECTORY}/SDK/build" # README Added manually. 
  # README Was missing.
  ${CUDAToolkit_INCLUDE_DIRS}
)

add_definitions(
  # Disable warnings for file operations fopen etc.
  "-D_CRT_SECURE_NO_WARNINGS"
)

if(USE_OPTIX_IR)
add_definitions(
  # This define switches the OptiX program module filenames to either *.optixir or *.ptx extensions at compile time.
  "-DUSE_OPTIX_IR"
)
endif()


add_executable(	${PROJECT_NAME} 
  ${IMGUI_SOURCES} 
  ${CPP_HEADERS} 
  ${CPP_SOURCES} 
  ${CG_HEADERS} 
  ${CG_SOURCES} 
  ${OPTIX_HEADERS} 
  ${OPTIX_SOURCES} 
  ${OPTIX_SHADER_HEADERS} 
  ${OPTIX_SHADER_SOURCES}
  ${PROGRAM_MODULES} # README Added.
  # README Why is this in ${PARENT_DIR}/Dependencies while the include directories "${CMAKE_SOURCE_DIR}/Dependencies/glad". This is inconsistent.
  ${PARENT_DIR}/Dependencies/glad/glad.c 
)

# README How is this supposed to work?
# For example, if you're using GLFW calls inside your application, where are the GLFW include directories set to find the necessary headers?
# Also if you're using freeglut, why is there no find_package(OpenGL REQUIRED) above and OpenGL::GL inside the target_link_libraries()?
# I'm assuming your include(Dependencies) inside the root CMakeLists.txt figures these out?
# Also why is there an AntTweakBar dependency while you're using ImGUI? Are there different GUIs inside the app?
set(LIBRARIES
  ObjLoader
  ImageLoader
  AntTweakBar
  freeglut
  glfw
)

target_link_libraries( ${PROJECT_NAME}
  ${LIBRARIES} 
  CUDA::cudart
  CUDA::cuda_driver
)

# README Just copied from your project. Not looked at.
create_target_launcher(${PROJECT_NAME} WORKING_DIRECTORY ${${PROJECT_NAME}_SOURCE_DIR})

SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER "Aufgaben")

install_sample(${PROJECT_NAME} ${SOURCES})

Given that this is a student assignment, I would recommend you work with your tutors to solve any CMake build problems.
If you actually have issues with OptiX itself, that would the right forum to discuss them.

Thank you very much for your help. Since I basically just added PROGRAM_MODULES to the executables, I thought the changes to that CMakeLists.txt wouldn’t justify posting the entire file again. As you wrote, the issue was caused by the multiple includes. I guess this was hidden in the self-documenting code.

Well, at the end of the day, it’s someone’s task to maintain code bases, which is rarely done by students, and considering the available CMake documentation regarding OptiX, which often turns out to be misleading or frankly wrong (I mean set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --machine 64 --use_fast_math --keep -optix-ir") wasn’t based on wishful thinking for sure), it might make sense to invest some resources in the improvement of documentation.

The explanations inside the OptiX Programming Guide chapter 6.1. Program Input describe how to construct a working NVCC command line or NVRTC build options.

–keep was not the problem. That only leaves intermediate compiler generated files on disk which is helpful to analyze NVCC compiler issues but isn’t required otherwise. The OptiX SDK doesn’t use it (unless the CUDA toolkit version is older than 3.0 (not sure why) but these are too old anyway) and it’s also not used inside my OptiX examples, so not sure where you got that from.

CMake is only a tool used to generate cross-platform build scripts. It’s also possible to use the CUDA Visual Studio Integration you began with, but then you must explicitly set all parameters for each individual *.cu file exactly as described inside the OptiX Programming Guide and that is rather tedious to do for all build targets.