-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCMakeLists.txt
254 lines (229 loc) · 8.26 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
cmake_minimum_required(VERSION 3.19)
project(video2x-qt6 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(VIDEO2X_ENABLE_NATIVE "Enable native optimizations (-march=native)" OFF)
option(VIDEO2X_ENABLE_X86_64_V4 "Enable x86-64-v4 optimizations (-march=x86-64-v4)" OFF)
option(VIDEO2X_ENABLE_X86_64_V3 "Enable x86-64-v3 optimizations (-march=x86-64-v3)" OFF)
option(USE_EXTERNAL_SPDLOG "Use the system-provided spdlog library" ON)
option(USE_EXTERNAL_VIDEO2X "Use the system-provided video2x" OFF)
option(USE_SHARED_VIDEO2X "Use the shared video2x library" OFF)
# Set global compile options for all targets
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/W4 /permissive-)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wshadow)
endif()
# Set the default optimization flags for Release builds
if(CMAKE_BUILD_TYPE STREQUAL "Release")
# Set the optimization flags for each compiler
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/Ox /Ot /GL /DNDEBUG)
add_link_options(/LTCG /OPT:REF /OPT:ICF)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-O3 -ffunction-sections -fdata-sections)
add_link_options(-Wl,-s -flto -Wl,--gc-sections)
endif()
endif()
# Enable the requested architecture-specific optimizations
if(VIDEO2X_ENABLE_NATIVE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/arch:NATIVE)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-march=native)
endif()
elseif(VIDEO2X_ENABLE_X86_64_V4)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/arch:AVX2)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-march=x86-64-v4)
endif()
elseif(VIDEO2X_ENABLE_X86_64_V3)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_compile_options(/arch:AVX2)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-march=x86-64-v3)
endif()
endif()
# Define lists to store include directories and libraries
set(VIDEO2X_QT6_INCLUDE_DIRS)
set(VIDEO2X_QT6_LIBS)
# Find the required Qt6 components
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Network LinguistTools)
qt_standard_project_setup()
list(APPEND VIDEO2X_QT6_LIBS Qt6::Core Qt6::Widgets Qt6::Network)
# Find the Vulkan SDK
find_package(Vulkan REQUIRED)
list(APPEND VIDEO2X_QT6_LIBS Vulkan::Vulkan)
# Find FFmpeg libraries and includes
if(WIN32)
# Add FFmpeg libraries and headers
set(FFMPEG_BASE_PATH ${CMAKE_SOURCE_DIR}/third_party/ffmpeg-shared)
list(APPEND VIDEO2X_QT6_LIBS
${FFMPEG_BASE_PATH}/lib/avutil.lib
${FFMPEG_BASE_PATH}/lib/avcodec.lib
)
list(APPEND VIDEO2X_QT6_INCLUDE_DIRS ${FFMPEG_BASE_PATH}/include)
else()
# Find the required packages using pkg-config
find_package(PkgConfig REQUIRED)
set(REQUIRED_PKGS libavutil libavcodec)
# Loop through each package to find and collect include dirs and libraries
foreach(PKG ${REQUIRED_PKGS})
pkg_check_modules(${PKG} REQUIRED ${PKG})
list(APPEND VIDEO2X_QT6_INCLUDE_DIRS ${${PKG}_INCLUDE_DIRS})
list(APPEND VIDEO2X_QT6_LIBS ${${PKG}_LIBRARIES})
endforeach()
endif()
# Find the spdlog library
if(USE_EXTERNAL_SPDLOG)
find_package(spdlog REQUIRED)
set(SPDLOG_LIB spdlog::spdlog)
else()
add_subdirectory(third_party/spdlog)
set(SPDLOG_LIB spdlog::spdlog_header_only)
endif()
list(APPEND VIDEO2X_QT6_LIBS ${SPDLOG_LIB})
# Find the libvideo2x library
if(USE_EXTERNAL_VIDEO2X)
find_package(Video2X REQUIRED)
list(APPEND VIDEO2X_QT6_LIBS Video2X::libvideo2x)
elseif(USE_SHARED_VIDEO2X)
# Add libvideo2x shared libraries and headers
set(LIBVIDEO2X_BASE_PATH ${CMAKE_SOURCE_DIR}/third_party/video2x-install)
list(APPEND VIDEO2X_QT6_LIBS ${LIBVIDEO2X_BASE_PATH}/libvideo2x.lib)
list(APPEND VIDEO2X_QT6_INCLUDE_DIRS ${LIBVIDEO2X_BASE_PATH}/include)
else()
# Include ExternalProject module
include(ExternalProject)
# Add libvideo2x as an external project
ExternalProject_Add(
Video2X
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/video2x
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/video2x-install
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_ALWAYS ON
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}
)
endif()
# Define the list of translation files
set(TS_FILES src/video2x-qt6_en_US.ts
src/video2x-qt6_zh_CN.ts
src/video2x-qt6_ja_JP.ts
src/video2x-qt6_pt_PT.ts
src/video2x-qt6_fr_FR.ts
src/video2x-qt6_de_DE.ts)
# Define the project source files
set(PROJECT_SOURCES
src/aboutdialog.cpp
src/aboutdialog.h
src/aboutdialog.ui
src/configmanager.cpp
src/configmanager.h
src/filedroptableview.cpp
src/filedroptableview.h
src/main.cpp
src/mainwindow.cpp
src/mainwindow.h
src/mainwindow.ui
src/qttexteditsink.cpp
src/qttexteditsink.h
src/taskconfig.h
src/taskconfigdialog.cpp
src/taskconfigdialog.h
src/taskconfigdialog.ui
src/taskprocessor.cpp
src/taskprocessor.h
src/timer.cpp
src/timer.h
src/utils.cpp
src/utils.h
src/translations.qrc
${TS_FILES}
)
# Define the application resource file for Windows
if(WIN32)
set(APP_RESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/src/resources.rc")
endif()
qt_add_executable(video2x-qt6
WIN32 MACOSX_BUNDLE
${PROJECT_SOURCES}
${APP_RESOURCE_FILE}
)
qt_add_translations(video2x-qt6
TS_FILES ${TS_FILES}
LUPDATE_OPTIONS -no-obsolete
RESOURCE_PREFIX "/i18n"
)
target_include_directories(video2x-qt6 PRIVATE
${spdlog_INCLUDE_DIRS}
${VIDEO2X_QT6_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/third_party/video2x/include
)
if(NOT USE_EXTERNAL_VIDEO2X AND NOT USE_SHARED_VIDEO2X)
add_dependencies(video2x-qt6 Video2X)
if(WIN32)
set(LIBVIDEO2X_LIB ${CMAKE_BINARY_DIR}/video2x-install/libvideo2x.lib)
else()
set(LIBVIDEO2X_LIB ${CMAKE_BINARY_DIR}/video2x-install/libvideo2x.so)
endif()
list(APPEND VIDEO2X_QT6_LIBS ${LIBVIDEO2X_LIB})
endif()
target_link_libraries(video2x-qt6 PRIVATE ${VIDEO2X_QT6_LIBS})
include(GNUInstallDirs)
install(TARGETS video2x-qt6
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(WIN32)
qt_generate_deploy_app_script(
TARGET video2x-qt6
OUTPUT_SCRIPT deploy_script
NO_UNSUPPORTED_PLATFORM_ERROR
)
install(SCRIPT ${deploy_script})
elseif(LINUX)
install(FILES resources/video2x-qt6.desktop
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications
)
install(DIRECTORY resources/icons/16x16/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/16x16/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/24x24/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/24x24/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/32x32/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/48x48/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/64x64/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/128x128/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/256x256/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/512x512/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/512x512/apps
FILES_MATCHING PATTERN "*.png"
)
install(DIRECTORY resources/icons/1024x1024/
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/1024x1024/apps
FILES_MATCHING PATTERN "*.png"
)
endif()