Creating a Visual Studio property sheet to ease the use of a C++ library
c++, libraries, visual-c++, visual-studio, visual-studio-2012
Solution
You can just install your library binaries in a structure such as:
<toplevelsdkdir>
|-> lib
|-> x86
|-> Debug
|-> Release
|-> x64
|-> Debug
|-> Release
And then just create a single project-wide props file like this:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_PropertySheetDisplayName>MyCPPLib, 1.0</_PropertySheetDisplayName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$INCLUDEPATH;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(AdditionalLibraryDirectories);$LIBPATH\$(PlatformTarget)\$(Configuration)</AdditionalLibraryDirectories>
<AdditionalDependencies>MyCPPLib.lib;$(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
If you can want you can replace the variables INCLUDEPATH and LIBPATH with information read from the registry (where you can put it during installation):
<ClCompile>
<AdditionalIncludeDirectories>$([MSBuild]::GetRegistryValue(`HKEY_LOCAL_MACHINE\Software\MyCompany\MySDK\v1`, `InstallDir`))\INCLUDE;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
Problem
I am building a C++ library (set of headers, import libs and DLLs). I want to make using this library as easy as possible for any developer who wants to use it. Especially I don't want the consumers of this library to have to worry about changing the header paths, libraries paths and link libraries manually for all the different configurations of their project (Debug|Release and x86/x64/ARM). I know that I can do this using property sheets. I created 6 different property sheets for this purpose (one for each configuration). Each sheet looks like the below (listing just the x86|Debug version, assume that the macros INCLUDEPATH and LIBPATH are correctly defined): ``` <?xml version="1.0" encoding="utf-8"?> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <_PropertySheetDisplayName>MyCPPLib, 1.0</_PropertySheetDisplayName> </PropertyGroup> <ItemDefinitionGroup> <ClCompile> <AdditionalIncludeDirectories>$INCLUDEPATH;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> <AdditionalLibraryDirectories>$(AdditionalLibraryDirectories);$LIBPATH\x86\Debug</AdditionalLibraryDirectories> <AdditionalDependencies>MyCPPLib.lib;$(AdditionalDependencies)</AdditionalDependencies> </Link> </ItemDefinitionGroup> </Project> ``` I want to know if it possible to create just a single props file that can take care of all 6 configurations based on whatever is the user's active configuration? How would that file look like?