Hello! I’m trying to set up a project with two configurations:
One for tests (Tests)
Another one for debug (Debug)
In the Tests configuration, I want the file tests.cpp that contains the main function that runs the tests from Google Test to be compiled, but I want this file to be excluded from compilation in the Debug config.
In the Debug configuration, I want the file main.cpp that contains the main function of the application to be compiled, but I want this file to be excluded in the Tests config.
If this works, I won’t have any problems of “redefinition of main”, since there is one main in each of these files.
I was able to do this by tweaking around some configs of the Visual Studio and now the .vcxproj looks like this:
The “Exclude from build” setting works out-of-the-box for MSBuild-based projects only. In order to achieve the same effect with GNU Make-based projects, we can advise one of the 2 workarounds:
You can manually use the $(filter-out …) expression combined with ifeq($(CONFIG), DEBUG) to filter out specific files from the source file list (see how this is handled for STARTUPFILES). VisualGDB will preserve your changes to the Makefile, although they won’t be synchronized with the VS-level “exclude from project” setting.
Alternatively, simply surround the code in your source files with #ifdef DEBUG (or any other macro used in your project to distinguish debug/release configurations).