forked from rime/librime
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
285 lines (240 loc) · 8.71 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/c_flag_overrides.cmake)
set(CMAKE_USER_MAKE_RULES_OVERRIDE_CXX ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cxx_flag_overrides.cmake)
cmake_minimum_required(VERSION 3.12)
project(rime)
set(CMAKE_CXX_STANDARD 17)
set(rime_version 1.12.0)
set(rime_soversion 1)
add_definitions(-DRIME_VERSION="${rime_version}")
include(GNUInstallDirs)
option(BUILD_SHARED_LIBS "Build Rime as shared library" ON)
option(BUILD_MERGED_PLUGINS "Merge plugins into one Rime library" ON)
option(BUILD_STATIC "Build with dependencies as static libraries" OFF)
option(BUILD_DATA "Build data for Rime" OFF)
option(BUILD_SAMPLE "Build sample Rime plugin" OFF)
option(BUILD_TEST "Build and run tests" ON)
option(BUILD_SEPARATE_LIBS "Build separate rime-* libraries" OFF)
option(ENABLE_LOGGING "Enable logging with google-glog library" ON)
option(ALSO_LOG_TO_STDERR "Log to stderr as well as log file" OFF)
option(ENABLE_ASAN "Enable Address Sanitizer (Unix Only)" OFF)
option(INSTALL_PRIVATE_HEADERS "Install private headers (usually needed for externally built Rime plugins)" OFF)
option(ENABLE_EXTERNAL_PLUGINS "Enable loading of externally built Rime plugins (from directory set by RIME_PLUGINS_DIR variable)" OFF)
option(ENABLE_THREADING "Enable threading for deployer" ON)
option(ENABLE_TIMESTAMP "Embed timestamp to schema artifacts" ON)
set(RIME_DATA_DIR "rime-data" CACHE STRING "Target directory for Rime data")
set(RIME_PLUGINS_DIR "rime-plugins" CACHE STRING "Target directory for externally built Rime plugins")
if(WIN32)
set(ext ".exe")
endif(WIN32)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "${PROJECT_SOURCE_DIR}")
if (ENABLE_ASAN)
set(asan_cflags "-fsanitize=address -fno-omit-frame-pointer")
set(asan_lflags "-fsanitize=address -lasan")
set(CMAKE_C_FLAGS "${asan_cflags} ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${asan_cflags} ${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${asan_lflags} ${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${asan_lflags} ${CMAKE_SHARED_LINKER_FLAGS}")
endif()
set(Boost_USE_STATIC_LIBS ${BUILD_STATIC})
set(Gflags_STATIC ${BUILD_STATIC})
set(Glog_STATIC ${BUILD_STATIC})
set(LevelDb_STATIC ${BUILD_STATIC})
set(Marisa_STATIC ${BUILD_STATIC})
set(Opencc_STATIC ${BUILD_STATIC})
set(YamlCpp_STATIC ${BUILD_STATIC})
set(Boost_USE_MULTITHREADED ON)
if(MSVC)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
if(LINUX)
find_package(Boost 1.74.0 REQUIRED COMPONENTS regex)
else()
find_package(Boost 1.77.0)
endif()
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_definitions(-DBOOST_DLL_USE_STD_FS)
endif()
if(ENABLE_LOGGING)
find_package(Gflags)
if(Gflags_FOUND)
include_directories(${Gflags_INCLUDE_PATH})
endif()
find_package(Glog REQUIRED)
if(Glog_FOUND)
include_directories(${Glog_INCLUDE_PATH})
if(WIN32)
add_compile_definitions("GLOG_DEPRECATED=__declspec(deprecated)")
add_compile_definitions(GLOG_NO_ABBREVIATED_SEVERITIES)
else()
add_compile_definitions("GLOG_DEPRECATED=__attribute__((deprecated))")
endif()
if(Glog_STATIC)
add_compile_definitions(GLOG_EXPORT=)
add_compile_definitions(GLOG_NO_EXPORT=)
else()
add_compile_definitions("GLOG_EXPORT=__attribute__((visibility(\"default\")))")
add_compile_definitions("GLOG_NO_EXPORT=__attribute__((visibility(\"default\")))")
endif()
endif()
set(RIME_ENABLE_LOGGING 1)
if (ALSO_LOG_TO_STDERR)
set(RIME_ALSO_LOG_TO_STDERR 1)
endif()
endif()
find_package(Threads)
if(NOT ENABLE_THREADING)
add_definitions(-DRIME_NO_THREADING)
endif()
if(NOT ENABLE_TIMESTAMP)
add_definitions(-DRIME_NO_TIMESTAMP)
endif()
if(BUILD_TEST)
find_package(GTest REQUIRED)
if(GTEST_FOUND)
enable_testing()
include_directories(${GTEST_INCLUDE_DIRS})
endif()
endif()
find_package(YamlCpp REQUIRED)
if(YamlCpp_FOUND)
include_directories(${YamlCpp_INCLUDE_PATH})
endif()
if(YamlCpp_STATIC)
add_definitions(-DYAML_CPP_STATIC_DEFINE)
endif()
find_package(LevelDb REQUIRED)
if(LevelDb_FOUND)
include_directories(${LevelDb_INCLUDE_PATH})
endif()
find_package(Marisa REQUIRED)
if(Marisa_FOUND)
include_directories(${Marisa_INCLUDE_PATH})
endif()
find_package(Opencc REQUIRED)
if(Opencc_FOUND)
include_directories(${Opencc_INCLUDE_PATH})
endif()
if(Opencc_STATIC)
add_definitions(-DOpencc_BUILT_AS_STATIC)
endif()
find_path(X11Keysym X11/keysym.h)
if(X11Keysym)
message(STATUS "Found X11/keysym.h at ${X11Keysym}")
include_directories(${X11Keysym})
else()
message(WARNING "X11/keysym.h not found.")
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/src/rime/build_config.h.in"
"${PROJECT_BINARY_DIR}/src/rime/build_config.h")
include_directories(${PROJECT_BINARY_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
if(MSVC)
# https://stackoverflow.com/a/31264946
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
add_definitions("/wd4244 /wd4996")
# large address aware
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /LARGEADDRESSAWARE")
endif()
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
if (NOT CMAKE_BUILD_PARALLEL_LEVEL)
include(ProcessorCount)
ProcessorCount(N)
if (NOT N EQUAL 0)
set(CMAKE_BUILD_PARALLEL_LEVEL ${N})
endif()
endif()
# keep these variables lest some Rime plugin's cmake file is still using them {
if(NOT DEFINED LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT DEFINED BIN_INSTALL_DIR)
set(BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR})
endif()
# }
# remove target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(remove
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux|FreeBSD|OpenBSD|DragonFly|GNU|Darwin" OR MINGW)
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(bindir "${CMAKE_INSTALL_FULL_BINDIR}")
set(libdir "${CMAKE_INSTALL_FULL_LIBDIR}")
set(pkgdatadir "${CMAKE_INSTALL_FULL_DATADIR}/${RIME_DATA_DIR}")
set(pluginsdir "${CMAKE_INSTALL_FULL_LIBDIR}/${RIME_PLUGINS_DIR}")
set(includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
configure_file(
${PROJECT_SOURCE_DIR}/rime.pc.in
${PROJECT_BINARY_DIR}/rime.pc
@ONLY)
install(FILES ${PROJECT_BINARY_DIR}/rime.pc
DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig)
endif()
install(FILES cmake/RimeConfig.cmake
DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/cmake/rime)
file(GLOB rime_public_header_files ${PROJECT_SOURCE_DIR}/src/*.h)
list(FILTER rime_public_header_files EXCLUDE REGEX .*_impl\.h$)
install(FILES ${rime_public_header_files}
DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR})
if(INSTALL_PRIVATE_HEADERS)
file(GLOB rime_private_header_files
${PROJECT_SOURCE_DIR}/src/rime/*.h
${PROJECT_BINARY_DIR}/src/rime/*.h)
install(FILES ${rime_private_header_files}
DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/rime)
foreach(rime_private_header_files_dir algo config dict gear lever)
file(GLOB rime_private_header_files
${PROJECT_SOURCE_DIR}/src/rime/${rime_private_header_files_dir}/*.h)
install(FILES ${rime_private_header_files}
DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/rime/${rime_private_header_files_dir})
endforeach()
endif()
if(BUILD_DATA)
file(GLOB rime_preset_data_files ${PROJECT_SOURCE_DIR}/data/preset/*.yaml)
install(FILES ${rime_preset_data_files} DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/${RIME_DATA_DIR})
endif()
if(BUILD_SHARED_LIBS)
add_definitions(-DRIME_BUILD_SHARED_LIBS)
set(rime_library rime)
if(BUILD_SEPARATE_LIBS)
set(rime_dict_library rime-dict)
set(rime_gears_library rime-gears)
set(rime_levers_library rime-levers)
endif()
else()
set(rime_library rime-static)
endif()
add_subdirectory(plugins)
message(STATUS "rime_plugins_libs: ${rime_plugins_deps}")
message(STATUS "rime_plugins_modules: ${rime_plugins_modules}")
set(list "")
foreach(mod ${rime_plugins_modules})
set(list "${list},Q(${mod})")
endforeach()
add_definitions(-DRIME_EXTRA_MODULES=${list})
if(BUILD_SHARED_LIBS AND BUILD_SEPARATE_LIBS AND rime_plugins_objs)
set(rime_plugins_library rime-plugins)
endif()
add_subdirectory(src)
if(BUILD_SHARED_LIBS)
add_subdirectory(tools)
if(BUILD_TEST)
add_subdirectory(test)
endif()
if (BUILD_SAMPLE)
add_subdirectory(sample)
endif()
endif()