windows-make: 处理构建 Windows 平台的历史与保留脚本内容,并支持定制模板

This commit is contained in:
zinface 2023-03-09 18:12:39 +08:00
parent 664f4b0923
commit a09a3f70ce
14 changed files with 346 additions and 6 deletions

8
.gitignore vendored
View File

@ -517,3 +517,11 @@ _deps
# End of https://www.toptal.com/developers/gitignore/api/cmake
!/Makefile
################ Customizable build templates. ################
# If you copy here and customize the build form, its changes will be ignored.
# Windows cmd or powershell supported files..
/windows-msvc-ninja.bat

View File

@ -0,0 +1,49 @@
# 此处提供 Makefile/Batch/PowerShell 配置模板 - 由使用者自定义环境
> 使用者将模板拷贝到项目根目录并进行修改。\
> 由于 .gitignore 中配置了对根目录的 mk 文件过滤,如果需要 git add 添加到暂存,请使用 -f 参数。
- 有关此处结构的内容说明
```
make
├── alternative
│ ├── windows-mingw.mk
│ ├── windows.mk
│ ├── windows-msvc.mk
│ └── windows-universal.mk
├── history
│ ├── win.bat
│ ├── windows.bat
│ ├── win-mingw-make-msbuild.mk
│ └── win.mk
├── powershell-msvc-msbuild.mk
├── README.md
└── windows-msvc-ninja.bat
2 directories, 11 files
```
- 来源于 alternative 目录的说明
```batch
:: 被用于保留的构建模板,在无法验证时保留其变化,除非被确定可用
```
- 来源于 history 目录的说明
```batch
:: 由 fork 用户提供的一系列构建模板,但一般情况下并不可通用
```
- 来源于 windows-msvc-ninja.bat 文件的说明
```batch
:: 用于直接在 Windows 的 cmd 与 PowerShell 中使用的基于批处理构建的模板
:: 将此文件复制到源代码根目录,并进行定制,而 .gitignore 已将其忽略,不再进入源代码树
```
- 来源于 powershell-msvc.mk 文件的说明(暂时保留,无法确认可行)
```shell
# 用于直接在 PowerShell 中使用 mingw32-make.exe 的模板
```

View File

@ -0,0 +1,34 @@
# windows-mingw.mk
# Windows MinGW - 通用 Windows 平台 MinGW 构建方案
builddir := build/windows-mingw
sourcedir := .
CMAKE_DEBUG := -DCMAKE_BUILD_TYPE=Debug
CMAKE_RELEASE := -DCMAKE_BUILD_TYPE=Release
CMAKE_OPTIONS := -DUSE_WINDOWS_MINGW=ON
CMAKE_MINGW_DIR := -DCMAKE_PREFIX_PATH=""
CMAKE_GENERATER := -G"CodeBlocks - MinGW Makefiles"
CMAKE_MINGW_QT := $(CMAKE_OPTIONS) -DWINDOWS_DEPLOY_QT=ON
CMAKE_MINGW_QT5 := $(CMAKE_MINGW_QT) -DWINDOWS_DEPLOY_QT5=ON
CMAKE_MINGW_QT6 := $(CMAKE_MINGW_QT) -DWINDOWS_DEPLOY_QT6=ON
JOBS=$(shell nproc)
# mingw32-make.exe
QT_MINGW_PREFIX_DIR := "-DCMAKE_PREFIX_PATH=C:\Qt\Qt5.14.2\5.14.2\mingw73_64"
windows-mingw:
cmake $(CMAKE_GENERATER) -B$(builddir) $(CMAKE_DEBUG) $(CMAKE_OPTIONS) $(CMAKE_MINGW_DIR)
$(MAKE) -C $(builddir) -j$(JOBS)
windows-mingw-release:
cmake $(CMAKE_GENERATER) -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_OPTIONS) $(CMAKE_MINGW_DIR)
$(MAKE) -C $(builddir) -j$(JOBS)
windows-mingw-release-qt5:
cmake $(CMAKE_GENERATER) -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_MINGW_QT5) $(CMAKE_MINGW_DIR)
$(MAKE) -C $(builddir) -j$(JOBS)
windows-mingw-release-qt6:
cmake $(CMAKE_GENERATER) -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_MINGW_QT6) $(CMAKE_MINGW_DIR)
$(MAKE) -C $(builddir) -j$(JOBS)

