Debian Codegraph @

src/CMakeLists.txt

raw
1 include (GenerateExportHeader)
2
3 include_directories("${PROJECT_BINARY_DIR}/src")
4 include_directories("${PROJECT_SOURCE_DIR}/src")
5
6 if(NOT USE_SYSTEM_MARISA)
7 include_directories(SYSTEM ../deps/marisa-0.3.1/include)
8 endif()
9 if(NOT USE_SYSTEM_RAPIDJSON)
10 include_directories(SYSTEM ../deps/rapidjson-1.1.0)
11 endif()
12 if(NOT USE_SYSTEM_TCLAP)
13 include_directories(SYSTEM ../deps/tclap-1.2.5)
14 endif()
15
16 # Library
17
18 set(
19 LIBOPENCC_HEADERS
20 Common.hpp
21 Config.hpp
22 Conversion.hpp
23 ConversionChain.hpp
24 ConversionInspection.hpp
25 Converter.hpp
26 Dict.hpp
27 DictEntry.hpp
28 DictGroup.hpp
29 Exception.hpp
30 Export.hpp
31 Lexicon.hpp
32 MarisaDict.hpp
33 MaxMatchSegmentation.hpp
34 Optional.hpp
35 ResourceProvider.hpp
36 Segmentation.hpp
37 Segments.hpp
38 SerializableDict.hpp
39 SimpleConverter.hpp
40 TextDict.hpp
41 UTF8Util.hpp
42 opencc.h
43 )
44
45 set(
46 LIBOPENCC_PRIVATE_HEADERS
47 ConfigBasedConverter.hpp
48 DictConverter.hpp
49 PhraseExtract.hpp
50 PipelineConverter.hpp
51 PluginSegmentation.hpp
52 PrefixMatch.hpp
53 SerializedValues.hpp
54 SingleStageConverter.hpp
55 UTF8StringSlice.hpp
56 )
57
58 set(
59 LIBOPENCC_SOURCES
60 Config.cpp
61 Conversion.cpp
62 ConversionChain.cpp
63 Converter.cpp
64 Dict.cpp
65 DictConverter.cpp
66 DictEntry.cpp
67 DictGroup.cpp
68 Lexicon.cpp
69 MarisaDict.cpp
70 MaxMatchSegmentation.cpp
71 PhraseExtract.cpp
72 PipelineConverter.cpp
73 PluginSegmentation.cpp
74 PrefixMatch.cpp
75 SingleStageConverter.cpp
76 ResourceProvider.cpp
77 SerializableDict.cpp
78 SerializedValues.cpp
79 SimpleConverter.cpp
80 Segmentation.cpp
81 TextDict.cpp
82 UTF8StringSlice.cpp
83 UTF8Util.cpp
84 )
85
86 set(UNITTESTS
87 ConfigTest
88 ConversionChainTest
89 ConversionInspectionTest
90 ConversionTest
91 DictGroupTest
92 LexiconAnnotationTest
93 MarisaDictTest
94 MaxMatchSegmentationTest
95 PhraseExtractTest
96 PrefixMatchTest
97 SerializedValuesTest
98 SimpleConverterTest
99 TextDictTest
100 UTF8StringSliceTest
101 UTF8UtilTest
102 )
103
104 include_directories(SYSTEM ../deps/darts-clone-0.32h/include)
105 set(
106 LIBOPENCC_PRIVATE_HEADERS
107 ${LIBOPENCC_PRIVATE_HEADERS}
108 BinaryDict.hpp
109 DartsDict.hpp
110 )
111 set(
112 LIBOPENCC_SOURCES
113 ${LIBOPENCC_SOURCES}
114 BinaryDict.cpp
115 DartsDict.cpp
116 )
117 set(
118 UNITTESTS
119 ${UNITTESTS}
120 BinaryDictTest
121 DartsDictTest
122 )
123
124 if (WIN32)
125 set(RC_FILE_DESCRIPTION "Open Chinese Convert Library")
126 set(RC_INTERNAL_NAME "opencc")
127 set(RC_ORIGINAL_FILENAME "opencc.dll")
128 set(RC_FILE_TYPE "VFT_DLL")
129 configure_file(
130 "${PROJECT_SOURCE_DIR}/src/version.rc.in"
131 "${CMAKE_CURRENT_BINARY_DIR}/version_libopencc.rc"
132 @ONLY
133 )
134 list(APPEND LIBOPENCC_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/version_libopencc.rc")
135 endif()
136
137 add_library(libopencc
138 ${LIBOPENCC_SOURCES}
139 ${LIBOPENCC_HEADERS}
140 ${LIBOPENCC_PRIVATE_HEADERS}
141 )
142 add_library(OpenCC::OpenCC ALIAS libopencc)
143 set_target_properties(libopencc PROPERTIES POSITION_INDEPENDENT_CODE ON)
144 source_group(libopencc FILES
145 ${LIBOPENCC_SOURCES}
146 ${LIBOPENCC_HEADERS}
147 ${LIBOPENCC_PRIVATE_HEADERS}
148 )
149 target_link_libraries(libopencc marisa)
150 if (NOT BUILD_SHARED_LIBS)
151 target_compile_definitions(libopencc PUBLIC Opencc_BUILT_AS_STATIC)
152 endif()
153 # PluginSegmentation.cpp uses LoadLibrary on _WIN32 (MSVC and MinGW).
154 # Only non-Windows targets may need libdl for dlopen.
155 if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
156 include(CheckLibraryExists)
157 check_library_exists(dl dlopen "" HAVE_LIBDL)
158 if (HAVE_LIBDL)
159 target_link_libraries(libopencc dl)
160 endif ()
161 endif ()
162 target_include_directories(libopencc PUBLIC
163 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
164 $<INSTALL_INTERFACE:${DIR_INCLUDE}/opencc>
165 )
166
167 GENERATE_EXPORT_HEADER(
168 libopencc
169 BASE_NAME OPENCC
170 EXPORT_MACRO_NAME OPENCC_EXPORT
171 EXPORT_FILE_NAME Opencc_Export.h
172 STATIC_DEFINE Opencc_BUILT_AS_STATIC
173 )
174
175 set_target_properties(
176 libopencc
177 PROPERTIES
178 LINKER_LANGUAGE
179 CXX
180 OUTPUT_NAME
181 opencc
182 EXPORT_NAME
183 OpenCC
184 VERSION
185 ${OPENCC_VERSION_MAJOR}.${OPENCC_VERSION_MINOR}.${OPENCC_VERSION_REVISION}
186 SOVERSION
187 ${OPENCC_ABI_VERSION}
188 )
189
190 # Installation
191
192 if (USE_SYSTEM_MARISA)
193 set(INSTALL_TARGETS libopencc)
194 else()
195 set(INSTALL_TARGETS libopencc marisa)
196 endif()
197
198 if(OPENCC_ENABLE_INSTALL)
199 install(
200 TARGETS ${INSTALL_TARGETS} EXPORT ${OPENCC_TARGETS_EXPORT_NAME}
201 LIBRARY DESTINATION ${DIR_LIBRARY}
202 ARCHIVE DESTINATION ${DIR_LIBRARY}
203 RUNTIME DESTINATION bin
204 )
205
206 install(
207 EXPORT ${OPENCC_TARGETS_EXPORT_NAME}
208 FILE ${OPENCC_TARGETS_EXPORT_NAME}.cmake
209 DESTINATION ${DIR_LIBRARY}/cmake/opencc
210 NAMESPACE OpenCC::
211 )
212
213 install(
214 FILES ${LIBOPENCC_HEADERS}
215 DESTINATION ${DIR_INCLUDE}/opencc
216 )
217
218 install(
219 FILES plugin/OpenCCPlugin.h
220 DESTINATION ${DIR_INCLUDE}/opencc/plugin
221 )
222 endif()
223
224 # Gtest
225
226 if (ENABLE_GTEST)
227 if (WIN32)
228 add_custom_target(
229 copy_gtest_to_src
230 ${CMAKE_COMMAND} -E copy $<TARGET_FILE:gtest> ${CMAKE_CURRENT_BINARY_DIR}
231 COMMENT "Copying gtest to src"
232 )
233 add_custom_target(
234 copy_gtest_main_to_src
235 ${CMAKE_COMMAND} -E copy $<TARGET_FILE:gtest_main> ${CMAKE_CURRENT_BINARY_DIR}
236 COMMENT "Copying gtest_main to src"
237 )
238 endif()
239
240 foreach(TESTCASE ${UNITTESTS})
241 add_executable(${TESTCASE} ${TESTCASE}.cpp)
242 target_link_libraries(${TESTCASE} gtest gtest_main libopencc)
243 add_test(${TESTCASE} ${TESTCASE})
244 if (WIN32)
245 add_dependencies(${TESTCASE} copy_gtest_to_src copy_gtest_main_to_src)
246 endif()
247 endforeach()
248 endif()
249
250 # Benchmark
251
252 if (ENABLE_BENCHMARK)
253 add_subdirectory(benchmark)
254 endif()
255
256 # Subdir
257
258 add_subdirectory(tools)