-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
343 lines (300 loc) · 11.7 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# Copyright 2019-2022 CEA LIST
# SPDX-FileCopyrightText: 2019-2022 CEA LIST <[email protected]>
#
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.18)
cmake_policy(VERSION 3.15)
# Enable policy to not use RPATH settings for install_name on macOS.
if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
endif()
cmake_policy(SET CMP0094 NEW)
# Consider changing the project name to something relevant for you.
project(LimaBinding)
find_package(Python3 COMPONENTS Interpreter Development.Embed REQUIRED)
#find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
message(STATUS "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}")
#find_package(PythonExtensions REQUIRED)
find_package(Qt6 REQUIRED Core)
get_target_property(QtCore_location Qt::Core LOCATION)
get_filename_component(QtCore_libdir ${QtCore_location} DIRECTORY)
set(CMAKE_AUTOMOC ON)
# find_path and find_library will search in these dirs too
set(CMAKE_PREFIX_PATH
"$ENV{LIMA_DIST}/share/apps/lima/cmake/Modules"
"/usr/share/apps/lima/cmake/Modules" # for those available on the system
"/usr/local/share/apps/lima/cmake/Modules" # for those available on the system
)
add_definitions(-D QT_NO_KEYWORDS)
include(${CMAKE_SOURCE_DIR}/manageQt.cmake)
addQtModules(Core Xml Test Qml Quick QuickTest Gui Widgets)
find_package(LIMACOMMON REQUIRED)
include_directories(BEFORE ${LIMACOMMON_INCLUDE_DIR})
find_package(LIMALP REQUIRED)
include_directories(BEFORE ${LIMALP_INCLUDE_DIR})
link_directories(${LIMACOMMON_LIBRARY_DIRS})
# ================================ General configuration ======================================
set(CMAKE_CXX_STANDARD 17)
# The sample library for which we will create bindings. You can change the name to something
# relevant for your project.
set(sample_library "liblimabinding")
# The name of the generated bindings module (as imported in Python). You can change the name
# to something relevant for your project.
set(bindings_library "cpplima")
# The header file with all the types and functions for which bindings will be generated.
# Usually it simply includes other headers of the library you are creating bindings for.
set(wrapped_header ${CMAKE_SOURCE_DIR}/bindings.h)
# The typesystem xml file which defines the relationships between the C++ types / functions
# and the corresponding Python equivalents.
set(typesystem_file ${CMAKE_SOURCE_DIR}/bindings.xml)
# Specify which C++ files will be generated by shiboken. This includes the module wrapper
# and a '.cpp' file per C++ type. These are needed for generating the module shared
# library.
# If you forget the cpp file defining the class Doc for example, you will get an undefined
# symbol error of your Doc class mangled name. Something like:
# ImportError: …/python3.8/site-packages/<your package>/<you lib>.so: undefined symbol: _Z8init_DocP7_object
set(generated_sources
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_module_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/limaanalyzer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/doc_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/span_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/token_wrapper.cpp
)
set(Python3_FIND_VIRTUALENV ONLY)
#find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
if(NOT python_interpreter)
find_program(python_interpreter "python$ENV{PYTHON_VERSION}")
endif()
set(PYSIDE6_DIR ${Python3_SITELIB}/PySide6)
# macro(pyside_config option output_var)
# if(${ARGC} GREATER 2)
# set(is_list ${ARGV2})
# else()
# set(is_list "")
# endif()
#
# execute_process(
# COMMAND ${python_interpreter} "${PYSIDE6_DIR}/examples/utils/pyside_config.py"
# ${option}
# OUTPUT_VARIABLE ${output_var}
# OUTPUT_STRIP_TRAILING_WHITESPACE)
#
# if ("${${output_var}}" STREQUAL "")
# message(FATAL_ERROR "Error: Calling pyside_config.py ${option} returned no output.")
# endif()
# if(is_list)
# string (REPLACE " " ";" ${output_var} "${${output_var}}")
# endif()
# endmacro()
set(shiboken_module_path "/opt/_internal/cpython-3.7.15/lib/python3.7/site-packages/shiboken6")
set(shiboken_generator_path "/opt/_internal/cpython-3.7.15/bin")
set(python_include_dir "${PYTHON_INCLUDE_DIR}")
set(shiboken_include_dir "/opt/_internal/cpython-3.7.15/lib/python3.7/site-packages/shiboken6_generator/include")
set(shiboken_shared_libraries "/opt/_internal/cpython-3.7.15/lib/python3.7/site-packages/shiboken6/libshiboken6.abi3.so.6.5")
set(pyside_link "/opt/_internal/cpython-3.7.15/lib/python3.7/site-packages/PySide6/libpyside6.abi3.so.6.5")
# pyside_config(--shiboken-module-path shiboken_module_path)
# pyside_config(--shiboken-generator-path shiboken_generator_path)
# pyside_config(--python-include-path python_include_dir)
# pyside_config(--shiboken-generator-include-path shiboken_include_dir 1)
# pyside_config(--shiboken-module-shared-libraries-cmake shiboken_shared_libraries 0)
# pyside_config(--pyside-shared-libraries-cmake pyside_link 0)
#
set(shiboken_path "${shiboken_generator_path}/shiboken6")
if(NOT EXISTS ${shiboken_path})
message(FATAL_ERROR "Shiboken executable not found at path: ${shiboken_path}")
endif()
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH ${shiboken_module_path} ${CMAKE_CURRENT_SOURCE_DIR} ${QtCore_libdir})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(${sample_library}_sources lima.cpp Doc.cpp Span.cpp Token.cpp)
add_library(${sample_library} SHARED ${${sample_library}_sources})
target_link_libraries(${sample_library}
fasttext-lima
lima-common-datahandler
lima-common-data
lima-common-factory
lima-common-fsaaccess
lima-common-mediaprocessors
lima-common-mediaticdata
lima-common-misc
lima-common-processunitframework
lima-common
lima-common-time
lima-common-tools
lima-common-xmlconfigurationfiles
lima-linguisticprocessing
lima-lp-analysisdict
lima-lp-analysisdumpers
lima-lp-analysishandlers
lima-lp-applyrecognizer
lima-lp-automatoncompiler
lima-lp-automaton
lima-lp-bagofwords
lima-lp-client
lima-lp-compounds
lima-lp-conllureader
lima-lp-corefsolver
lima-lp-dictionary
lima-lp-entitytracker
lima-lp-eventanalyzer
lima-lp-flattokenizer
lima-lp-helpers
lima-lp-langdetector
lima-lp-lineartextrepresentation
lima-lp-linguisticanalysisstructure
lima-lp-linguisticdata
lima-lp-linguisticprocessing-core
lima-lp-linguisticprocessors
lima-lp-linguisticresources
lima-lp-misc
lima-lp-morphologicanalysis
lima-lp-postagger
lima-lp-propertycode
lima-lp-regexmatcher
lima-lp-se-datetime
lima-lp-semanticanalysis
lima-lp-se-number
lima-lp-se-person
lima-lp-specificentities
lima-lp-syntacticanalysis
lima-lp-tensorflowlemmatizer
lima-lp-tensorflowmorphosyntax
lima-lp-tensorflowspecificentities
lima-lp-tensorflowtokenizer
lima-lp-textsegmentation
lima-lp-tgv
lima-lp-wordsensetagger
lima-xp-client
lima-xp-core
lima-xp-documentsreader
lima-xp-qtsgmlentities
tensorflow-for-lima
Qt::Core
)
set_property(TARGET ${sample_library} PROPERTY PREFIX "")
get_target_property(qtcore_lib_includes Qt::Core INTERFACE_INCLUDE_DIRECTORIES)
list(JOIN qtcore_lib_includes ";-I" lib_includes)
set(lib_includes "-I${lib_includes}")
target_compile_definitions(${sample_library} PRIVATE BINDINGS_BUILD)
set(shiboken_options --generator-set=shiboken
--enable-parent-ctor-heuristic
--enable-return-value-heuristic
--use-isnull-as-nb_nonzero
--avoid-protected-hack
--enable-pyside-extensions
--language-level=c++17
--no-suppress-warnings
--debug-level=full
${lib_includes}
-I${CMAKE_SOURCE_DIR}
-I/opt/lima/include/
-I/opt/qt6/include/
-I/opt/qt6/include/QtCore
-T${CMAKE_SOURCE_DIR}
-T${PYSIDE6_DIR}/typesystems/
--output-directory=${CMAKE_CURRENT_BINARY_DIR}
)
set(generated_sources_dependencies ${wrapped_header} ${typesystem_file})
add_custom_command(OUTPUT ${generated_sources}
COMMAND ${shiboken_path}
${shiboken_options} ${wrapped_header} ${typesystem_file}
DEPENDS ${generated_sources_dependencies}
IMPLICIT_DEPENDS CXX ${wrapped_header}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running generator for ${typesystem_file}.")
set(${bindings_library}_sources ${generated_sources})
add_library(${bindings_library} MODULE ${${bindings_library}_sources})
#python_extension_module(${bindings_library})
target_include_directories(${bindings_library} PRIVATE ${python_include_dir})
target_include_directories(${bindings_library} PRIVATE ${PYSIDE6_DIR}/include/)
target_include_directories(${bindings_library} PRIVATE ${PYSIDE6_DIR}/include/QtCore)
target_include_directories(${bindings_library} PRIVATE ${shiboken_include_dir})
target_include_directories(${bindings_library} PRIVATE ${CMAKE_SOURCE_DIR})
target_link_libraries(${bindings_library} PRIVATE ${shiboken_shared_libraries})
target_link_libraries(${bindings_library} PRIVATE ${sample_library})
target_link_libraries(${bindings_library} PRIVATE ${pyside_link})
target_link_libraries(${bindings_library} PRIVATE
fasttext-lima
lima-common-data
lima-common-datahandler
lima-common-factory
lima-common-fsaaccess
lima-common-mediaprocessors
lima-common-mediaticdata
lima-common-misc
lima-common-processunitframework
lima-common-time
lima-common-tools
lima-common-xmlconfigurationfiles
lima-common
lima-linguisticprocessing
lima-lp-analysisdict
lima-lp-analysisdumpers
lima-lp-analysishandlers
lima-lp-annotationgraph
lima-lp-applyrecognizer
lima-lp-automaton
lima-lp-automatoncompiler
lima-lp-bagofwords
lima-lp-client
lima-lp-compounds
lima-lp-conllureader
lima-lp-corefsolver
lima-lp-dictionary
lima-lp-entitytracker
lima-lp-eventanalyzer
lima-lp-flattokenizer
lima-lp-helpers
lima-lp-langdetector
lima-lp-lineartextrepresentation
lima-lp-linguisticanalysisstructure
lima-lp-linguisticdata
lima-lp-linguisticprocessing-core
lima-lp-linguisticprocessors
lima-lp-linguisticresources
lima-lp-misc
lima-lp-morphologicanalysis
lima-lp-postagger
lima-lp-propertycode
lima-lp-regexmatcher
lima-lp-rnn-dependency-parser
lima-lp-rnn-ner
lima-lp-rnn-tokenizer
lima-lp-rnn-tokens-analyzer
lima-lp-se-datetime
lima-lp-se-number
lima-lp-se-person
lima-lp-semanticanalysis
lima-lp-specificentities
lima-lp-syntacticanalysis
lima-lp-tensorflowlemmatizer
lima-lp-tensorflowmorphosyntax
lima-lp-tensorflowspecificentities
lima-lp-tensorflowtokenizer
lima-lp-textsegmentation
lima-lp-tgv
lima-lp-wordsensetagger
lima-xp-client
lima-xp-core
lima-xp-documentsreader
lima-xp-qtsgmlentities
svmtool
tensorflow-for-lima
torch
torch_cpu
xcb
)
set_property(TARGET ${bindings_library} PROPERTY PREFIX "")
set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME
"${bindings_library}${PYTHON_EXTENSION_SUFFIX}")
#set(site_packages "${Python3_SITELIB}")
#message("site_packages ${Python3_SITELIB}")
#install(FILES aymaralima/lima_analyzer.py aymaralima/lima_models.py aymaralima/deeplima_models.py DESTINATION ${site_packages}/aymaralima)
install(FILES aymara/lima.py aymara/lima_models.py aymara/deeplima_models.py DESTINATION aymara)
file(GLOB LIB_FILES ${PROJECT_SOURCE_DIR}/clib/lib/lib*.so*)
install(FILES ${LIB_FILES} DESTINATION aymaralima)
install(TARGETS ${bindings_library} ${sample_library}
LIBRARY DESTINATION aymaralima
RUNTIME DESTINATION aymaralima
)