View File

@ -0,0 +1,45 @@
# windows-msvc.mk
# Windows MSVC - 通用 Windows 平台 MSVC 构建方案
# 设定指向用于构建时引用的 MSVC Qt 库位置
QT_MSVC_PREFIX_DIR := C:\Qt\Qt5.14.2\5.14.2\msvc2017_64
CPUS:=$(shell powershell "(Get-CimInstance -ClassName Win32_Processor).NumberOfLogicalProcessors")
builddir := build/windows-msvc
installdir:= $(builddir)/install
sourcedir := .
CMAKE_DEBUG := -DCMAKE_BUILD_TYPE=Debug
CMAKE_RELEASE := -DCMAKE_BUILD_TYPE=Release
CMAKE_CXX_FLAGS := -DCMAKE_CXX_FLAGS="/MP$(CPUS)"
CMAKE_OPTIONS := $(CMAKE_CXX_FLAGS) -DUSE_WINDOWS_MSVC=ON
CMAKE_MSVC_DIR := -DCMAKE_PREFIX_PATH=$(QT_MSVC_PREFIX_DIR)
CMAKE_GENERATER := ""
CMAKE_MSVC_QT := $(CMAKE_OPTIONS) -DWINDOWS_DEPLOY_QT=ON
CMAKE_MSVC_QT5 := $(CMAKE_MSVC_QT) -DWINDOWS_DEPLOY_QT5=ON
CMAKE_MSVC_QT6 := $(CMAKE_MSVC_QT) -DWINDOWS_DEPLOY_QT6=ON
windows-msvc:
cmake -B$(builddir) $(CMAKE_DEBUG) $(CMAKE_OPTIONS) $(CMAKE_MSVC_DIR)
cmake --build $(builddir)
windows-msvc-release:
cmake -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_OPTIONS) $(CMAKE_MSVC_DIR)
cmake --build $(builddir) --config Release
windows-msvc-release-qt5:
cmake -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_MSVC_QT5) $(CMAKE_MSVC_DIR)
cmake --build $(builddir) --config Release
windows-msvc-release-qt6:
cmake -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_MSVC_QT6) $(CMAKE_MSVC_DIR)
cmake --build $(builddir) --config Release
windows-msvc-release-qt5-install: windows-msvc-release-qt5
cmake --install $(installdir)
cmake --build $(builddir) --target windows-deployqt
windows-msvc-release-qt6-install: windows-msvc-release-qt6
cmake --install $(installdir)
cmake --build $(builddir) --target windows-deployqt

View File

@ -0,0 +1,11 @@
set Msg='Build with the following configuration:'
set One='1. mingw-make32.exe -f windows-universal.mk'
set Two='2. mingw-make32.exe -f windows-mingw.mk'
set Three='3. mingw-make32.exe -f windows-msvc.mk'
@echo %Msg%
@echo %One% "\n\tThe default Universal Windows platform build"
@echo %Two% "\n\tThe default Universal Windows Platform MinGW build."
@echo %Three% "\n\tThe default Universal Windows Platform MSVC build."

View File

@ -0,0 +1,11 @@
Msg := 'Build with the following configuration:'
One := '1. mingw-make32.exe -f windows-universal.mk'
Two := '2. mingw-make32.exe -f windows-mingw.mk'
Three := '3. mingw-make32.exe -f windows-msvc.mk'
all:
@echo -e $(Msg)
@echo -e $(One) "\n\tThe default Universal Windows platform build"
@echo -e $(Two) "\n\tThe default Universal Windows Platform MinGW build."
@echo -e $(Three) "\n\tThe default Universal Windows Platform MSVC build."

View File

