tag:blogger.com,1999:blog-1428229206472084182024-03-05T12:14:59.898+01:00KennyKnechtKenny Knechthttp://www.blogger.com/profile/10864162727339330416noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-142822920647208418.post-1126453361461156482011-01-14T14:23:00.001+01:002011-01-14T14:24:05.521+01:00Nested ItemGroups in MSBUILDFirst something about what I want to achieve. In our setup we're using boost C++ library quite intensely and therefore we would like the code and the build process to be part of our TFS setup. We don't use the binary libraries out of the box because for example in Visual Studio 2005 and 2008 a release build was built by default with checked iterators (macro <span style="font-family: "Courier New",Courier,monospace;">_SECURE_SCL = 1</span>) and our code was build without checked iterators. Boost only supported the Visual studio defaults, so we have a long tradition of building our own boost libraries. The default checked iterator policy was changed back in Visual Studio 2010 to disabled in release mode, but we maintain both flavours.<br />
Since Visual studio 2010 we started using TFS and TFS build. The custom MSBUILD project to produce the boost binaries had the following structure<br />
<br />
<div style="background-color: #dddddd; font-family: "Courier New",Courier,monospace; font-size: 85%;overflow:auto;"><ItemGroup><br />
<BoostLib Include="regex"/><br />
<BoostLib Include="thread"/><br />
<BoostLib Include="filesystem"/><br />
<BoostLib Include="date_time"/><br />
<BoostLib Include="random"/><br />
</ItemGroup><br />
<ItemGroup><br />
 <BuildPlatform Include="Win32"><br />
<AddressModel>32</AddressModel><br />
</BuildPlatform><br />
<BuildPlatform Include="x64"><br />
<AddressModel>64</AddressModel><br />
</BuildPlatform><br />
</ItemGroup><br />
<ItemGroup><br />
<BuildVariant Include="Debug"><br />
<CxxFlag>\D_SECURE_SCL=1</CxxFlag><br />
<Variant>debug</Variant><br />
</BuildVariant><br />
<BuildVariant Include="Release"><br />
 <CxxFlag>\D_SECURE_SCL=1</CxxFlag><br />
