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?
To create a static library project in Visual Studio On the menu bar, choose File > New > Project to open the Create a New Project dialog. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.
right click on the project that you want to add a . props file for and choose "Add Existing Property Sheet". You can also choose to add a new property sheet.
A property sheet is a window that allows the user to view and edit the properties of an item. For example, a spreadsheet application can use a property sheet to allow the user to set the font and border properties of a cell or to view and set the properties of a device, such as a disk drive, printer, or mouse.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With