Skip to content

Commit 6c832cd

Browse files
Info, 更新CMake下使用nuget方式引用VC-LTL的帮助
1 parent 618f796 commit 6c832cd

File tree

2 files changed

+251
-157
lines changed

2 files changed

+251
-157
lines changed

Readme.md

Lines changed: 122 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -106,99 +106,139 @@ later, even in the environment which installed no hotfixes.
106106
## 3. How to used?
107107
We will enter the theme, we have prepared a rich [VC-LTL Samples](https://github.com/Chuyu-Team/vc-ltl-samples) for your reference, and welcome to join our QQ group (633710173).
108108

109-
### 3.1. Using VC-LTL in Visual Studio
110-
111-
#### 3.1.1. Choose reference mode
112-
113-
##### 3.1.1.1. Reference via NuGet (recommend)
114-
115-
Right-click on the project and select "Manage NuGet Packages", then search for `VC-LTL` and choose the version that suits you, and finally click Install.
109+
### 3.1. Using VC-LTL in Visual Studio C++ Project
110+
1. Right-click on the project and select "Manage NuGet Packages". Search for `VC-LTL` and choose the version that suits you, and finally click Install.
111+
2. C/C++ - Code Generation -`Runtime Library` adjust to `Multi-threaded (/MT)`
112+
- For XP support, Right click on the project, Properties - NuGet Packages Settings - YY-Thunks - 最小兼容系统版本 - 5.1.2600.0.
113+
3. Rebuild the project
116114

117115
![InstallByNuGet](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/en/image/InstallByNuGet.png)
118116

119-
##### 3.1.1.2. Reference via Registry
120-
If you download and unzip [VC-LTL Binary](https://github.com/Chuyu-Team/VC-LTL5/releases/latest) to `D:\Src\VC-LTL`, please double-click `D:\Src\VC-LTL\Install.cmd`.
121-
122-
> The script will save the information in the registry `HKCU\Code\VC-LTL`.
123-
124-
Copy `VC-LTL helper for Visual Studio.props` to your project, then open the Property Manager ( View - Property Manager ) and right-click on the Release Configuration, click on `Add Existing Property Sheet...`, and finally select `VC-LTL helper for Visual Studio.props`.
125-
126-
![AddShared](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/en/image/AddShared.png)
127-
128-
#### 3.1.2. Configure Project Properties
129-
* C/C++ - Code Generation -`Runtime Library` adjust to `Multi-threaded (/MT)`
130-
131117
![ConfigurationProject](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/en/image/ConfigurationProject.png)
132118

133-
> For XP support, please Right click on the project, Properties - NuGet Packages Settings - VC-LTL - Target CRT version - "msvcrt 5.1.2600.0".
134-
In addition, it is recommended that you install YY-Thunks.
135-
136-
### 3.2. Using VC-LTL in CMake
137-
If you download and unzip [VC-LTL Binary](https://github.com/Chuyu-Team/VC-LTL5/releases/latest) to `D:\Src\VC-LTL`, please double-click `D:\Src\VC-LTL\Install.cmd`.
138-
139-
> The script will save the information in the registry `HKCU\Code\VC-LTL`.
140-
141-
#### 3.2.1. Add VC-LTL Module File
142-
143-
Copy `VC-LTL helper for cmake.cmake` to your project. Then add `include("VC-LTL helper for cmake.cmake")` to `CMakeLists.txt`.
144-
145-
**Example:**
146-
```
147-
cmake_minimum_required(VERSION 3.5.2)
148-
project(ltltest)
149-
150-
include("VC-LTL helper for cmake.cmake")
151-
152-
add_subdirectory(src)
153-
```
154-
155-
#### 3.2.2. Modify The Configuration
156-
157-
> It's recommended to use `/MT` to compile the project when using VC-LTL.
158-
For XP support, please modify `VC-LTL helper for cmake.cmake` to enable `set(WindowsTargetPlatformMinVersion "5.1.2600.0")`.
159-
In addition, it is recommended that you install YY-Thunks.
160-
161-
### 3.3. Using VC-LTL in NMake/CL
162-
163-
#### 3.3.1. Run VC-LTL Cmd Script
164-
If you download and unzip [VC-LTL Binary](https://github.com/Chuyu-Team/VC-LTL5/releases/latest) to `D:\Src\VC-LTL`, please double-click `D:\Src\VC-LTL\Install.cmd`.
165-
166-
> The script will save the information in the registry `HKCU\Code\VC-LTL`.
167-
168-
Copy `VC-LTL helper for nmake.cmd` to your project. Run `vcvars32.bat` or `vcvars64.bat` and execute this script. The script will automatically modify the `include` and `lib` environment variables.
169-
170-
**Example: cmd**
171-
```
172-
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
173-
call "D:\VC-LTL\VC-LTL helper for nmake.cmd"
174-
175-
nmake /f Test.mak
176-
```
177-
178-
**Example: powershell**
179-
```
180-
$BuiltInVsWhereExe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
181-
$LatestVisualStudioRoot = & $BuiltInVsWhereExe -latest -prerelease -property installationPath
182-
183-
# x86、amd64、arm、arm64
184-
& "$LatestVisualStudioRoot\Common7\Tools\Launch-VsDevShell.ps1" -arch x86
185-
& D:\VC-LTL\VC-LTL helper for nmake.ps1"
119+
![AppBuildByVC-LTL](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/image/AppWithLTL.png)
186120

187-
& nmake /f Test.mak
188-
```
121+
### 3.2. Using VC-LTL in Visual Studio .NET Native AOT Project
122+
1. `TargetFramework` property to add `Windows` system platform, e.g. `net8.0-windows` or `net9.0-windows`.
123+
2. Right-click on the project and select "Manage NuGet Packages". Search for `VC-LTL` and choose the version that suits you, and finally click Install.
124+
3. For XP support, please add project `WindowsSupportedOSPlatformVersion` = `5.1`, for example:
125+
```xml
126+
<Project Sdk="Microsoft.NET.Sdk">
127+
<PropertyGroup>
128+
<!-- ... -->
129+
<TargetFramework>net8.0-windows</TargetFramework>
130+
<SupportedOSPlatformVersion>5.1</SupportedOSPlatformVersion>
131+
<!-- ... -->
132+
</PropertyGroup>
133+
<!--...-->
134+
</Project>
135+
```
136+
4. Rebuild the project
189137

190-
#### 3.3.2. Modify The Configuration
138+
![InstallByNuGet](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/en/image/InstallByNuGet.png)
191139

192-
> It's recommended to use `/MT` to compile the project when using VC-LTL.
193-
For XP support, please modify `VC-LTL helper for nmake.cmd` to enable `set WindowsTargetPlatformMinVersion=5.1.2600.0`.
194-
In addition, it is recommended that you install YY-Thunks.
140+
![AppBuildByVC-LTL](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/image/AppWithLTL.png)
195141

196-
### 3.4. Rebuild
197-
Is the file size smaller? If you fail to compile, please refer to [4. FAQ](#4-faq). You can also feedback and work together to improve VC-LTL.
142+
### 3.3. Using VC-LTL in CMake
143+
1. Create file `Directory.Build.props` in source directory, and add the following code:
144+
```xml
145+
<?xml version="1.0" encoding="utf-8"?>
146+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
147+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
148+
<ProjectCapability Include="PackageReferences" />
149+
</ItemGroup>
150+
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
151+
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
152+
<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
153+
154+
<!--Turn on Windows XP support, and you can choose according to your situation.-->
155+
<WindowsTargetPlatformMinVersion>5.1.2600</WindowsTargetPlatformMinVersion>
156+
</PropertyGroup>
157+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
158+
<PackageReference Include="VC-LTL">
159+
<!--VC-LTL Version-->
160+
<Version>5.1.1</Version>
161+
</PackageReference>
162+
</ItemGroup>
163+
<!--从兼容性考虑,继续向上搜索 Directory.Build.props-->
164+
<PropertyGroup>
165+
<DirectoryBuildPropsPath>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</DirectoryBuildPropsPath>
166+
</PropertyGroup>
167+
<Import Project="$(DirectoryBuildPropsPath)" Condition="'$(DirectoryBuildPropsPath)' != ''"/>
168+
</Project>
169+
```
170+
2. Start Build, for example:
171+
```
172+
# The Gen parameter must be use `Visual Studio`, as Visual Studio only supports nuget.
173+
# Assuming that the output dir is `.build\x86-Release`, you can modify it as needed.
174+
cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=.\build\x86-Release .
175+
176+
# Note the `-- -r` at the end, which is the command to restore the nuget package.
177+
cmake --build .\build\x86-Release --config Release -- -r
178+
179+
cmake --install .\build\x86-Release --config Release
180+
```
181+
3. Rebuild the project
182+
183+
### 3.4. I don't want to use NuGet, how do I configure the project manually?
184+
#### 3.4.1. Using VC-LTL in Visual Studio C++ Project
185+
1. Download VC-LTL. If you download and unzip [VC-LTL Binary](https://github.com/Chuyu-Team/VC-LTL5/releases/latest) to `D:\Src\VC-LTL`, please double-click `D:\Src\VC-LTL\Install.cmd`.
186+
- The script will save the information in the registry `HKCU\Code\VC-LTL`.
187+
2. Add VC-LTL Module File. Copy `VC-LTL helper for Visual Studio.props` to your project, then open the Property Manager ( View - Property Manager ) and right-click on the Release Configuration, click on `Add Existing Property Sheet...`, and finally select `VC-LTL helper for Visual Studio.props`.
188+
3. Configure YY-Thunks according to the installation [YY-Thunks documentation](https://github.com/Chuyu-Team/YY-Thunks/blob/master/Readme.md).
189+
4. C/C++ - Code Generation -`Runtime Library` adjust to `Multi-threaded (/MT)`
190+
- For XP support, please Right click on the project, Properties - NuGet Packages Settings - YY-Thunks - 最小兼容系统版本 - 5.1.2600.0.
191+
5. Rebuild the project
198192

199-
> It is recommended to use `/MT` to compile when compiling with VC-LTL 5.0, and the dependent static libraries does not need to be recompiled.
193+
![AddShared](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/en/image/AddShared.png)
200194

201-
![AppBuildByVC-LTL](https://raw.githubusercontent.com/wiki/Chuyu-Team/VC-LTL/image/AppWithLTL.png)
195+
#### 3.4.2. Using VC-LTL in CMake
196+
1. Download VC-LTL. If you download and unzip [VC-LTL Binary](https://github.com/Chuyu-Team/VC-LTL5/releases/latest) to `D:\Src\VC-LTL`, please double-click `D:\Src\VC-LTL\Install.cmd`.
197+
- The script will save the information in the registry `HKCU\Code\VC-LTL`.
198+
2. Add VC-LTL Module File. Copy `VC-LTL helper for cmake.cmake` to your project. Then add `include("VC-LTL helper for cmake.cmake")` to `CMakeLists.txt`.
199+
200+
**Example:**
201+
```
202+
cmake_minimum_required(VERSION 3.5.2)
203+
project(ltltest)
204+
205+
include("VC-LTL helper for cmake.cmake")
206+
207+
add_subdirectory(src)
208+
```
209+
3. Configure YY-Thunks according to the installation [YY-Thunks documentation](https://github.com/Chuyu-Team/YY-Thunks/blob/master/Readme.md).
210+
4. Recommended to use `/MT` to compile the project when using VC-LTL.
211+
- For XP support, please modify `VC-LTL helper for cmake.cmake` to enable `set(WindowsTargetPlatformMinVersion "5.1.2600.0")`.
212+
5. Rebuild the project
213+
214+
#### 3.4.3. Using VC-LTL in NMake/CL
215+
1. Download VC-LTL. If you download and unzip [VC-LTL Binary](https://github.com/Chuyu-Team/VC-LTL5/releases/latest) to `D:\Src\VC-LTL`, please double-click `D:\Src\VC-LTL\Install.cmd`.
216+
- The script will save the information in the registry `HKCU\Code\VC-LTL`.
217+
2. Configure YY-Thunks according to the installation [YY-Thunks documentation](https://github.com/Chuyu-Team/YY-Thunks/blob/master/Readme.md).
218+
3. Copy `VC-LTL helper for nmake.cmd` to your project. Run `vcvars32.bat` or `vcvars64.bat` and execute this script. The script will automatically modify the `include` and `lib` environment variables.
219+
220+
**Example: cmd**
221+
```
222+
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
223+
call "D:\VC-LTL\VC-LTL helper for nmake.cmd"
224+
225+
nmake /f Test.mak
226+
```
227+
228+
**Example: powershell**
229+
```
230+
$BuiltInVsWhereExe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
231+
$LatestVisualStudioRoot = & $BuiltInVsWhereExe -latest -prerelease -property installationPath
232+
233+
# x86、amd64、arm、arm64
234+
& "$LatestVisualStudioRoot\Common7\Tools\Launch-VsDevShell.ps1" -arch x86
235+
& D:\VC-LTL\VC-LTL helper for nmake.ps1"
236+
237+
& nmake /f Test.mak
238+
```
239+
4. Recommended to use `/MT` to compile the project when using VC-LTL.
240+
- For XP support, please modify `VC-LTL helper for nmake.cmd` to enable `set WindowsTargetPlatformMinVersion=5.1.2600.0`.
241+
5. Rebuild the project
202242

203243
## 4. FAQ
204244
### 4.1. 未共享到msvcrt.dll/ucrtbase.dll

0 commit comments

Comments
 (0)