@ -0,0 +1,44 @@
# windows-msvc.mk
# Windows MSVC - 通用 Windows 平台 MSVC 构建方案
# 设定指向用于构建时引用的 MSVC Qt 库位置
QT_MSVC_PREFIX_DIR := C:\Qt\Qt5.14.2\5.14.2\msvc2017_64
CPUS:=$(shell powershell "(Get-CimInstance -ClassName Win32_Processor).NumberOfLogicalProcessors")
builddir := build/windows-msvc
installdir:= $(builddir)/install
sourcedir := .
CMAKE_DEBUG := -DCMAKE_BUILD_TYPE=Debug
CMAKE_RELEASE := -DCMAKE_BUILD_TYPE=Release
CMAKE_CXX_FLAGS := -DCMAKE_CXX_FLAGS="/MP$(CPUS)"
CMAKE_OPTIONS := $(CMAKE_CXX_FLAGS) -DUSE_WINDOWS_MSVC=ON
CMAKE_MSVC_DIR := -DCMAKE_PREFIX_PATH=$(QT_MSVC_PREFIX_DIR)
CMAKE_GENERATER := ""
CMAKE_MSVC_QT := $(CMAKE_OPTIONS) -DWINDOWS_DEPLOY_QT=ON
CMAKE_MSVC_QT5 := $(CMAKE_MSVC_QT) -DWINDOWS_DEPLOY_QT5=ON
CMAKE_MSVC_QT6 := $(CMAKE_MSVC_QT) -DWINDOWS_DEPLOY_QT6=ON
windows-msvc:
cmake -B$(builddir) $(CMAKE_DEBUG) $(CMAKE_OPTIONS) $(CMAKE_MSVC_DIR)
cmake --build $(builddir)
windows-msvc-release:
cmake -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_OPTIONS) $(CMAKE_MSVC_DIR)
cmake --build $(builddir) --config Release
windows-msvc-release-qt5:
cmake -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_MSVC_QT5) $(CMAKE_MSVC_DIR)
cmake --build $(builddir) --config Release
windows-msvc-release-qt6:
cmake -B$(builddir) $(CMAKE_RELEASE) $(CMAKE_MSVC_QT6) $(CMAKE_MSVC_DIR)
cmake --build $(builddir) --config Release
windows-msvc-release-qt5-install: windows-msvc-release-qt5
cmake --install $(installdir)
cmake --build $(builddir) --target windows-deployqt
windows-msvc-release-qt6-install: windows-msvc-release-qt6
cmake --install $(installdir)
cmake --build $(builddir) --target windows-deployqt

View File

