Skip to content

Commit

Permalink
[vcpkg] Repair msbuild damage and workaround the way we integrate on …
Browse files Browse the repository at this point in the history
…VS2015. (#19767)

* Repair msbuild damage and workaround the way we integrate on VS2015.

This is a fix for a pile of issues discovered by #18906

* VS 2015 has a bug that the <VcpkgInstalledDir Condition="!$(VcpkgInstalledDir.EndsWith('\'))">$(VcpkgInstalledDir)\</VcpkgInstalledDir> dance we do to get a trailing slash is not applied correctly when VcpkgInstalledDir was edited in the same property group attempting to add the trailing slash.
* We need a trailing slash on VcpkgInstalledDir at all times, but #16173 damaged this by removing it from TreatAsLocalProperty. Add the right TreatAsLocalPropertys back. Add all such slash defenses to the top of the file just beneath, eliminating need to call Path::Combine and friends by following msbuild "directory properties have a trailing slash" convention.
* Move VcpkgOSTarget and VcpkgPlatformTarget into the .targets, as they aren't intended to be overridable by users and don't appear in our selection dialog box(es).
* Don't bother avoiding setting vcpkg properties when VcpkgEnabled is off; after all, VcpkgEnabled is itself a vcpkg property :). I left attempts to skip creating items since creating items can hit the disk.
* Add _Z to several internal msbuild variables.
* Move VcpkgApplocalDeps to the .props since it's a user setting.
* Don't unconditionally use $(TLogLocation) because it is not set on 2015, and also it's per-project.
* Fixed typo in docs "VcpkgInstalledDirectory", and document the limitation that it doesn't work in 2015.
* In manifest mode, put the installed tree in a subdirectory including the triplet to make changing configurations faster.

Known limitations:

* If you change vcpkg.json without changing any .cpp files, we don't rebuild the dependencies even though we should. I don't know how to fix this but it doesn't appear to be a regression.

* Fix .tlog handling.

* Further defend against modified properties on VS2015.

* Document more VS2015 limitations.

* Remove TreatAsLocalProperty comment.
  • Loading branch information
BillyONeal authored Sep 2, 2021
1 parent 7734e8b commit 97e7ac8
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 83 deletions.
18 changes: 15 additions & 3 deletions docs/users/manifests.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ See the `--feature-flags=` command line option for more information.
## MSBuild Integration

To use manifests with MSBuild, first you need to use an [existing integration method](integration.md#with-msbuild).
Then, simply add a vcpkg.json above your project file (such as in the root of your source repository) and set the
Then, add a vcpkg.json above your project file (such as in the root of your source repository) and set the
property `VcpkgEnableManifest` to `true`. You can set this property via the IDE in `Project Properties -> Vcpkg -> Use
Vcpkg Manifest`.

Expand All @@ -453,9 +453,21 @@ Note: It is critical that all project files in a single build consuming the same
you need to use different triplets for different projects in your solution, they must consume from different
`vcpkg.json` files.

### Known issues

* Visual Studio 2015 does not correctly track edits to the `vcpkg.json` and `vcpkg-configuration.json` files, and will
not respond to changes unless a `.cpp` is edited.

### MSBuild Properties

These properties can be defined via the VS GUI under `Project Properties -> Vcpkg` or via a common `.props` file.
When using Visual Studio 2015 integration, these properties can be set in your project file before the

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

line, which unfortunately requires manual editing of the `.vcxproj` or passing on the msbuild command line with `/p:`.
With 2017 or later integration, These properties can additionally be set via the Visual Studio GUI under
`Project Properties -> Vcpkg` or via a common `.props` file imported between `Microsoft.Cpp.props` and
`Microsoft.Cpp.targets`.

#### `VcpkgEnabled` (Use Vcpkg)

Expand Down Expand Up @@ -495,7 +507,7 @@ vcpkg.json files will be ignored. This will default to true in the future.
This property can be set to "false" to disable automatic dependency restoration on project build. Dependencies can be
manually restored via the vcpkg command line.

#### `VcpkgInstalledDirectory` (Installed Directory)
#### `VcpkgInstalledDir` (Installed Directory)

This property defines the location where headers and binaries are consumed from. In manifest mode, this directory is
created and populated based on your manifest.
17 changes: 2 additions & 15 deletions scripts/buildsystems/msbuild/vcpkg.props
Original file line number Diff line number Diff line change
@@ -1,34 +1,21 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Do not define derived properties here. This file may be imported once and some of the properties below may be overridden afterwards -->

<!-- Set default OS Target-->
<PropertyGroup Condition="'$(VcpkgOSTarget)' == ''">
<VcpkgOSTarget>windows</VcpkgOSTarget>
<VcpkgOSTarget Condition="'$(AppContainerApplication)' == 'true'">uwp</VcpkgOSTarget>
</PropertyGroup>

<!-- Set default Platform Target. $(PlatformTarget) is not available at the top of the .vcxproj file. -->
<PropertyGroup Condition="'$(VcpkgPlatformTarget)' == ''">
<VcpkgPlatformTarget>$(Platform)</VcpkgPlatformTarget>
<VcpkgPlatformTarget Condition="'$(Platform)' == 'Win32'">x86</VcpkgPlatformTarget>
</PropertyGroup>

<PropertyGroup>
<VcpkgPropsImported>true</VcpkgPropsImported>
<VcpkgEnabled Condition="'$(VcpkgEnabled)' == ''">true</VcpkgEnabled>
<VcpkgConfiguration Condition="'$(VcpkgConfiguration)' == ''">$(Configuration)</VcpkgConfiguration>
<VcpkgUseStatic Condition="'$(VcpkgUseStatic)' == ''">false</VcpkgUseStatic>
<VcpkgRoot Condition="'$(VcpkgRoot)' == ''">$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), '..\..\..'))</VcpkgRoot>
<VcpkgRoot Condition="'$(VcpkgRoot)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\..'))</VcpkgRoot>

<VcpkgAutoLink Condition="'$(VcpkgAutoLink)' == ''">true</VcpkgAutoLink>
<!-- Deactivate Autolinking if lld is used as a linker. (Until a better way to solve the problem is found!).
Tried to add /lib as a parameter to the linker call but was unable to find a way to pass it as the first parameter. -->
<VcpkgAutoLink Condition="'$(UseLldLink)' == 'true'">false</VcpkgAutoLink>
<VcpkgApplocalDeps Condition="'$(VcpkgApplocalDeps)' == ''">true</VcpkgApplocalDeps>

<!-- Manifest files -->
<VcpkgEnableManifest Condition="'$(VcpkgEnableManifest)' == ''">false</VcpkgEnableManifest>
<VcpkgManifestInstall Condition="'$(VcpkgManifestInstall)' == ''">true</VcpkgManifestInstall>
<VcpkgManifestRoot Condition="'$(VcpkgManifestRoot)' == ''">$([MSbuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), vcpkg.json))</VcpkgManifestRoot>
</PropertyGroup>

</Project>
Loading

0 comments on commit 97e7ac8

Please sign in to comment.