Using Visual Studio Code 1.39.2 on Ubuntu 18.04. My C++ program has tasks for generating a Makefile with Cmake using the command cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug ..
. There is an equivalent Release
version.
Thereafter, a make
task is run which correctly builds a DEBUG and RELEASE version in ./PROJECT/build/Debug
or ./PROJECT/build/Release
folders.
The problem is that Visual Studio Code does not understand any Debug
or _DEBUG
symbols, so code like the following does not work as expected:
#ifdef _DEBUG // or #ifdef Debug
cout << "Debug build\n";
#else
cout << "Release build\n";
#endif
When the application is run, only Release build
is printed, never Debug build
. Moreover, in the Visual Studio Code editor, the Debug build
line is greyed out.
Manually defining the symbols with #define DEBUG
is an option, but will require manually editing the file every time the build type is changed.
How do you get Visual Studio Code to define and understand the correct symbols based on the selected build task? Or is there some clever way to get Code to "look into" the generated CMake/make files (such as CMakeCache.txt, cmake_install.cmake, Makefile)?