-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
98 lines (88 loc) · 2.86 KB
/
CMakeLists.txt
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
cmake_minimum_required(VERSION 3.28)
# 定义项目
project(ZXNoter-cpp LANGUAGES CXX)
# 自动处理qt文件
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
# 设置c++标准
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE
Debug
CACHE STRING "Build type" FORCE)
# 导出编译命令(clangd补全用)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
# 包含src中全部头文件
include_directories(src)
# 分系统find库
if(WIN32)
# WIN系统
set(VCPKG "$ENV{CMAKE_TOOLCHAIN_FILE}/../../../packages/")
# 配置vcpkg库路径
list(APPEND CMAKE_MODULE_PATH "${VCPKG}ffmpeg_x64-windows/share/ffmpeg")
# sdl2(simple directmedia layer)媒体库
list(APPEND CMAKE_PREFIX_PATH "${VCPKG}sdl2_x64-windows/share/sdl2")
# json库
list(APPEND CMAKE_PREFIX_PATH "${VCPKG}jsoncpp_x64-windows/share/jsoncpp")
# gl数学库
list(APPEND CMAKE_PREFIX_PATH "${VCPKG}glm_x64-windows/share/glm")
# 字体库
list(APPEND CMAKE_PREFIX_PATH "${VCPKG}freetype_x64-windows/share/freetype")
# 日志和前置
list(APPEND CMAKE_PREFIX_PATH "${VCPKG}fmt_x64-windows/share/fmt")
list(APPEND CMAKE_PREFIX_PATH "${VCPKG}spdlog_x64-windows/share/spdlog")
find_package(FFMPEG REQUIRED)
find_package(SDL2 CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(Freetype CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
endif(WIN32)
if(UNIX)
# UNIX系统
find_package(SDL2 REQUIRED)
find_package(glm REQUIRED)
find_package(Freetype REQUIRED)
find_package(spdlog REQUIRED)
endif(UNIX)
# 查找jsoncpp库
find_package(jsoncpp CONFIG REQUIRED)
# 查找Qt库
find_package(Qt6 REQUIRED COMPONENTS Gui Core Widgets OpenGL OpenGLWidgets)
# qt ui文件列表
set(QTUIS src/qt/ui/mainwindow.ui)
# qt资源文件管理
set(RESOURCES src/qt/ui/resources/css_resources.qrc)
# 源文件列表
set(SOURCES src/qt/gl/glcanvas.cpp src/qt/ui/mainwindow.cpp src/main.cpp
src/qt/concurrent_preview.cpp ${QTUIS} ${RESOURCES})
# 添加启动项
add_executable(test_zxnoter ${SOURCES})
# 链接Qt库
target_link_libraries(test_zxnoter PRIVATE Qt::Core Qt::Gui Qt::Widgets
Qt::OpenGL Qt::OpenGLWidgets)
# 链接零散库
target_link_libraries(test_zxnoter PRIVATE JsonCpp::JsonCpp SDL2::SDL2 glm::glm
Freetype::Freetype spdlog::spdlog)
# 链接ffmpeg
if(WIN32)
# WIN系统 包含ffmpeg头文件
include_directories(${FFMPEG_INCLUDE_DIRS})
target_link_libraries(test_zxnoter PRIVATE ${FFMPEG_LIBRARIES})
endif(WIN32)
if(UNIX)
# UNIX系统 查找包管理器
find_package(PkgConfig REQUIRED)
# 直接查找ffmpeg
pkg_check_modules(
ffmpeg
REQUIRED
IMPORTED_TARGET
libavutil
libavformat
libavcodec
libswresample
libswscale)
# 链接ffmpeg
target_link_libraries(test_zxnoter PRIVATE PkgConfig::ffmpeg)
endif(UNIX)