Search code examples
c++visual-studioboostmsbuildpropertysheet

project building with and without boost


I have a project that can use boost library and it can also not to use it. I have a property sheet use_boost that can be added to the project and there are set the path to boost and a <PreprocessorDefinitions> tag with value I_AM_USING_BOOST.

In the code I have something like:

#ifdef I_AM_USING_BOOST
   #include <boost/any.hpp>
#else 
   #include <string>
#endif


namespace test
{


#ifdef I_AM_USING_BOOST
  using my_defined_type = boost::any;
#else
  using my_defined_type = std::string;
#endif


}

So if I do not want a build with boost, I remove the property sheet. If I want to build with boost, I add the property sheet to the project.

Now, I want to build both variations of the library: one using boost and one not using boost.

Can I have a single project with two different builds: one with boost and one without boost, but not manually add or remove the property sheet?

I build using msbuild from a batch file.


Solution

  • As a solution for me, I've added a new project configuration (Release_no_boost) and in that configuration I've removed the property sheet using boost library.

    So, in the batch file I can now run msbuild for both variations by calling different configurations. I have now in the batch file:

    msbuild /t:rebuild /p:Configuration=Release D:\projects\some_test\test_1\test_1.vcxproj
    msbuild /t:rebuild /p:Configuration=Release_no_boost D:\projects\some_test\test_1\test_1.vcxproj
    

    This can be also used for a solution with multiple project, but it is needed to be created a solution configuration and for each project in the solution that is build, it is set the project configuration that is wanted.

    Difference in batch is that instead of the project file it is given as parameter the solution file:

    msbuild /t:rebuild /p:Configuration=Release D:\projects\some_test\some_test.sln
    msbuild /t:rebuild /p:Configuration=Release_no_boost D:\projects\some_test\some_test.sln