repo: 全新构建结构与模式规划,从 Makefile 到 CMakeLists.txt 的定义

This commit is contained in:
zinface 2023-02-16 23:16:50 +08:00
parent 9fe169963e
commit 347f3a3616
5 changed files with 105 additions and 86 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)
project(notepad-- VERSION 1.22.0) project(Notepad-- VERSION 1.22.0)
include(cmake/SparkEnvConfig.cmake) include(cmake/SparkEnvConfig.cmake)
include(cmake/SparkMacrosConfig.cmake) include(cmake/SparkMacrosConfig.cmake)
@ -27,12 +27,76 @@ if(TRUE)
endif(TRUE) endif(TRUE)
# ----------------- Notepad-- 线 ----------------- # # ----------------- Notepad-- 线 ----------------- #
option(USE_MACOS_UNIVERSAL "通用 MacOS 平台构建" OFF)
#
option(USE_LINUX_UNIVERSAL "通用 Linux 平台构建" OFF)
option(USE_LINUX_DEBIAN "通用 Debian Linux 平台构建" OFF)
option(USE_LINUX_APPIMGE "通用 Appimage Linux 平台构建" OFF)
#
option(USE_LINUX_UOS "独立 Linux 平台的 Uos 构建" OFF)
#
option(USE_WINDOWS_UNIVERSAL "通用 Windows 平台构建" OFF)
option(USE_WINDOWS_MINGW "通用 Windows 平台 MinGW 构建" OFF)
option(USE_WINDOWS_MSVC "通用 Windows 平台 MSVC 构建" OFF)
#
option(WINDOWS_DEPLOY_QT5 "通用 Windows Qt5 构建 windeployqt" OFF)
option(WINDOWS_DEPLOY_QT6 "通用 Windows Qt6 构建 windeployqt" OFF)
# 使 macos.cmake / linux.cmake / windows.cmake . # 使 macos.cmake / linux.cmake / windows.cmake .
if(APPLE) if(APPLE)
include(cmake/platforms/macos.cmake) # MacOS 平台的构建(一个无具体实现的空构建)
# include(cmake/platforms/macos.cmake)
# Linux Debian Appimage Uos
elseif(UNIX AND NOT APPLE AND NOT WIN32 AND NOT ANDROID) elseif(UNIX AND NOT APPLE AND NOT WIN32 AND NOT ANDROID)
include(cmake/platforms/linux.cmake)
# Linux
if(USE_LINUX_UNIVERSAL)
# include(cmake/platforms/linux-universal.cmake)
# Debian deb
if(USE_LINUX_DEBIAN)
# include(cmake/platforms/linux-debian.cmake)
endif()
# Appimage
if(USE_LINUX_APPIMGE)
# include(cmake/platforms/linux-appimage.cmake)
endif()
# Linux Uos
elseif(USE_LINUX_UOS)
# include(cmake/platforms/linux-uos.cmake)
# Linux
else()
# include(cmake/platforms/linux.cmake)
endif(USE_LINUX_UNIVERSAL)
# Windows MinGW MSVC
elseif(WIN32) elseif(WIN32)
include(cmake/platforms/windows.cmake)
# Windows
if(USE_WINDOWS_UNIVERSAL)
# include(cmake/platforms/windows.cmake)
# Windows MinGW
if(USE_WINDOWS_MINGW)
# include(cmake/platforms/windows-mingw.cmake)
endif()
# Windows MSVC
if(USE_WINDOWS_MSVC)
# include(cmake/platforms/windows-msvc.cmake)
endif()
# Windows
else()
# include(cmake/platforms/windows.cmake)
endif(USE_WINDOWS_UNIVERSAL)
endif() endif()
# ----------------- Notepad-- 线 ----------------- #

107
Makefile
View File

