-1

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.

mtb
  • 1,350
  • 16
  • 32
  • 2
    I am not following. How are you using this type later? Using `std::string` and `boost::any` commands very different patterns. – SergeyA May 13 '16 at 14:41
  • 3
    Yes you can, create two different targets in the project and set the properties for each target. – Richard Hodges May 13 '16 at 14:43
  • you could also provide the property via command line to msbuild with `/p:=` – Wurmloch May 13 '16 at 14:50
  • @SergeyA it is actually defined like std::map< std::string, boost::any > or std::map< std::string, std::string > – mtb May 13 '16 at 15:00
  • http://stackoverflow.com/questions/606660/does-msbuild-recognise-any-build-configurations-other-than-debugrelease and http://stackoverflow.com/questions/10714668/how-do-you-pass-conditional-compilation-symbols-defineconstants-to-msbuild – ivan_pozdeev May 18 '16 at 11:27

1 Answers1

0

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
mtb
  • 1,350
  • 16
  • 32