-1

我有一个可以使用 boost 库的项目,也可以不使用它。我有一个use_boost可以添加到项目中的属性表,并且设置了 boost 的路径和一个<PreprocessorDefinitions>带有 value 的标签I_AM_USING_BOOST

在代码中我有类似的东西:

#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


}

因此,如果我不想要带有 boost 的构建,我会删除属性表。如果我想用 boost 构建,我将属性表添加到项目中。

现在,我想构建该库的两种变体:一种使用 boost,一种不使用 boost。

我是否可以拥有一个具有两种不同构建的项目:一个带有 boost,一个没有 boost,但不能手动添加或删除属性表?

我使用批处理文件中的 msbuild 构建。

4

1 回答 1

0

作为我的解决方案,我添加了一个新的项目配置 (Release_no_boost),在该配置中,我使用 boost 库删除了属性表。

因此,在批处理文件中,我现在可以通过调用不同的配置为这两种变体运行 msbuild。我现在在批处理文件中:

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

这也可以用于具有多个项目的解决方案,但需要创建解决方案配置,并且为构建的解决方案中的每个项目设置所需的项目配置。

批处理的不同之处在于,它不是项目文件,而是作为解决方案文件的参数给出:

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
于 2016-05-17T07:13:40.360 回答