77 [string ]$Config = " develop"
88)
99
10- $ErrorActionPreference = " Stop"
11-
12- # Function to read INI configuration file
13- function Get-IniConfig {
14- param (
15- [string ]$FilePath
16- )
17-
18- $config = @ {}
19- $currentSection = " "
20-
21- if (Test-Path $FilePath ) {
22- Get-Content $FilePath | ForEach-Object {
23- $line = $_.Trim ()
24-
25- # Skip empty lines and comments
26- if ([string ]::IsNullOrEmpty($line ) -or $line.StartsWith (" #" ) -or $line.StartsWith (" ;" )) {
27- return
28- }
29-
30- # Section header
31- if ($line -match ' ^\[([^\]]+)\]$' ) {
32- $currentSection = $matches [1 ]
33- if (-not $config.ContainsKey ($currentSection )) {
34- $config [$currentSection ] = @ {}
35- }
36- return
37- }
38-
39- # Key=value pair
40- if ($line -match ' ^([^=]+)=(.*)$' ) {
41- $key = $matches [1 ].Trim()
42- $value = $matches [2 ].Trim()
43-
44- if ($currentSection -and $config.ContainsKey ($currentSection )) {
45- $config [$currentSection ][$key ] = $value
46- }
47- }
48- }
49- }
50- else {
51- throw " Configuration file not found: $FilePath "
52- }
10+ # 导入库模块
11+ $LibDir = Join-Path (Split-Path - Parent $PSScriptRoot ) " lib\powershell"
12+ Import-Module (Join-Path $LibDir " LibCommon.psm1" ) - Force
13+ Import-Module (Join-Path $LibDir " LibConfig.psm1" ) - Force
14+ Import-Module (Join-Path $LibDir " LibPaths.psm1" ) - Force
5315
54- return $config
55- }
16+ $ErrorActionPreference = " Stop"
5617
57- # Log function
58- function Write-Log {
59- param (
60- [string ]$Message ,
61- [string ]$Level = " INFO"
62- )
63- $timestamp = Get-Date - Format " yyyy-MM-dd HH:mm:ss"
64- $color = switch ($Level ) {
65- " INFO" { " Cyan" }
66- " SUCCESS" { " Green" }
67- " WARNING" { " Yellow" }
68- " ERROR" { " Red" }
69- default { " White" }
70- }
71- Write-Host " [$timestamp ] [$Level ] $Message " - ForegroundColor $color
72- }
18+ Write-LogSeparator
19+ Write-LogInfo " Starting Windows CMake Configuration"
20+ Write-LogInfo " Configuration: $Config "
21+ Write-LogSeparator
7322
74- Write-Log " ========================================" " INFO"
75- Write-Log " Starting Windows CMake Configuration" " INFO"
76- Write-Log " Configuration: $Config " " INFO"
77- Write-Log " ========================================" " INFO"
23+ # Set caller's PSScriptRoot for module functions to access
24+ $global :CallerPSScriptRoot = $PSScriptRoot
25+ $global :CallerMyInvocationPath = $MyInvocation.MyCommand.Path
7826
79- # Get the script directory and project root
80- $ScriptDir = Split-Path - Parent $MyInvocation .MyCommand.Path
81- $ProjectRoot = Split-Path - Parent ( Split-Path - Parent $ScriptDir )
27+ # Get the script directory and project root using library functions
28+ $ScriptDir = Get-ScriptDir
29+ $ProjectRoot = Get-ProjectRoot
8230
83- Write-Log " Project root: $ProjectRoot " " INFO "
84- Write-Log " Changing to project directory" " INFO "
31+ Write-LogInfo " Project root: $ProjectRoot "
32+ Write-LogInfo " Changing to project directory"
8533
8634Set-Location $ProjectRoot
8735
@@ -93,14 +41,14 @@ else {
9341 $ConfigFile = Join-Path $ScriptDir " build_develop_config.ini"
9442}
9543
96- Write-Log " Loading configuration from: $ConfigFile " " INFO "
44+ Write-LogInfo " Loading configuration from: $ConfigFile "
9745
9846try {
9947 $ConfigData = Get-IniConfig - FilePath $ConfigFile
100- Write-Log " Configuration loaded successfully!" " SUCCESS "
48+ Write-LogSuccess " Configuration loaded successfully!"
10149}
10250catch {
103- Write-Log " Failed to load configuration: $_ " " ERROR "
51+ Write-LogError " Failed to load configuration: $_ "
10452 exit 1
10553}
10654
@@ -109,14 +57,14 @@ $Generator = $ConfigData["cmake"]["generator"]
10957$Toolchain = $ConfigData [" cmake" ][" toolchain" ]
11058$BuildType = $ConfigData [" cmake" ][" build_type" ]
11159if (-not $BuildType ) {
112- Write-Log " ERROR: build_type not specified in config file" " ERROR "
60+ Write-LogError " ERROR: build_type not specified in config file"
11361 exit 1
11462}
11563
11664# Validate BuildType value
11765$ValidBuildTypes = @ (" Debug" , " Release" , " RelWithDebInfo" )
11866if ($BuildType -notin $ValidBuildTypes ) {
119- Write-Log " ERROR: Invalid build_type '$BuildType '. Must be one of: $ ( $ValidBuildTypes -join ' , ' ) " " ERROR "
67+ Write-LogError " ERROR: Invalid build_type '$BuildType '. Must be one of: $ ( $ValidBuildTypes -join ' , ' ) "
12068 exit 1
12169}
12270
@@ -135,17 +83,17 @@ else {
13583 }
13684}
13785
138- Write-Log " Generator: $Generator " " INFO "
139- Write-Log " Toolchain: $Toolchain " " INFO "
140- Write-Log " Build Type: $BuildType " " INFO "
141- Write-Log " Source directory: $SourceDir (resolved: $ResolvedSourceDir )" " INFO "
142- Write-Log " Build directory: $BuildDir " " INFO "
86+ Write-LogInfo " Generator: $Generator "
87+ Write-LogInfo " Toolchain: $Toolchain "
88+ Write-LogInfo " Build Type: $BuildType "
89+ Write-LogInfo " Source directory: $SourceDir (resolved: $ResolvedSourceDir )"
90+ Write-LogInfo " Build directory: $BuildDir "
14391
14492# Configure with CMake
145- Write-Log " ======================================== " " INFO "
146- Write-Log " Configuring with CMake (NO BUILD)" " INFO "
147- Write-Log " Command: cmake -G $Generator -DUSE_TOOLCHAIN=$Toolchain -DCMAKE_BUILD_TYPE=$BuildType -S $ResolvedSourceDir -B $BuildDir " " INFO "
148- Write-Log " ======================================== " " INFO "
93+ Write-LogSeparator
94+ Write-LogInfo " Configuring with CMake (NO BUILD)"
95+ Write-LogInfo " Command: cmake -G $Generator -DUSE_TOOLCHAIN=$Toolchain -DCMAKE_BUILD_TYPE=$BuildType -S $ResolvedSourceDir -B $BuildDir "
96+ Write-LogSeparator
14997
15098$cmakeConfigArgs = @ (
15199 " -G" , $Generator ,
@@ -158,17 +106,17 @@ $cmakeConfigArgs = @(
158106try {
159107 & cmake @cmakeConfigArgs
160108 if ($LASTEXITCODE -eq 0 ) {
161- Write-Log " ======================================== " " INFO "
162- Write-Log " CMake configuration completed successfully!" " SUCCESS "
163- Write-Log " To build the project, run: cmake --build $BuildDir " " INFO "
164- Write-Log " ======================================== " " INFO "
109+ Write-LogSeparator
110+ Write-LogSuccess " CMake configuration completed successfully!"
111+ Write-LogInfo " To build the project, run: cmake --build $BuildDir "
112+ Write-LogSeparator
165113 }
166114 else {
167- Write-Log " CMake configuration failed with exit code: $LASTEXITCODE " " ERROR "
115+ Write-LogError " CMake configuration failed with exit code: $LASTEXITCODE "
168116 exit $LASTEXITCODE
169117 }
170118}
171119catch {
172- Write-Log " Error during CMake configuration: $_ " " ERROR "
120+ Write-LogError " Error during CMake configuration: $_ "
173121 exit 1
174122}
0 commit comments