-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
180 lines (157 loc) · 4.77 KB
/
Copy pathCMakeLists.txt
File metadata and controls
180 lines (157 loc) · 4.77 KB
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
cmake_minimum_required(VERSION 3.16)
project(
Memento
VERSION 2.0.1
DESCRIPTION "An mpv-based video player for studying Japanese"
HOMEPAGE_URL "https://ripose-jp.github.io/Memento"
LANGUAGES C CXX
)
if(APPLE)
enable_language(OBJCXX)
endif()
# Set the default build type
set(default_build_type "RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
set(
CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE
)
# Set the possible values of build type for cmake-gui
set_property(
CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo"
)
endif()
# Require out-of-source builds
file(TO_CMAKE_PATH "${PROJECT_BINARY_DIR}/CMakeLists.txt" LOC_PATH)
if(EXISTS "${LOC_PATH}")
message(FATAL_ERROR "You cannot build in a source directory (or any directory with a CMakeLists.txt file). Please make a build subdirectory. Feel free to remove CMakeCache.txt and CMakeFiles.")
endif()
add_subdirectory(option)
# Check that dangerous options have no been toggled
if(NOT APPLE AND MEMENTO_BUNDLE)
message(FATAL_ERROR "You cannot set the MEMENTO_BUNDLE option to ON on non-Apple platforms.")
endif()
# Set the module path
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Make IDEs understand the code better
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Set Compiler Flags
list(
APPEND
MEMENTO_COMPILER_FLAGS
"-Wall"
"-Wextra"
"-Wpedantic"
"$<$<BOOL:${MEMENTO_BUNDLE}>:-DMEMENTO_BUNDLE=1>"
"$<$<BOOL:${MEMENTO_ASAN}>:-fsanitize=address>"
"$<$<BOOL:${MEMENTO_MECAB_SUPPORT}>:-DMEMENTO_MECAB_SUPPORT=1>"
"$<$<BOOL:${MEMENTO_OCR_SUPPORT}>:-DMEMENTO_OCR_SUPPORT=1>"
"$<$<BOOL:${MEMENTO_QAPPLICATION}>:-DMEMENTO_QAPPLICATION=1>"
"$<$<BOOL:${MEMENTO_SYSTEM_QCORO}>:-DMEMENTO_SYSTEM_QCORO=1>"
"$<$<BOOL:${MEMENTO_WERROR}>:-Werror>"
)
if(MEMENTO_ASAN)
add_link_options(-fsanitize=address)
endif()
# Get the Git version hash
if(NOT MEMENTO_RELEASE_BUILD)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(
COMMAND ${GIT_EXECUTABLE} log --pretty=format:%h -n 1
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE MEMENTO_VERSION_HASH
)
endif()
endif()
# Set the proper variables for macOS cross compilation
if(MEMENTO_MAC_CROSSCOMPILE_X86)
set(CMAKE_OSX_ARCHITECTURES "x86_64")
endif()
# Generate include directories
if(APPLE AND NOT MEMENTO_MAC_CROSSCOMPILE_X86)
# This makes sure Memento builds on whatever arch is native
# The order of directories MATTERS because M1 users may cross compile but
# x86_64 users will not
set(
MEMENTO_INCLUDE_DIRS
# arm64 locations
"/opt/homebrew/opt/qt6/include"
"/opt/homebrew/include"
# x86_64 locations
"/usr/local/opt/qt6/include/"
"/usr/local/include"
)
elseif(APPLE AND MEMENTO_MAC_CROSSCOMPILE_X86)
# This is a cross compile target, x86_64 users shouldn't need to use this
set(
MEMENTO_INCLUDE_DIRS
"/usr/local/opt/qt6/include/"
"/usr/local/include"
)
endif()
list(PREPEND MEMENTO_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/src")
# Set prefix path for macOS
if(APPLE AND NOT MEMENTO_MAC_CROSSCOMPILE_X86)
# x86_64 locations
list(PREPEND CMAKE_PREFIX_PATH "/usr/local/opt")
list(PREPEND CMAKE_PREFIX_PATH "/usr/local/")
# arm64 locations
list(PREPEND CMAKE_PREFIX_PATH "/opt/homebrew/opt")
list(PREPEND CMAKE_PREFIX_PATH "/opt/homebrew")
elseif(APPLE AND MEMENTO_MAC_CROSSCOMPILE_X86)
# x86_64 locations
list(PREPEND CMAKE_PREFIX_PATH "/usr/local/opt")
list(PREPEND CMAKE_PREFIX_PATH "/usr/local/")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(JsonC REQUIRED)
find_package(libzip REQUIRED)
find_package(mpv REQUIRED)
find_package(SQLite3 REQUIRED)
if(NOT TARGET SQLite3::SQLite3 AND TARGET SQLite::SQLite3)
add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)
endif()
if(MEMENTO_SYSTEM_QCORO)
find_package(QCoro6 REQUIRED COMPONENTS Core Network Qml)
endif()
if(MEMENTO_MECAB_SUPPORT)
find_package(MeCab REQUIRED)
endif()
if(MEMENTO_OCR_SUPPORT AND MEMENTO_SYSTEM_MOCR)
find_package(mocr REQUIRED)
endif()
set(
MEMENTO_QT_COMPONENTS
Concurrent
Core
Gui
LinguistTools
Network
OpenGL
Qml
Quick
QuickControls2
Svg
)
if(APPLE)
list(APPEND MEMENTO_QT_COMPONENTS QuickPrivate)
endif()
if(UNIX AND NOT APPLE)
list(APPEND MEMENTO_QT_COMPONENTS DBus)
endif()
if(MEMENTO_QAPPLICATION)
list(APPEND MEMENTO_QT_COMPONENTS Widgets)
endif()
set(QT_NO_PRIVATE_MODULE_WARNING ON CACHE BOOL "Suppress Qt private module warning" FORCE)
find_package(Qt6 REQUIRED COMPONENTS ${MEMENTO_QT_COMPONENTS})
unset(MEMENTO_QT_COMPONENTS)
qt_standard_project_setup(REQUIRES 6.9)
if(WIN32)
add_subdirectory(windows)
endif()
add_subdirectory(extern)
add_subdirectory(src)
add_subdirectory(res)