I just started my first CUDA/OptiX project for a scientific path tracer to model the interaction of light with planetary regolith. I used the SDK samples as a starting point; and i have to say setting everything up went quite smoothly, thanks for all the work!
However, i have some issues with the CMAKE_BUILD_TYPE used to switch between Debug and Release builds. I am quite new to CMake, but it seams the CMakeLists.txt only sets the cuda flags
if the initial configuration is set to “Debug”.
However is the initial build type is “Release” and the type is later changed to “Debug” with ccmake the build flags are not added because everything happens in this if statement:
if( NOT PASSED_FIRST_CONFIGURE )
Is this intended this way, or am i not doing something properly?
Also there are two macros NDEBUG and DEBUG used in the SDK samples and i don’t understand the difference, or when to use which.
The intent with the first-time cmake config is to have the build flags set up for all the configurations you might be using. If you follow the logic around the uses of optix_add_cuda_flag_config, you will notice that on the first cmake configure, those macros get called for every build type in CMAKE_CONFIGURATION_TYPES (https://cmake.org/cmake/help/latest/variable/CMAKE_CONFIGURATION_TYPES.html).
On my machine, CMAKE_CONFIGURATION_TYPES is initialized with Debug , Release , RelWithDebInfo and MinSizeRel, and because of that I end up with build flags initialized for all those configurations (named CMAKE_{C,CXX}_FLAGS_<CONFIG>, where <CONFIG> is the name of the build config in all uppercase. Then when I switch to a Debug build, it has the right build flags with -G available, and I don’t have to clear my cmake cache before I reconfigure. Can you check what the value of that variable is after clearing your cmake cache and configuring for the ‘first time’?
Regarding the debug defines, once you get all the build flags working, you’ll be able to see in cmake that DEBUG is defined for a Debug build, and NDEBUG is defined for all 3 Release build types. So DEBUG and NDEBUG are the logical negation of each other, and you can use whichever one is more convenient. Might be worth noting that the RelWithDebInfo config is considered a Release build with symbols, but not intended for any Debug build features, which is why it uses NDEBUG.
Thanks for the quick response.
I am developing on Ubuntu/VSCode at the moment, and indeed, the CMAKE_CONFIGURATION_TYPES is not set.
Good news first: when I add set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo;MinSizeRel" CACHE STRING "Available build types" FORCE) at the beginning of the CMakeLists file everything works as expected.
However, if this variable is not set, I really don’t get what is going on…
The only way I can get the Pipeline statistics to say Debug information: yes is by changing the default CMAKE_BUILD_TYPE to “Debug”. Even changing from “Release” to “Debug” on the initial ccmake configuration doesn’t help.