CMakeLists.txt

PowerShell

开发常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 查看,需要修改 D:\file
ls # 当前目录下所有
ls "D:\file" -r # 特定目录下的文件和子目录
ls "D:\file" -fi # 查看特定目录下的文件
ls "D:\file" -di # 查看特定目录下的子目录
ls "D:\file" -fi "*.cpp" # 通配符查找特定目录下的文件

# 删除,需要修改 D:\file
ri .\file\ -r -fo # 强制删除所有子项
rm .\file\* -in *.tmp -Recurse # 删除 *.tmp 的文件,视情况修改条件
rm .\file\* -ex *.tmp -Recurse # 保留 *.tmp 的文件,视情况修改条件
rm .\file -r -wi # 预览将要执行的删除操作效果

# 创建
ni .\folder -t d # 需要修改 folder
ni "D:\file\project" -t f # 需要修改 D:\file\projec

# 导航,需要修改 file
cd file

# 显示当前目录
pwd

# 清屏
cls

# 编译
cmake .. -G "Visual Studio 17 2022" # 以 VS2022 进行编译,视情况修改引号中的内容
cmake .. -G "Visual Studio 17 2022" # 若省略 -A 参数,默认生成 32 位
cmake .. -G "Visual Studio 17 2022" -A x64 # 生成 64 位

# Debug 模式
cmake --build . --config Debug

# Release 模式
cmake --build . --config Release

# 检查文件是否存在,需修改 path
Test-Path -Path <path>

检查缺失文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 项目根目录(根据实际情况修改)
$projectRoot = "D:\CocosProjects\MyCardGameClean"

# CMakeLists.txt 路径(你可以根据实际修改)
$cmakeFile = Join-Path $projectRoot "CMakeLists.txt"

# 读取 CMakeLists.txt 文件内容
$content = Get-Content $cmakeFile

# 正则匹配所有可能的 .cpp 文件路径(简单匹配以 .cpp 结尾的字符串)
# 这里假设文件路径写在双引号内或直接写,且包含 'Classes/' 或 'src/' 目录
# 你可以根据实际格式微调正则
$pattern = '(Classes[^\s"\)]+\.cpp)|(src[^\s"\)]+\.cpp)'

# 找到所有匹配的文件路径(相对路径)
$matches = [regex]::Matches($content, $pattern)

# 去重,避免重复检查
$filePaths = $matches | ForEach-Object { $_.Groups[1].Value } | Select-Object -Unique

# 检查每个文件是否存在
foreach ($filePath in $filePaths) {
if (-not [string]::IsNullOrEmpty($filePath)) {
$fullPath = Join-Path $projectRoot $filePath
if (-Not (Test-Path $fullPath)) {
Write-Output "缺失文件: $filePath"
}
}
}

Write-Output "检查完成。"

如何使用?

  1. 打开 PowerShell

  2. 使用 cd 命令导航到脚本所在的目录。例如,如果脚本保存在桌面,可以执行:

    1
    cd ~/Desktop
  3. 运行脚本:

    1
    .\check_files.ps1 # 脚本文件名

如果遇到权限问题,可能需要临时启用脚本执行:

  1. 打开 PowerShell,以管理员权限运行:

    1
    Set-ExecutionPolicy RemoteSigned -Scope Process
  2. 再次运行脚本