@ -1,84 +1,27 @@
CPUS=$(shell nproc) # 主体构建入口
CALENDAR=$(shell date '+%Y%m%d')
OSID=$(shell lsb_release -si) # 1. 在 Windows 中 $(OS) 为 Windows_NT
OSRELEASE=$(shell lsb_release -sr) # 2. 在 Linux 中 $(OS) 为空的,此时应该使用 uname
SUFFIX= # 注意:在 Linux 中 uanme -s 显示为 Linux
ifneq ("$(OSID)", "") # 注意:在 Linux 中某些内核 uanme -p 显示为 unknow
SUFFIX=_$(OSID)$(OSRELEASE) # 3. 待验证:在 OSX 中 $(OS) 为空的,此时应该使用 uname
# 待验证:在 OSX 中 uname -s 显示为 Darwin
# 待验证:在 OSX 中 uname -p 显示为 ?
# Windows 平台相关
ifeq ($(OS),Windows_NT)
include windows.mk
# Unix 平台相关
else
UNAME_S := $(shell uname -s)
# Linux 构建
ifeq ($(UNAME_S),Linux)
include linux.mk
endif
# MacOS 构建
ifeq ($(UNAME_S),Darwin)
include macos.mk
endif
endif endif
PROJECT_NAME=notepad--
PACKAGE_NAME=com.hmja.notepad
all:
mkdir -p build
cd build && cmake ..
cd build && make -j$(CPUS)
run: all
exec $(shell find build/ -maxdepth 1 -type f -executable | grep $(PROJECT_NAME))
debug:
mkdir -p build
cd build && cmake -DCMAKE_BUILD_TYPE=Debug ..
cd build && make -j$(CPUS)
release:
mkdir -p build
cd build && cmake -DCMAKE_BUILD_TYPE=Release -DPACKAGE_SUFFIX="$(SUFFIX)" ..
cd build && make -j$(CPUS)
package: release
cd build && make package
tree build/_CPack_Packages/Linux/DEB/$(PROJECT_NAME)-*
dpkg-deb --contents build/$(PACKAGE_NAME)_*$(CALENDAR)*$(SUFFIX).deb
# cd build/_CPack_Packages/Linux/DEB/$(PROJECT_NAME)_*$(CALENDAR)*$(SUFFIX).deb && find .
builddeps:
cd build && make builddeps
cpus:
@echo "CPU数量: $(CPUS)"
copytosource:package
cp build/$(PACKAGE_NAME)_*$(CALENDAR)*.deb .
# 进入 qdebug 模式,在 deepin 中默认被禁用,可 env | grep QT 查看,并在 /etc/X11/Xsession.d/00deepin-dde-env 配置中已定义
# 1. 禁止 qt 的 debug 打印: qt.*.debug=false
# qt.qpa.input.events
# qt.qpa.events
# 2. 禁止 dtk 的 debug 打印: dtk.*.debug=false
# dtk.dpluginloader
# 3. 禁止 qtcreator 本身的 debug 打印
# qtc.autotest.testcodeparser
# qtc.clangbackend.server
# ...
# 4. 关闭其它的太麻烦了,直接只启用本地 debug
# .debug=true
enter-qdebug-mode:
# 进入新的 bash 环境
@# export QT_LOGGING_RULES=".debug=true; qt.*.debug=false; dtk.*.debug=false; dde.*.debug=false; qtc*=false; " && bash
export QT_LOGGING_RULES=".debug=true" && bash
# Appimage 的构建流 --
# 在 Makefile 进行构建目标构建 Appimage (要求提供工具的绝对路径然后可依次进行linuxdeployqt, genrate-appimage)
# 来自于 https://github.com/probonopd/linuxdeployqt 的 linuxdeployqt
# 来自于 https://github.com/AppImage/AppImageKit 的 appimagetool
# 来自于 https://gitlink.org.cn/zinface/bundle-linuxdeployqt.git 托管存储的工具
# 或指定你所想存放克隆项目的位置
BUNDLE_LINUXDEPLOYQT := $(shell pwd)/build/bundle-linuxdeployqt
download-bundle-linuxdeploytools:
-git clone https://gitlink.org.cn/zinface/bundle-linuxdeployqt.git $(BUNDLE_LINUXDEPLOYQT)
LINUXDEPLOYQT := "$(BUNDLE_LINUXDEPLOYQT)/linuxdeployqt-continuous-x86_64.AppImage"
APPIMAGETOOL := "$(BUNDLE_LINUXDEPLOYQT)/appimagetool-x86_64.AppImage"
linuxdeploy: release download-bundle-linuxdeploytools
cd build && cmake .. -DLINUXDEPLOYQT=$(LINUXDEPLOYQT) -DAPPIMAGETOOL=$(APPIMAGETOOL)
cd build && make linuxdeploy
genrate-appimage:
cd build && cmake .. -DLINUXDEPLOYQT=$(LINUXDEPLOYQT) -DAPPIMAGETOOL=$(APPIMAGETOOL)
cd build && make appimage

4
linux.mk Normal file
View File

@ -0,0 +1,4 @@
Msg := 'Build with the following configuration:'
all:
@echo $(Msg)

4
macos.mk Normal file
View File

@ -0,0 +1,4 @@
Msg := 'Build with the following configuration:'
all:
@echo $(Msg)

4
windows.mk Normal file
View File

@ -0,0 +1,4 @@
Msg := 'Build with the following configuration:'
all:
@echo -e $(Msg)