Skip to content

Commit 6c1f9c2

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

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

Readme.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,52 @@ Copy `VC-LTL helper for Visual Studio.props` to your project, then open the Prop
134134
In addition, it is recommended that you install YY-Thunks.
135135

136136
### 3.2. Using VC-LTL in CMake
137+
#### 3.2.1. Reference via NuGet (recommend)
138+
##### 3.2.1.1. Create `Directory.Build.props` in source directory
139+
```xml
140+
<?xml version="1.0" encoding="utf-8"?>
141+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
142+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
143+
<ProjectCapability Include="PackageReferences" />
144+
</ItemGroup>
145+
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
146+
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
147+
<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
148+
149+
<!--Turn on Windows XP support, and you can choose according to your situation.-->
150+
<WindowsTargetPlatformMinVersion>5.1.2600</WindowsTargetPlatformMinVersion>
151+
</PropertyGroup>
152+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
153+
<PackageReference Include="VC-LTL">
154+
<!--VC-LTL Version-->
155+
<Version>5.1.1</Version>
156+
</PackageReference>
157+
</ItemGroup>
158+
<!--从兼容性考虑,继续向上搜索 Directory.Build.props-->
159+
<PropertyGroup>
160+
<DirectoryBuildPropsPath>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</DirectoryBuildPropsPath>
161+
</PropertyGroup>
162+
<Import Project="$(DirectoryBuildPropsPath)" Condition="'$(DirectoryBuildPropsPath)' != ''"/>
163+
</Project>
164+
```
165+
##### 3.2.1.2. Start Build
166+
```
167+
# The Gen parameter must be use `Visual Studio`, as Visual Studio only supports nuget.
168+
# Assuming that the output dir is `.build\x86-Release`, you can modify it as needed.
169+
cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=.\build\x86-Release .
170+
171+
# Note the `-- -r` at the end, which is the command to restore the nuget package.
172+
cmake --build .\build\x86-Release --config Release -- -r
173+
174+
cmake --install .\build\x86-Release --config Release
175+
```
176+
177+
#### 3.2.2. Manual
137178
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`.
138179

139180
> The script will save the information in the registry `HKCU\Code\VC-LTL`.
140181
141-
#### 3.2.1. Add VC-LTL Module File
182+
#### 3.2.2.1. Add VC-LTL Module File
142183

143184
Copy `VC-LTL helper for cmake.cmake` to your project. Then add `include("VC-LTL helper for cmake.cmake")` to `CMakeLists.txt`.
144185

@@ -152,7 +193,7 @@ include("VC-LTL helper for cmake.cmake")
152193
add_subdirectory(src)
153194
```
154195

155-
#### 3.2.2. Modify The Configuration
196+
#### 3.2.2.2. Modify The Configuration
156197

157198
> It's recommended to use `/MT` to compile the project when using VC-LTL.
158199
For XP support, please modify `VC-LTL helper for cmake.cmake` to enable `set(WindowsTargetPlatformMinVersion "5.1.2600.0")`.

Readme.osc.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,52 @@ VC-LTL 5.0开始,ABI与微软原版`兼容`,您可以直接使用现有的
125125
> 建议使用`/MT`编译代码。如需支持XP,请右键项目 - 属性 - NuGet程序包设置 - VC-LTL - 目标CRT版本 -`msvcrt 5.1.2600.0`,除此之外建议您安装YY-Thunks。
126126
127127
### 3.2. 在CMake中使用VC-LTL
128+
#### 3.2.1. 通过NuGet引用(推荐)
129+
##### 3.2.1.1. 在代码根目录创建`Directory.Build.props`
130+
```xml
131+
<?xml version="1.0" encoding="utf-8"?>
132+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
133+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
134+
<ProjectCapability Include="PackageReferences" />
135+
</ItemGroup>
136+
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
137+
<NuGetTargetMoniker Condition="'$(NuGetTargetMoniker)' == ''">native,Version=v0.0</NuGetTargetMoniker>
138+
<RuntimeIdentifiers Condition="'$(RuntimeIdentifiers)' == ''">win;win-x86;win-x64;win-arm;win-arm64</RuntimeIdentifiers>
139+
140+
<!--将项目最小支持到Windows XP,可根据自己的情况设置-->
141+
<WindowsTargetPlatformMinVersion>5.1.2600</WindowsTargetPlatformMinVersion>
142+
</PropertyGroup>
143+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.vcxproj'">
144+
<PackageReference Include="VC-LTL">
145+
<!--根据自己的情况选择VC-LTL版本-->
146+
<Version>5.1.1</Version>
147+
</PackageReference>
148+
</ItemGroup>
149+
<!--从兼容性考虑,继续向上搜索 Directory.Build.props-->
150+
<PropertyGroup>
151+
<DirectoryBuildPropsPath>$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))</DirectoryBuildPropsPath>
152+
</PropertyGroup>
153+
<Import Project="$(DirectoryBuildPropsPath)" Condition="'$(DirectoryBuildPropsPath)' != ''"/>
154+
</Project>
155+
```
156+
##### 3.2.1.2. 启动编译过程
157+
```
158+
# Gen必须选择Visual Studio系列,因为Visual Studio才支持nuget。
159+
# 假设输出目录为build\x86-Release,自己可根据情况修改。
160+
cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_CONFIGURATION_TYPES:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=.\build\x86-Release .
161+
162+
# 注意尾部的 `-- -r`,该命令是还原nuget包,此时会自动下载VC-LTL,并且配置到工程。
163+
cmake --build .\build\x86-Release --config Release -- -r
164+
165+
cmake --install .\build\x86-Release --config Release
166+
```
128167

168+
#### 3.2.2. 手工配置
129169
假如,你将[VC-LTL Binary](https://github.com/Chuyu-Team/VC-LTL5/releases/latest)下载并解压至`D:\Src\VC-LTL`(具体位置无任何要求),双击`D:\Src\VC-LTL\Install.cmd`即可。
130170

131171
> 脚本会在`HKCU\Code\VC-LTL`创建注册表。
132172
133-
#### 3.2.1. 添加VC-LTL配置文件
173+
#### 3.2.2.1. 添加VC-LTL配置文件
134174

135175
将模块文件`VC-LTL helper for cmake.cmake`复制到你的工程目录(顶层CMakeLists.txt同级目录)。然后在`CMakeLists.txt`中添加一行 `include("VC-LTL helper for cmake.cmake")` 即可。
136176

@@ -144,7 +184,7 @@ include("VC-LTL helper for cmake.cmake")
144184
add_subdirectory(src)
145185
```
146186

147-
#### 3.2.2. 调整配置工程
187+
#### 3.2.2.2. 调整配置工程
148188

149189
> 建议使用`/MT`编译代码。如需支持XP,请修改`VC-LTL helper for cmake.cmake`启用 `set(WindowsTargetPlatformMinVersion "5.1.2600.0")`,除此之外建议您安装YY-Thunks。
150190

0 commit comments

Comments
 (0)