CMake构建学习笔记22-libxml2库的构建

在上一篇文章《CMake构建学习笔记21-通用的CMake构建脚本》中,笔者封装了一个通用的cmake构建脚本cmake-build.ps1,那么这里笔者就尝试通过这个脚本来构建libxml2库。

libxml2是GNOME项目下的XML库,虽然比不上TinyXML-2轻量,但是胜在功能全面。这里就直接列出构建libxml2的脚本:

param(         [string]$Name = "libxml2-v2.14.4",     [string]$SourceDir = "../Source",     [string]$Generator,     [string]$InstallDir,       [string]$SymbolDir  )  # 根据 $Name 动态构建路径 $zipFilePath = Join-Path -Path $SourceDir -ChildPath "$Name.zip" $SourcePath = Join-Path -Path $SourceDir -ChildPath $Name $BuildDir = Join-Path -Path "." -ChildPath $Name  # 解压ZIP文件到指定目录 if (!(Test-Path $SourcePath)) {     Expand-Archive -LiteralPath $zipFilePath -DestinationPath $SourceDir -Force }  # 检查目标文件是否存在,以判断是否安装 $DstFilePath = "$InstallDir/bin/libxml2.dll" if (Test-Path $DstFilePath) {     Write-Output "The current library has been installed."     exit 1 }   # 复制符号库 $PdbFiles = @(     "$BuildDir/RelWithDebInfo/libxml2.pdb" )   # 额外构建参数 $CMakeCacheVariables = @{     BUILD_SHARED_LIBS = "ON"     LIBXML2_WITH_ZLIB = "ON"     LIBXML2_WITH_ICONV = "ON"     LIBXML2_WITH_HTTP = "ON" }  # 调用通用构建脚本 . ./cmake-build.ps1 -SourceLocalPath $SourcePath `     -BuildDir $BuildDir `     -Generator $Generator `     -InstallDir $InstallDir `     -SymbolDir $SymbolDir `     -PdbFiles $PdbFiles `     -CMakeCacheVariables $CMakeCacheVariables `     -MultiConfig $true  

这段脚本实现了解压源代码文件,判断是否已安装、复制符号库、额外构建参数。最后再执行cmake-build.ps1脚本。有的步骤如何不需要可以省略,不过额外构建参数还是需要关心一下,比如LIBXML2_WITH_ZLIB表示使用依赖库zlib参与构建(参看《CMake构建学习笔记2-zlib库的构建》);LIBXML2_WITH_ICONV,表示使用依赖库iconv参与构建(参看《CMake构建学习笔记20-iconv库的构建》)。

在PowerShell中使用如下指令进行构建:

./libxml2.ps1 -Generator "Visual Studio 16 2019" ` -InstallDir "$env:eGova3rdParty" ` -SymbolDir "$env:eGova3rdParty/symbols" ` 

构建代码项目

发表评论

评论已关闭。

相关文章