@ -0,0 +1,144 @@
:: windows-msvc-ninja.bat
:: Windows MSVC - 通用 Windows 平台 MSVC 构建方案
:: 此文件需以 GBK 方案保存,并在 PowerShell 中运行
@echo off
:: 预固化配置
set builddir=build/windows-universal
set installdir=%builddir%/install
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: ::
:: !!! 定制: 指向用于构建时引用的 MSVC Qt 库位置!!! ::
set QT_MSVC_PREFIX_DIR=C:\Qt\Qt5.14.2\5.14.2\msvc2017_64
:: ::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 构建选项预定义
set CMAKE_OPTIONS=
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -G Ninja
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DCMAKE_PREFIX_PATH=%QT_MSVC_PREFIX_DIR%
@REM set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DCMAKE_BUILD_TYPE=Debug
@REM set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DUSE_WINDOWS_UNIVERSAL=ON
@REM set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DWINDOWS_DEPLOY_QT=ON
@REM set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DWINDOWS_DEPLOY_QT5=ON
@REM set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DWINDOWS_DEPLOY_QT6=ON
@REM set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DUSE_QT6=ON
:: 在配置时 installdir 表示将要安装的路径
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DCMAKE_INSTALL_PREFIX=%installdir%
:: --------------------------------------------------- ::
:: 检查可用配置接收参数
if "%1" == "run" (
:: 此处 \ 与 / 相反
build\windows-universal\windows-deployqt\Notepad--.app\bin\Notepad--.exe
goto :finish
)
:: --------------------------------------------------- ::
@echo ---- 即将构建 Notepad-- 项目 ----
:: 1. 询问构建的类型
@echo 1. 构建 Debug(默认), 2. 构建 Release
set /p chose="请输入序号: "
if "%chose%" == "2" (
set CMAKE_BUILD_TYPE=Relase
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DCMAKE_BUILD_TYPE=Relase
) else (
set CMAKE_BUILD_TYPE=Debug
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DCMAKE_BUILD_TYPE=Debug
)
:: 2. 询问 QSci 构建的类型
@echo ---- 是否指定 QScint 构建为动态库? 默认(OFF) ----
set /p useshare=输入(on):
if "%useshare%" == "on" (
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DNOTEPAD_BUILD_BY_SHARED=ON
)
:: 3. 询问配置 USE_WINDOWS_UNIVERSAL
@echo ---- 是否配置 USE_WINDOWS_UNIVERSAL? 默认(ON) ----
set /p universal=输入(n):
if not "%universal%" == "n" (
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DUSE_WINDOWS_UNIVERSAL=ON
)
:: 4. 询问配置 WINDOWS_DEPLOY_QT
@echo ---- 是否配置 WINDOWS_DEPLOY_QT? 默认(ON) ----
set /p deployqt=输入(n):
if not "%deployqt%" == "n" (
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DWINDOWS_DEPLOY_QT=ON
)
:: 5. 询问配置 WINDOWS_DEPLOY_QT5 或 WINDOWS_DEPLOY_QT6 USE_QT6
@echo ---- 是否配置 WINDOWS_DEPLOY_QT5 版本? 默认(5,可选6) ----
set /p deployqt5=输入(6):
if not "%deployqt5%" == "6" (
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DWINDOWS_DEPLOY_QT5=ON
) else (
set CMAKE_OPTIONS=%CMAKE_OPTIONS% -DWINDOWS_DEPLOY_QT6=ON -DUSE_QT6
)
:: ------------------------------------------------------------------- ::
@echo ----------------------- 构建前配置预览 ---------------------------
@echo "cmake -B%builddir% %CMAKE_OPTIONS% ."
@echo "cmake --build %builddir% --config %CMAKE_BUILD_TYPE%"
@echo "cmake --install %builddir% --prefix %installdir%"
@echo "cmake --build %builddir% --target windows-deployqt"
:: ------------------------------------------------------------------- ::
:: 构建前配置 - 寻找硬盘中的 msvc 环境配置
@echo ---- 寻找硬盘中的 msvc 环境配置 ----
set vcvars=
for %%d in (C: D: E: F: G: H:) do (
if exist %%d (
@echo 正在查找硬盘 %%d 中的 VC 配置环境...
pushd %%d\
for /r %%p in (*vcvars64.bat) do (
@echo 发现配置文件: %%p
set vcvars=%%p
popd
goto :set_vcvars
)
popd
)
)
:set_vcvars
if "%vcvars%" == "" (
@echo "could not found vcvars64.bat file"
goto :finish
) else (
@echo "config MSVC environment..."
call "%vcvars%" amd64
)
:: 正式对项目进行配置、构建、安装、部署
@echo ------------ 准备构建 ------------
cmake -B%builddir% %CMAKE_OPTIONS% .
cmake --build %builddir% --config %CMAKE_BUILD_TYPE%
cmake --install %builddir% --prefix %installdir%
cmake --build %builddir% --target windows-deployqt
goto :finish
:: 正常或异常退出的定位
:finish
pause
:: 本配置模板可在 cmd 命令行 或 Powershell 中运行
:: 本配置模板复制到项目根目录,并定制,可在 Windows 中双击运行
:: 本配置可

View File

@ -1,6 +0,0 @@
Msg := 'Build with the following configuration:'
One := '1. make -f windows-universal.mk'
all:
@echo -e $(Msg)
@echo -e $(One) "\n\tThe default Universal Windows platform build"