-
Notifications
You must be signed in to change notification settings - Fork 117
/
CMakeLists.txt
228 lines (191 loc) · 8.06 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
cmake_minimum_required(VERSION 3.6.0)
project(fcitx VERSION 5.1.11)
set(FCITX_VERSION ${PROJECT_VERSION})
find_package(ECM REQUIRED 1.0.0)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${ECM_MODULE_PATH} ${CMAKE_MODULE_PATH})
#######################################################################
# CMake macros
#######################################################################
include(FeatureSummary)
include(GNUInstallDirs)
include(ECMSetupVersion)
include(GenerateExportHeader)
include(WriteBasicConfigVersionFile)
include(ECMUninstallTarget)
include(src/lib/fcitx-utils/Fcitx5Macros.cmake)
include(CheckSymbolExists)
#######################################################################
# Options
#######################################################################
option(ENABLE_TEST "Build Test" On)
option(ENABLE_COVERAGE "Build the project with gcov support (Need ENABLE_TEST=On)" Off)
set(GCOV_TOOL "gcov" CACHE STRING "Path to gcov tool used by coverage.")
set(DEFAULT_XKB_RULES "evdev" CACHE STRING "Xkb rules name")
option(ENABLE_ENCHANT "Enable enchant for word predication" On)
option(ENABLE_X11 "Enable X11 support" On)
option(ENABLE_WAYLAND "Enable wayland support" On)
option(ENABLE_DBUS "Enable DBus" On)
option(ENABLE_DOC "Build doxygen" Off)
option(ENABLE_SERVER "Build a fcitx as server, disable this option if you want to use fcitx as an embedded library." On)
option(ENABLE_KEYBOARD "Enable key event translation with XKB and build keyboard engine" On)
option(USE_SYSTEMD "Use systemd for event loop and dbus, will fallback to libuv/libdbus if not found." On)
option(ENABLE_XDGAUTOSTART "Enable xdg autostart desktop file installation" On)
option(USE_FLATPAK_ICON "Use flatpak icon name for desktop files" Off)
option(ENABLE_EMOJI "Enable emoji module" On)
option(ENABLE_LIBUUID "Use libuuid for uuid generation" On)
option(BUILD_SPELL_DICT "Build en_dict.fscd for English spell check" On)
set(NO_PREEDIT_APPS "gvim.*,wps.*,wpp.*,et.*" CACHE STRING "Disable preedit for follwing app by default.")
if (ENABLE_EMOJI)
find_package(ZLIB REQUIRED)
endif()
if ((ENABLE_WAYLAND OR ENABLE_X11) AND NOT ENABLE_KEYBOARD)
message(FATAL_ERROR "X11 and Wayland require ENABLE_KEYBOARD to be set to ON.")
endif ()
#######################################################################
# Find packages
#######################################################################
find_package(PkgConfig REQUIRED)
if (USE_SYSTEMD)
find_package(Systemd)
endif ()
if (USE_FLATPAK_ICON)
set(FCITX_ICON_NAME "org.fcitx.Fcitx5")
else()
set(FCITX_ICON_NAME "fcitx")
endif()
if (NOT TARGET Systemd::Systemd)
if (ENABLE_DBUS)
pkg_check_modules(DBus REQUIRED IMPORTED_TARGET "dbus-1")
pkg_get_variable(DBUS_SYSTEM_BUS_DEFAULT_ADDRESS "dbus-1" "system_bus_default_address")
endif()
if (NOT LIBUV_TARGET)
if (NOT (TARGET PkgConfig::LibUV))
pkg_check_modules(LibUV REQUIRED IMPORTED_TARGET "libuv")
endif()
set(LIBUV_TARGET PkgConfig::LibUV)
endif()
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "BSD|DragonFly")
find_package(LibKVM REQUIRED)
endif()
find_package(DL REQUIRED)
if (NOT TARGET LibIntl::LibIntl)
find_package(LibIntl REQUIRED)
endif()
if (ENABLE_LIBUUID)
find_package(LibUUID REQUIRED)
endif()
find_package(Pthread REQUIRED)
find_package(Execinfo)
find_package(Gettext REQUIRED)
if (NOT (TARGET fmt::fmt OR TARGET fmt::fmt-header-only))
find_package(fmt REQUIRED)
endif()
if (TARGET fmt::fmt-header-only)
set(FMT_TARGET fmt::fmt-header-only)
else()
set(FMT_TARGET fmt::fmt)
endif ()
set(REQUIRED_XKBCOMMON_COMPONENTS XKBCommon)
if (ENABLE_X11)
set(REQUIRED_XKBCOMMON_COMPONENTS ${REQUIRED_XKBCOMMON_COMPONENTS} X11)
find_package(XCB REQUIRED COMPONENTS XCB AUX XKB XFIXES ICCCM XINERAMA RANDR EWMH KEYSYMS)
find_package(XCBImdkit 1.0.3 REQUIRED)
pkg_check_modules(CairoXCB REQUIRED IMPORTED_TARGET cairo-xcb)
pkg_check_modules(XkbFile REQUIRED IMPORTED_TARGET "xkbfile")
endif()
if (ENABLE_KEYBOARD)
find_package(Expat REQUIRED)
endif()
if (ENABLE_KEYBOARD)
find_package(XKBCommon REQUIRED COMPONENTS ${REQUIRED_XKBCOMMON_COMPONENTS})
find_package(IsoCodes REQUIRED)
find_package(XKeyboardConfig REQUIRED)
pkg_check_modules(JsonC REQUIRED IMPORTED_TARGET "json-c")
set(DEFAULT_XKB_RULES_FILES "${XKEYBOARDCONFIG_XKBBASE}/rules/${DEFAULT_XKB_RULES}.xml")
if (NOT EXISTS "${DEFAULT_XKB_RULES_FILES}" AND NOT APPLE)
message(WARNING "Could not find default xkb rules file: ${DEFAULT_XKB_RULES_FILES}")
endif()
endif()
# Library for classicui painting
if (ENABLE_X11 OR ENABLE_WAYLAND)
pkg_check_modules(Cairo IMPORTED_TARGET cairo)
pkg_check_modules(Pango IMPORTED_TARGET pango pangocairo)
pkg_check_modules(GdkPixbuf IMPORTED_TARGET gdk-pixbuf-2.0)
pkg_check_modules(GioUnix IMPORTED_TARGET gio-unix-2.0)
endif()
if (ENABLE_WAYLAND)
set(REQUIRED_WAYLAND_COMPONENTS Client Cursor)
find_package(Wayland REQUIRED COMPONENTS ${REQUIRED_WAYLAND_COMPONENTS})
find_package(WaylandScanner REQUIRED)
find_package(WaylandProtocols REQUIRED)
pkg_check_modules(Gio IMPORTED_TARGET gio-2.0)
endif()
if(ENABLE_ENCHANT)
pkg_check_modules(Enchant IMPORTED_TARGET "enchant-2")
if(NOT TARGET PkgConfig::Enchant)
pkg_check_modules(Enchant IMPORTED_TARGET "enchant" REQUIRED)
endif()
endif()
if (TARGET Wayland::Client AND ENABLE_WAYLAND)
set(WAYLAND_FOUND TRUE)
else()
set(WAYLAND_FOUND FALSE)
endif()
# directory needed by bsd
if(NOT CMAKE_INSTALL_LIBDATADIR)
set(CMAKE_INSTALL_LIBDATADIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "libdata root (LIBDIR)")
endif()
get_filename_component(CMAKE_INSTALL_FULL_LIBDATADIR "${CMAKE_INSTALL_LIBDATADIR}" ABSOLUTE)
mark_as_advanced(CMAKE_INSTALL_LIBDATADIR)
mark_as_advanced(CMAKE_INSTALL_FULL_LIBDATADIR)
include(Fcitx5CompilerSettings)
set(FCITX_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(FCITX_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR})
set(FCITX_INSTALL_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
set(FCITX_INSTALL_LIBDATADIR ${CMAKE_INSTALL_FULL_LIBDATADIR})
set(FCITX_INSTALL_LIBEXECDIR ${CMAKE_INSTALL_FULL_LIBEXECDIR})
set(FCITX_INSTALL_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
set(FCITX_INSTALL_PKGDATADIR "${CMAKE_INSTALL_FULL_DATADIR}/fcitx5")
set(FCITX_INSTALL_BINDIR ${CMAKE_INSTALL_FULL_BINDIR})
set(FCITX_INSTALL_LOCALEDIR ${CMAKE_INSTALL_FULL_LOCALEDIR})
set(FCITX_INSTALL_ADDONDIR "${CMAKE_INSTALL_FULL_LIBDIR}/fcitx5")
set(FCITX_INSTALL_CMAKECONFIG_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/cmake")
set(FCITX_INSTALL_MODULE_HEADER_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/Fcitx5/Module/fcitx-module")
# TODO mac/win
set(FCITX_LIBRARY_SUFFIX ".so")
check_function_exists(pipe2 HAVE_PIPE2)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(src)
add_subdirectory(data)
add_subdirectory(po)
add_subdirectory(testing)
#######################################################################
# Test features
#######################################################################
if (ENABLE_TEST)
enable_testing()
add_subdirectory(test)
if (ENABLE_COVERAGE)
add_custom_target(coverage
COMMAND "${CMAKE_CTEST_COMMAND}"
COMMAND lcov --gcov-tool "${GCOV_TOOL}" --no-external --capture --directory ./ -b "${CMAKE_CURRENT_SOURCE_DIR}" --output-file coverage.info
COMMAND genhtml coverage.info --output-directory "coverage_pages"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif ()
if (ENABLE_DOC)
find_package(Doxygen REQUIRED)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/.codedocs" FCITX_DOXYGEN_CONFIGURATION)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
@ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif()
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)