Not compile some files based on current configuration

Sysprogs forums Forums VisualGDB Not compile some files based on current configuration

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26745
    Jose Cazarin
    Participant

    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:

    <ClCompile Include=”tests\tests.cpp”>
    <ExcludedFromBuild Condition=”‘$(Configuration)|$(Platform)’==’Debug|x64′”>true</ExcludedFromBuild>
    <ExcludedFromBuild Condition=”‘$(Configuration)|$(Platform)’==’Tests|x64′”>false</ExcludedFromBuild>
    </ClCompile>

    <ClCompile Include=”main.cpp”>
    <ExcludedFromBuild Condition=”‘$(Configuration)|$(Platform)’==’Tests|x64′”>true</ExcludedFromBuild>
    <ExcludedFromBuild Condition=”‘$(Configuration)|$(Platform)’==’Debug|x64′”>false</ExcludedFromBuild>
    </ClCompile>

    But both files are still being compiled on both configurations. Can this be a case of VisualGDB overriding those settings and always compiling all files?

     

    #26750
    support
    Keymaster

    Thanks for confirming your license key.

    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:

    1. 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.
    2. 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).
    #26767
    Jose Cazarin
    Participant

    Thank you, actually I thought about the ifdef solution a while after I posted it here, and it worked. Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.