<Variant>release</Variant><br />
</BuildVariant><br />
<BuildVariant Include="ReleaseSecure0"><br />
<CxxFlag>\D_SECURE_SCL=0</CxxFlag><br />
<Variant>release</Variant><br />
</BuildVariant><br />
</ItemGroup><br />
<PropertyGroup><br />
<_CommonCmdLine>$(ProjectDir)..\bjam.exe toolset=msvc-10.0 link=static threading=multi runtime-link=static --cxxflags=/MP</_CommonCmdLine><br />
</PropertyGroup><br />
</div>This gave me maximum flexibility: I can add or remove libraries, build variants or address models. But now I had to call bjam for each <i>combination</i>. And this is not trivial in MSBUILD.<br />
<br />
I have found <a href="http://blogs.msdn.com/b/giuliov/archive/2010/04/30/gotcha-msbuild-nested-loops-double-batching.aspx">one reference</a> to combining or nesting Items from ItemsGroups, but sadly this doesn't seem to work for me. If I attach the follwoning target, as suggested in the blog<br />
<br />
<br />
<div style="background-color: #dddddd; font-family: "Courier New",Courier,monospace; font-size: 85%;overflow:auto;"><Target Name="Build"><br />
<PropertyGroup><br />
<CurrentVariant>%(BuildVariant.CxxFlag)</CurrentVariant><br />
</PropertyGroup><br />
<Message Text="VariantPlatform $(CurrentVariant) : %(BuildPlatform.FileName)"/><br />
</Target></div><br />
The output I get reads<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRJSXdF3BS-W_RivIpWA2fIhGE1kqmvax6sjYizkLCiFC54lr-rUiF7QmKHXcw3tHjTa0Hmxr-Qw5zrNLiSqsmWrFXrixVi9Vlh0_vf0OdC1AaJqIyjLlL11mSy3R9Mhmj3YUe8p5MF7M/s1600/cmd.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRJSXdF3BS-W_RivIpWA2fIhGE1kqmvax6sjYizkLCiFC54lr-rUiF7QmKHXcw3tHjTa0Hmxr-Qw5zrNLiSqsmWrFXrixVi9Vlh0_vf0OdC1AaJqIyjLlL11mSy3R9Mhmj3YUe8p5MF7M/s1600/cmd.png" /></a></div><br />
So the property <span style="font-family: "Courier New",Courier,monospace;">CurrentVariant</span> gets all the subsequent <span style="font-family: "Courier New",Courier,monospace;">BuildVariant</span> values and in my <span style="font-family: "Courier New",Courier,monospace;">Message</span> task I'm stuck with the last value.<br />
<br />
I will not bother you with all the combinations and tricks I have tried but in the end I experimented with CreateItem and came up with the idea to batch over one type item while adding AddionalMetadata from another type. Something like this<br />
<br />
<br />
<br />
<div style="background-color: #dddddd; font-family: "Courier New",Courier,monospace; font-size: 85%;overflow:auto;"><Target Name="Build"><br />
<CreateItem<br />
Include="@(BuildVariant)"<br />
AdditionalMetadata="Platform=%(BuildPlatform.FileName);AddressModel=%(BuildPlatform.AddressModel)"><br />
<Output<br />
TaskParameter="Include"<br />
ItemName="VariantPlatform"/><br />
</CreateItem><br />
<Message Text="VariantPlatform %(VariantPlatform.Platform), %(VariantPlatform.FileName), %(VariantPlatform.AddressModel)"/><br />
</Target></div><br />
This gave the following result<br />
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwhvuGRiULYW8LAbZORlc1b-T_PDCP8onZEduF_qmPPY3bYu0q5goci6YeHE0IwVIhf8c3FOk9RfnOSjLtnejChgnfDJuGxDmTjjMz4ToHCm14ZyiT9HAZtj-V64npl7f8sSlwGkXfLrU/s1600/cmd.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwhvuGRiULYW8LAbZORlc1b-T_PDCP8onZEduF_qmPPY3bYu0q5goci6YeHE0IwVIhf8c3FOk9RfnOSjLtnejChgnfDJuGxDmTjjMz4ToHCm14ZyiT9HAZtj-V64npl7f8sSlwGkXfLrU/s1600/cmd.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRJSXdF3BS-W_RivIpWA2fIhGE1kqmvax6sjYizkLCiFC54lr-rUiF7QmKHXcw3tHjTa0Hmxr-Qw5zrNLiSqsmWrFXrixVi9Vlh0_vf0OdC1AaJqIyjLlL11mSy3R9Mhmj3YUe8p5MF7M/s1600/cmd.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><br />
</a></div>This was exactly what I was after: a combination of the two properties!<br />
<br />
<br />
For completeness here is the rest of the MSBUILD projects which builds the boost binaries<br />
<br />
<div style="background-color: #dddddd; font-family: "Courier New",Courier,monospace; font-size: 85%;overflow:auto;"><Target Name="ComposeItems" BeforeTargets="Build;Clean;Rebuild"><br />
<CreateItem<br />
Include="@(BuildVariant)"<br />
AdditionalMetadata="Platform=%(BuildPlatform.FileName);AddressModel=%(BuildPlatform.AddressModel)"><br />
<Output<br />
TaskParameter="Include"<br />
ItemName="VariantPlatform"/><br />
</CreateItem><br />
<Message Text="VariantPlatform %(VariantPlatform.Platform) : %(VariantPlatform.FileName) ? %(VariantPlatform.AddressModel)"/><br />
<CreateItem<br />
Include="@(VariantPlatform)"<br />
AdditionalMetadata="Lib=%(BoostLib.FileName)"><br />
<Output<br />
TaskParameter="Include"<br />
ItemName="Tobuild2"/><br />
</CreateItem><br />
<CreateItem<br />
Include="@(Tobuild2)"<br />
AdditionalMetadata="IntermDir=$(INTERMEDIATEROOT)\Boost_$(Boostver)\%(Tobuild2.Platform)\%(Tobuild2.FileName); OutDir=$(OUTPUT)%(Tobuild2.Platform)\%(Tobuild2.FileName)"><br />
<Output<br />
TaskParameter="Include"<br />
ItemName="Tobuild"/><br />
</CreateItem><br />
<Message Text="BUILD %(Tobuild.Lib) %(Tobuild.Platform) : %(Tobuild.FileName) ? %(Tobuild.AddressModel) %(ToBuild.StageDir)"/><br />
</Target><br />
<Target Name="Build"><br />
<Exec WorkingDirectory="$(ProjectDir)boost_$(BOOSTVER)" <br />
Command='$(_CommonCmdLine) variant=%(Tobuild.Variant) cxxflags=%(Tobuild.CxxFlag) "--stagedir=%(ToBuild.OutDir)" "--build-dir=%(ToBuild.IntermDir)" --with-%(ToBuild.Lib) stage'/><br />
</Target><br />
<Target Name="Clean"><br />
<Exec WorkingDirectory="$(ProjectDir)boost_$(BOOSTVER)"<br />
Command='$(_CommonCmdLine) --clean variant=%(Tobuild.Variant) cxxflags=%(Tobuild.CxxFlag) "--stagedir=%(ToBuild.OutDir)" "--build-dir=%(ToBuild.IntermDir)" --with-%(ToBuild.Lib) stage'/><br />
</Target><br />
<Target Name="Rebuild"><br />
<Exec WorkingDirectory="$(ProjectDir)boost_$(BOOSTVER)" <br />
Command='$(_CommonCmdLine) -a variant=%(Tobuild.Variant) cxxflags=%(Tobuild.CxxFlag) "--stagedir=%(ToBuild.OutDir)" "--build-dir=%(ToBuild.IntermDir)" --with-%(ToBuild.Lib) stage'/><br />
</Target></div>Happy programming!Kenny Knechthttp://www.blogger.com/profile/10864162727339330416noreply@blogger.com0tag:blogger.com,1999:blog-142822920647208418.post-75494660896745642342010-12-15T09:48:00.001+01:002010-12-16T08:56:14.952+01:00Command Line ready for VS2010At <span class="blsp-spelling-error" id="SPELLING_ERROR_0">times</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_1">you</span> want <span class="blsp-spelling-error" id="SPELLING_ERROR_2">to</span> do stuff <span class="blsp-spelling-error" id="SPELLING_ERROR_3">from</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_4">the</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_5">command</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_6">line</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_7">with</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_8">visual</span> studio. <span class="blsp-spelling-error" id="SPELLING_ERROR_9">The</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_10">first</span> action is <span class="blsp-spelling-error" id="SPELLING_ERROR_11">often</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_12">to</span> run <span style="font-family: courier new;"><span class="blsp-spelling-error" id="SPELLING_ERROR_13">vsvars</span>32.bat</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_14">which</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_15">injects</span> all <span class="blsp-spelling-error" id="SPELLING_ERROR_16">the</span> environment variables <span class="blsp-spelling-error" id="SPELLING_ERROR_17">the</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_18">visual</span> studio <span class="blsp-spelling-error" id="SPELLING_ERROR_19">tools</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_20">need</span>. <span class="blsp-spelling-error" id="SPELLING_ERROR_21">You</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_22">might</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_23">consider</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_24">doing</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_25">that</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_26">globally</span>, <span class="blsp-spelling-error" id="SPELLING_ERROR_27">but</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_28">this</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_29">turns</span> out <span class="blsp-spelling-error" id="SPELLING_ERROR_30">to</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_31">be</span> a <span class="blsp-spelling-error" id="SPELLING_ERROR_32">very</span> bad <span class="blsp-spelling-error" id="SPELLING_ERROR_33">idea</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_34">if</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_35">you</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_36">work</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_37">with</span> different version of <span class="blsp-spelling-error" id="SPELLING_ERROR_38">Visual</span> Studio.<br />
<span class="blsp-spelling-error" id="SPELLING_ERROR_39">Because</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_40">like</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_41">any</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_42">real</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_43">programmer</span> I <span class="blsp-spelling-error" id="SPELLING_ERROR_44">hate</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_45">doing</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_46">repetitive</span> stuff, <span class="blsp-spelling-error" id="SPELLING_ERROR_47">here's</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_48">what</span> I <span class="blsp-spelling-error" id="SPELLING_ERROR_49">came</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_50">up</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_51">with</span>. Put a <span class="blsp-spelling-error" id="SPELLING_ERROR_52">shortcut</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_53">to</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_54">the</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_55">command</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_56">line</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_57">window</span> on desktop <span class="blsp-spelling-error" id="SPELLING_ERROR_58">and</span> open <span class="blsp-spelling-error" id="SPELLING_ERROR_59">properties</span>. <span class="blsp-spelling-error" id="SPELLING_ERROR_60">The</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_61">actual</span> program <span class="blsp-spelling-error" id="SPELLING_ERROR_62">called</span> is <span class="blsp-spelling-error" id="SPELLING_ERROR_63">found</span> in Target<br />
<br />
<span style="font-family: courier new;">C:\<span class="blsp-spelling-error" id="SPELLING_ERROR_64">Windows</span>\<span class="blsp-spelling-error" id="SPELLING_ERROR_65">System</span>32\<span class="blsp-spelling-error" id="SPELLING_ERROR_66">cmd</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_67">exe</span></span><br />
<br />
As <span class="blsp-spelling-error" id="SPELLING_ERROR_68">it</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_69">turns</span> out <span class="blsp-spelling-error" id="SPELLING_ERROR_70">cmd</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_71">has</span> a <span class="blsp-spelling-error" id="SPELLING_ERROR_72">nice</span> set of <span class="blsp-spelling-error" id="SPELLING_ERROR_73">command</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_74">line</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_75">switches</span> as <span class="blsp-spelling-error" id="SPELLING_ERROR_76">you</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_77">can</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_78">see</span> <a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/cmd.mspx?mfr=true">here</a> (<span class="blsp-spelling-error" id="SPELLING_ERROR_79">for</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_80">windows</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_81">XP</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_82">but</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_83">things</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_84">still</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_85">work</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_86">the</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_87">same</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_88">way</span> in <span class="blsp-spelling-error" id="SPELLING_ERROR_89">Windows</span>7). <span class="blsp-spelling-error" id="SPELLING_ERROR_90">So</span> I <span class="blsp-spelling-error" id="SPELLING_ERROR_91">altered</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_92">the</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_93">properties</span> of <span class="blsp-spelling-error" id="SPELLING_ERROR_94">my</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_95">shortcut</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_96">to</span><br />
<br />
<span style="font-family: courier new;">C:\<span class="blsp-spelling-error" id="SPELLING_ERROR_97">Windows</span>\<span class="blsp-spelling-error" id="SPELLING_ERROR_98">System</span>32\<span class="blsp-spelling-error" id="SPELLING_ERROR_99">cmd</span>.<span class="blsp-spelling-error" id="SPELLING_ERROR_100">exe</span> /k "%<span class="blsp-spelling-error" id="SPELLING_ERROR_101">VS</span>100<span class="blsp-spelling-error" id="SPELLING_ERROR_102">COMNTOOLS</span>%<span class="blsp-spelling-error" id="SPELLING_ERROR_103">vsvars</span>32.bat"</span><br />
<br />
<span class="blsp-spelling-error" id="SPELLING_ERROR_104">Which</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_105">gives</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_106">you</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_107">the</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_108">following</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_109">result</span><br />
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxNgpsej7lQs1JvXZSKF86pV4HHh-X6fUMvIPauNpECtwBtH5HARbvlFTYuY7JNHKTLo38loMlh-CcfcXMt3Upd1EogVdCPp3VIlhQxA_Y-x1CEdAigByQigUgEkeXnM_tD1koQI3ZA8s/s1600/cmd.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img alt="" border="0" id="BLOGGER_PHOTO_ID_5550832899700562290" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxNgpsej7lQs1JvXZSKF86pV4HHh-X6fUMvIPauNpECtwBtH5HARbvlFTYuY7JNHKTLo38loMlh-CcfcXMt3Upd1EogVdCPp3VIlhQxA_Y-x1CEdAigByQigUgEkeXnM_tD1koQI3ZA8s/s320/cmd.png" style="cursor: pointer; display: block; height: 282px; margin: 0px auto 10px; text-align: center; width: 547px;" /></a><br />
<br />
<span class="blsp-spelling-error" id="SPELLING_ERROR_110">If</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_111">you</span> set <span class="blsp-spelling-error" id="SPELLING_ERROR_112">the</span> 'Start in' <span class="blsp-spelling-error" id="SPELLING_ERROR_113">to</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_114">something</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_115">meaningful</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_116">for</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_117">you</span>, <span class="blsp-spelling-error" id="SPELLING_ERROR_118">you're</span> ready <span class="blsp-spelling-error" id="SPELLING_ERROR_119">for</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_120">take-off</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_121">with</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_122">no</span> <span class="blsp-spelling-error" id="SPELLING_ERROR_123">effort</span>!!!Kenny Knechthttp://www.blogger.com/profile/10864162727339330416noreply@blogger.com0tag:blogger.com,1999:blog-142822920647208418.post-55300082976192174282010-05-07T15:16:00.000+02:002010-05-07T15:38:41.156+02:00Visual Studio 2010 NoStepIntoTwo things have changed with the NoStepInto feature of the native C++ debugger in VS2010 compared to VS2008 (for a general intro see <a href="http://blogs.msdn.com/andypennell/archive/2004/02/06/69004.aspx">here</a>):<br /><ul><li>You don't have to put your rules in HKLM anymore: you might as well put them in HKCU (more precise in HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\NativeDE\StepOver), which is of course much better</li><li>If you put <span style="font-family: courier new;">=NoStepInto</span> things will no longer work: just leave it off.</li></ul>Some examples (as entered in RegEdit)<br /><ul><li>Name:<span style="font-family: courier new;">10</span>, Value: <span style="font-family: courier new;">boost\:\:shared_ptr.*</span></li><li>Name:<span style="font-family: courier new;">20</span>, Value: <span style="font-family: courier new;">std\:\:.*</span></li></ul><span style="font-family: courier new;"><span style="font-family: georgia;">Happy programming!</span><br /></span>Kenny Knechthttp://www.blogger.com/profile/10864162727339330416noreply@blogger.com3