Thursday, 31 March 2016

Vulkan, first steps 02: Visual Studio Project Properties

I have decided to create a Visual Studio solution with API samples from Lunar's Vulkan SDK recoded to use nVidia's Open-Source Vulkan C++ API. But for each project in the solution, I have to add: paths for Vulkan SDK, tools and libraries from it. Doing it by hand would be tedious. It is a place, where project properties come in handy! The solution presented below is inspired by "Sharing project properties in Visual C++" post.

List of all Vulkan tutorial posts is here.

In solution's directory, I have created vulkan.props file intended for storing all changes in project properties corresponding to using Vulkan SDK. Setting include directory and the additional link-time library was easy because these are shared among all configurations. But libraries directory is different for Win32 and x64 builds. There I had to use a choose construct with proper condition. The whole file is presented below.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  
  <Choose>
    <When Condition="'$(Platform)'!='x64'">
      <PropertyGroup Label="UserMacros">
        <VULKAN_BIN_DIR>$(VULKAN_SDK)\Bin32</VULKAN_BIN_DIR>
      </PropertyGroup>
    </When>
    <Otherwise>
      <PropertyGroup Label="UserMacros">
        <VULKAN_BIN_DIR>$(VULKAN_SDK)\Bin</VULKAN_BIN_DIR>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup>
    <IncludePath>$(VULKAN_SDK)\Include;$(IncludePath)</IncludePath>
    <LibraryPath>$(VULKAN_BIN_DIR);$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup>
    <Link>
      <AdditionalDependencies>vulkan-1.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <BuildMacro Include="VULKAN_BIN_DIR">
      <Value>$(VULKAN_BIN_DIR)</Value>
      <EnvironmentVariable>true</EnvironmentVariable>
    </BuildMacro>
  </ItemGroup>
</Project>


The $(VULKAN_SDK) is a system variable created by Vulkan SDK installer. Now, to reference Vulkan SDK I have only to add vulkan.props property file to each project once. Thanks to the choose construct my property file is working in all project configurations.

No comments:

Post a Comment