forked from manicki/psi-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
885 lines (726 loc) · 32.2 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
cmake_minimum_required(VERSION 3.1)
cmake_policy(SET CMP0026 OLD)
cmake_policy(SET CMP0038 OLD)
project(psi-toolkit CXX)
if(CMAKE_SIZEOF_VOID_P MATCHES "8")
SET(CPU_ARCH "amd64")
else(CMAKE_SIZEOF_VOID_P MATCHES "8")
SET(CPU_ARCH "i386")
endif(CMAKE_SIZEOF_VOID_P MATCHES "8")
SET(MY_TARGETLIB_PREFIX "libpsitoolkit_")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
include_directories(${psi-toolkit_SOURCE_DIR})
# coverage mode
if(CMAKE_CONFIGURATION_TYPES)
list(APPEND CMAKE_CONFIGURATION_TYPES Coverage)
list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
"Add the configurations that we need"
FORCE)
endif()
SET( CMAKE_CXX_FLAGS_COVERAGE "-g -pg -Wall -Wundef -Wnon-virtual-dtor -Wextra -fprofile-arcs -ftest-coverage -fPIC" CACHE STRING
"Flags used by the C++ compiler during maintainer builds."
FORCE )
SET( CMAKE_C_FLAGS_COVERAGE "-g -pg -Wall -pedantic -fprofile-arcs -ftest-coverage -fPIC" CACHE STRING
"Flags used by the C compiler during maintainer builds."
FORCE )
SET( CMAKE_EXE_LINKER_FLAGS_COVERAGE
"-g -pg -Wl,--warn-unresolved-symbols,--warn-once -fprofile-arcs -ftest-coverage -fPIC" CACHE STRING
"Flags used for linking binaries during maintainer builds."
FORCE )
SET( CMAKE_SHARED_LINKER_FLAGS_COVERAGE
"-g -pg -Wl,--warn-unresolved-symbols,--warn-once -fprofile-arcs -ftest-coverage -fPIC" CACHE STRING
"Flags used by the shared libraries linker during maintainer builds."
FORCE )
MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE)
# extracting information from git, see http://stackoverflow.com/questions/1435953/how-can-i-pass-git-sha1-to-compiler-as-definition-using-cmake
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules/")
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
git_last_date(GIT_LAST_DATE)
# ====================================================
# Options for installable version
# ====================================================
set(PSITOOLKIT_INSTALL_DATA_DIR share/psi-toolkit)
set(INSTALL_DATA_DIR "${CMAKE_INSTALL_PREFIX}/${PSITOOLKIT_INSTALL_DATA_DIR}")
option(IS_INSTALLABLE "Is prepared for install" OFF)
message(STATUS "Is prepared for install ${IS_INSTALLABLE}")
set(PACKAGE_OS_NAME default)
option(PACKAGE_OS_NAME "Name of the operating system for package generation" default)
if(PACKAGE_OS_NAME STREQUAL ubuntu)
set(PACKAGE_OS 1)
elseif(PACKAGE_OS_NAME STREQUAL archlinux)
set(PACKAGE_OS 2)
else()
set(PACKAGE_OS -1)
endif()
if(PACKAGE_OS GREATER 0)
message("-- Setting package os variable to: ${PACKAGE_OS_NAME} (${PACKAGE_OS})")
else()
message("-- Setting default package os")
endif()
option(DOWNLOAD_DATA "Downloading data (artifacts)" ON)
message(STATUS "Downloading data (artifacts) ${DOWNLOAD_DATA}")
# setting PSI-Server variables
if(IS_INSTALLABLE)
# ./server/website content has to be moved to /var/psi-server/website during installation
set(WEBSITE_ROOT "/var/lib/psi-server/website" CACHE STRING "The website root directory")
else(IS_INSTALLABLE)
set(WEBSITE_ROOT "../server/website" CACHE STRING "The website root directory")
endif(IS_INSTALLABLE)
message(STATUS "The psi-server root directory is set to ${WEBSITE_ROOT}")
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
# Install bash-completion scripts
install(FILES psi-pipe DESTINATION /etc/bash_completion.d)
install(FILES psi-server DESTINATION /etc/bash_completion.d)
# ====================================================
# Finds and includes external libraries
# ====================================================
# ----------------------------------------------------
# Boost
# ----------------------------------------------------
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost COMPONENTS program_options graph serialization filesystem system thread
unit_test_framework prg_exec_monitor REQUIRED)
# ----------------------------------------------------
# Logging
# ----------------------------------------------------
find_library(LOG4CPP_LIB NAMES log4cpp)
find_path(LOG4CPP_INCLUDE log4cpp/Appender.hh)
if(EXISTS ${LOG4CPP_LIB} AND EXISTS ${LOG4CPP_INCLUDE})
message(STATUS "Found Log4cpp")
include_directories(${LOG4CPP_INCLUDE})
link_directories(${LOG4CPP_LIB})
set(HAVE_LOG4CPP 1)
else()
message(WARNING "Log4cpp not found")
set(HAVE_LOG4CPP 0)
endif(EXISTS ${LOG4CPP_LIB} AND EXISTS ${LOG4CPP_INCLUDE})
# ----------------------------------------------------
# Aspell
# ----------------------------------------------------
option(USE_ASPELL "Using aspell" ON)
message(STATUS "Using aspell ${USE_ASPELL}")
if (USE_ASPELL)
find_library(ASPELL_LIB NAMES aspell)
find_path(ASPELL_INCLUDE aspell.h)
if(EXISTS ${ASPELL_LIB} AND EXISTS ${ASPELL_INCLUDE})
message(STATUS "Found Aspell")
include_directories(${ASPELL_INCLUDE})
link_directories(${ASPELL_LIB})
link_directories("${psi-toolkit_BINARY_DIR}/tools/spellcheckers/aspell/plugin")
set(HAVE_ASPELL 1)
else()
message(WARNING "Aspell not found: aspell disabled")
set(HAVE_ASPELL 0)
endif(EXISTS ${ASPELL_LIB} AND EXISTS ${ASPELL_INCLUDE})
else()
set(HAVE_ASPELL 0)
endif(USE_ASPELL)
# ----------------------------------------------------
# Finds OpenFST
# ----------------------------------------------------
option(USE_IAYKO "Using iayko normalizer" ON)
message(STATUS "Using iayko normalizer ${USE_IAYKO}")
if (USE_IAYKO)
find_package(OpenFST)
if (OPENFST_FOUND)
message(STATUS "Found OpenFST")
include_directories(${OPENFST_INCLUDE_DIRS})
message(STATUS "OpenFST include directories: ${OPENFST_INCLUDE_DIRS}")
link_directories(${OPENFST_LIBRARIES})
link_directories("${psi-toolkit_BINARY_DIR}/tools/normalizers/iayko/plugin")
set(HAVE_OPENFST 1)
else (OPENFST_FOUND)
message(WARNING "OpenFST not found: iayko normalizer disabled")
set(HAVE_OPENFST 0)
endif (OPENFST_FOUND)
else (USE_IAYKO)
set(HAVE_OPENFST 0)
endif (USE_IAYKO)
# ----------------------------------------------------
# CMPH library (for perfect hashing)
# ----------------------------------------------------
find_library(CMPH_LIB NAMES cmph)
find_path(CMPH_INCLUDE cmph.h)
if(EXISTS ${CMPH_LIB} AND EXISTS ${CMPH_INCLUDE})
message(STATUS "Found CMPH")
include_directories(${CMPH_INCLUDE})
link_directories(${CMPH_LIB})
set(HAVE_CMPH 1)
else()
message(WARNING "CMPH not found")
set(HAVE_CMPH 0)
endif(EXISTS ${CMPH_LIB} AND EXISTS ${CMPH_INCLUDE})
# ----------------------------------------------------
# SFST library (for TRmorph)
# ----------------------------------------------------
option(USE_SFST "Using SFST" ON)
message(STATUS "Using SFST ${USE_SFST}")
if (USE_SFST)
find_path(SFST_LIB libsfst.so /usr/lib/sfst)
find_path(SFST_LIB libsfst.so /usr/lib)
find_path(SFST_INCLUDE fst.h /usr/include/sfst)
if(EXISTS ${SFST_LIB} AND EXISTS ${SFST_INCLUDE})
message(STATUS "Found SFST")
include_directories(${SFST_INCLUDE})
link_directories(${SFST_LIB})
link_directories("${psi-toolkit_BINARY_DIR}/tools/lemmatizers/sfst/plugin")
set(HAVE_SFST 1)
else()
message(WARNING "SFST not found")
set(HAVE_SFST 0)
endif(EXISTS ${SFST_LIB} AND EXISTS ${SFST_INCLUDE})
endif (USE_SFST)
# ----------------------------------------------------
# Java components
# ----------------------------------------------------
option(USE_JAVA "Using Java components" OFF)
message(STATUS "Using Java components ${USE_JAVA}")
if(USE_JAVA)
enable_language(Java)
find_package(Java REQUIRED)
find_package(JNI)
if(NOT JNI_FOUND)
message(STATUS "JNI not found using alternative cmake file")
find_package(JNIAlt REQUIRED)
endif(NOT JNI_FOUND)
message(STATUS "Java JVM library: ${JAVA_JVM_LIBRARY}")
message(STATUS "Java AWT include path: ${JAVA_AWT_INCLUDE_PATH}")
string(REGEX REPLACE "(.*)/libjvm.so" "\\1" LD_LIBPATH ${JAVA_JVM_LIBRARY})
message(STATUS "You may need to set LD_LIBRARY_PATH=${LD_LIBPATH} to run installed software")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${LD_LIBPATH}")
include_directories(${JAVA_INCLUDE_PATH})
include_directories(${JAVA_INCLUDE_PATH}/linux)
include_directories("${psi-toolkit_SOURCE_DIR}/common/j")
list(APPEND CMAKE_JAVA_INCLUDE_PATH "${JAVA_INCLUDE_PATH}")
list(APPEND CMAKE_JAVA_INCLUDE_PATH "${psi-toolkit_SOURCE_DIR}/common/j")
set(CMAKE_JAVA_COMPILE_FLAGS "-cp ${CMAKE_JAVA_INCLUDE_PATH}")
message(STATUS "Java include path: ${JAVA_INCLUDE_PATH}")
message(STATUS "CMake Java include path: ${CMAKE_JAVA_INCLUDE_PATH}")
message(STATUS "Java flags: ${CMAKE_JAVA_COMPILE_FLAGS}")
set(HAVE_JAVA 1)
endif(USE_JAVA)
# ----------------------------------------------------
# Finds PostgreSQL
# ----------------------------------------------------
option(USE_POSTGRESQL "Compiling PostgreSQL components" OFF)
message(STATUS "Compiling PostgreSQL components ${USE_POSTGRESQL}")
if(USE_POSTGRESQL)
find_package(PostgreSQL REQUIRED)
include_directories(${PostgreSQL_INCLUDE_DIRS})
link_directories(${PostgreSQL_LIBRARY_DIRS})
set(HAVE_POSTGRESQL 1)
endif(USE_POSTGRESQL)
# ----------------------------------------------------
# Regular expression libraries
# ----------------------------------------------------
option(WITH_RE2 "Using RE2 regular expression library" OFF)
message(STATUS "Using RE2 regular expression library ${WITH_RE2}")
if(WITH_RE2)
set(HAVE_RE2 1)
endif(WITH_RE2)
option(WITH_PCRE "Using PCRE regular expression library" ON)
message(STATUS "Using PCRE regular expression library ${WITH_PCRE}")
if(WITH_PCRE)
set(HAVE_PCRE 1)
endif(WITH_PCRE)
# ----------------------------------------------------
# Bonsai and puddle
# ----------------------------------------------------
option(USE_BONSAI_PARSEGRAPH "Using bonsai ParseGraph with puddle shallow parser" OFF)
message(STATUS "Using bonsai ParseGraph with puddle shallow parser ${USE_BONSAI_PARSEGRAPH}")
option(BONSAI_PATH "Bonsai common path file (required while using ParseGraph)" "/home/user/poleng4/src/bonsai/common")
message(STATUS "Bonsai common path file (required while using ParseGraph) ${BONSAI_PATH}")
option(USE_STRING_FRAG_VALIDATION "Validating string frags" OFF)
message(STATUS "Validating string frags ${USE_STRING_FRAG_VALIDATION}")
if(USE_STRING_FRAG_VALIDATION)
set(STRING_FRAG_VALIDATION 1)
endif(USE_STRING_FRAG_VALIDATION)
# ----------------------------------------------------
# Finds SWIG
# ----------------------------------------------------
find_package(SWIG)
if(SWIG_FOUND)
message(STATUS "Found SWIG version: ${SWIG_VERSION}")
set(HAVE_SWIG_BINDINGS 1)
find_package(PerlLibs)
if(PERLLIBS_FOUND)
set(HAVE_PERL_BINDINGS 1)
include_directories(${PERL_INCLUDE_PATH})
message(STATUS "Have Perl bindings ${HAVE_PERL_BINDINGS}")
GET_FILENAME_COMPONENT(PERL_LIBRARY_DIR ${PERL_LIBRARY} PATH)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}:${PERL_LIBRARY_DIR}")
endif(PERLLIBS_FOUND)
find_package(PythonLibs)
if(PYTHONLIBS_FOUND)
set(HAVE_PYTHON_BINDINGS 1)
include_directories(${PYTHON_INCLUDE_PATH})
message(STATUS "Have Python bindings ${HAVE_PYTHON_BINDINGS}")
endif(PYTHONLIBS_FOUND)
find_package(Ruby)
if(RUBY_FOUND)
set(HAVE_RUBY_BINDINGS 1)
include_directories(${RUBY_INCLUDE_PATH})
message(STATUS "Have Ruby bindings ${HAVE_RUBY_BINDINGS}")
endif(RUBY_FOUND)
endif(SWIG_FOUND)
# ----------------------------------------------------
# Finds GraphViz
# ----------------------------------------------------
option(USE_GV_WRITER "Using gv-writer" ON)
message(STATUS "Using gv-writer ${USE_GV_WRITER}")
if (USE_GV_WRITER)
find_package(Graphviz)
if (GRAPHVIZ_FOUND)
message(STATUS "Found GraphViz, version ${GRAPHVIZ_VERSION}")
message(STATUS "Graphviz graph library is ${GRAPHVIZ_GRAPH_LIBRARY}")
if (${GRAPHVIZ_GRAPH_LIBRARY} MATCHES "cgraph")
set(GRAPHVIZ_CGRAPH 1)
message(STATUS "Graphviz uses cgraph library")
else (${GRAPHVIZ_GRAPH_LIBRARY} MATCHES "cgraph")
set(GRAPHVIZ_CGRAPH 0)
message(STATUS "Graphviz uses graph library")
endif (${GRAPHVIZ_GRAPH_LIBRARY} MATCHES "cgraph")
include_directories(${GRAPHVIZ_INCLUDE_DIRS})
link_directories(${GRAPHVIZ_LIBRARIES})
link_directories("${psi-toolkit_BINARY_DIR}/formats/gv/plugin")
set(HAVE_GRAPHVIZ 1)
else (GRAPHVIZ_FOUND)
message(WARNING "GraphViz not found: gv-writer disabled")
set(HAVE_GRAPHVIZ 0)
endif (GRAPHVIZ_FOUND)
else (USE_GV_WRITER)
set(HAVE_GRAPHVIZ 0)
endif (USE_GV_WRITER)
# ----------------------------------------------------
# Finds LibMagic
# ----------------------------------------------------
find_package(LibMagic)
if(LIBMAGIC_FOUND)
message(STATUS "Found LibMagic")
include_directories(${LibMagic_INCLUDE_DIRS})
link_directories(${LibMagic_LIBRARY})
set(HAVE_LIBMAGIC 1)
else()
message(WARNING "LibMagic not found")
set(HAVE_LIBMAGIC 0)
endif(LIBMAGIC_FOUND)
# ----------------------------------------------------
# Finds Poppler
# ----------------------------------------------------
option(USE_PDF_READER "Using pdf-reader" ON)
message(STATUS "Using pdf-reader ${USE_PDF_READER}")
if (USE_PDF_READER)
find_package(Poppler)
if (POPPLER_FOUND)
message(STATUS "Found Poppler")
include_directories(${POPPLER_INCLUDE_DIRS})
link_directories(${POPPLER_LIBRARIES})
link_directories("${psi-toolkit_BINARY_DIR}/formats/pdf/plugin")
set(HAVE_POPPLER 1)
else (POPPLER_FOUND)
message(WARNING "Poppler not found: pdf-reader disabled")
set(HAVE_POPPLER 0)
endif (POPPLER_FOUND)
else (USE_PDF_READER)
set(HAVE_POPPLER 0)
endif (USE_PDF_READER)
# ----------------------------------------------------
# Finds DjVuLibre
# ----------------------------------------------------
option(USE_DJVU_READER "Using djvu-reader" OFF)
message(STATUS "Using djvu-reader ${USE_DJVU_READER}")
if (USE_DJVU_READER)
find_package(DjVuLibre)
if (DJVULIBRE_FOUND)
message(STATUS "Found DjVuLibre")
include_directories(${DJVULIBRE_INCLUDE_DIRS})
link_directories(${DJVULIBRE_LIBRARIES})
link_directories("${psi-toolkit_BINARY_DIR}/formats/djvu/plugin")
set(HAVE_DJVULIBRE 1)
else (DJVULIBRE_FOUND)
message(WARNING "DjVuLibre not found: djvu-reader disabled")
set(HAVE_DJVULIBRE 0)
endif (DJVULIBRE_FOUND)
else (USE_DJVU_READER)
set(HAVE_DJVULIBRE 0)
endif (USE_DJVU_READER)
# ----------------------------------------------------
# Finds Link Grammar
# ----------------------------------------------------
option(USE_LINK_GRAMMAR "Using link-parser" ON)
message(STATUS "Using link-parser ${USE_LINK_GRAMMAR}")
if (USE_LINK_GRAMMAR)
find_package(LinkGrammar)
if (LINK_GRAMMAR_FOUND)
message(STATUS "Found LinkGrammar")
include_directories(${LINK_GRAMMAR_INCLUDE_DIRS})
link_directories(${LINK_GRAMMAR_LIBRARIES})
link_directories("${psi-toolkit_BINARY_DIR}/tools/parsers/link/plugin")
set(HAVE_LINK_GRAMMAR 1)
else (LINK_GRAMMAR_FOUND)
message(WARNING "LinkGrammar not found: link-parser disabled")
set(HAVE_LINK_GRAMMAR 0)
endif (LINK_GRAMMAR_FOUND)
else (USE_LINK_GRAMMAR)
set(HAVE_LINK_GRAMMAR 0)
endif (USE_LINK_GRAMMAR)
# ----------------------------------------------------
# Links Antiword plugin
# ----------------------------------------------------
option(USE_DOC_READER "Using doc-reader" OFF)
message(STATUS "Using doc-reader ${USE_DOC_READER}")
if (USE_DOC_READER)
link_directories("${psi-toolkit_BINARY_DIR}/formats/doc/plugin")
endif (USE_DOC_READER)
# ----------------------------------------------------
# Flex
# ----------------------------------------------------
if (NOT DEFINED FLEX_PREFIX_OUTPUTS)
set(FLEX_PREFIX_OUTPUTS FALSE)
endif (NOT DEFINED FLEX_PREFIX_OUTPUTS)
if (NOT DEFINED FLEX_GENERATE_DEFINES)
set(FLEX_GENERATE_DEFINES FALSE)
endif (NOT DEFINED FLEX_GENERATE_DEFINES)
if (NOT FLEX_EXECUTABLE)
find_program(FLEX_EXECUTABLE flex)
if (FLEX_EXECUTABLE)
message(STATUS "Found Flex")
else (FLEX_EXECUTABLE)
if (EXISTS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.cpp)
message(STATUS
"Flex not found: file lex.grlex.cpp exists and will be left unchanged")
else (EXISTS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.cpp)
message(WARNING
"Flex not found: file lex.grlex.cpp is missing and cannot be generated\n"
"You should install the `flex` package")
endif (EXISTS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.cpp)
endif (FLEX_EXECUTABLE)
endif (NOT FLEX_EXECUTABLE)
add_custom_target(
flex-grlex ALL
DEPENDS
${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.cpp
)
if (FLEX_EXECUTABLE)
add_custom_command(
OUTPUT ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.cpp
COMMAND ${FLEX_EXECUTABLE}
-P grlex
-o ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.cpp
${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.lpp
DEPENDS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/lex.grlex.lpp
COMMENT "Generating lex.grlex.cpp"
)
endif (FLEX_EXECUTABLE)
# ----------------------------------------------------
# Bison
# ----------------------------------------------------
if (NOT DEFINED BISON_PREFIX_OUTPUTS)
set(BISON_PREFIX_OUTPUTS FALSE)
endif (NOT DEFINED BISON_PREFIX_OUTPUTS)
if (NOT DEFINED BISON_GENERATE_DEFINES)
set(BISON_GENERATE_DEFINES FALSE)
endif (NOT DEFINED BISON_GENERATE_DEFINES)
if (NOT BISON_EXECUTABLE)
message(STATUS "Looking for bison")
find_program(BISON_EXECUTABLE bison)
if (BISON_EXECUTABLE)
message(STATUS "Found Bison")
else (BISON_EXECUTABLE)
if (EXISTS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.bis.cpp)
message(STATUS
"Bison not found: file grparser.bis.cpp exists and will be left unchanged")
else (EXISTS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.bis.cpp)
message(WARNING
"Bison not found: file grparser.bis.cpp is missing and cannot be generated\n"
"You should install the `bison` package")
endif (EXISTS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.bis.cpp)
endif (BISON_EXECUTABLE)
endif (NOT BISON_EXECUTABLE)
add_custom_target(
bison-grparser ALL
DEPENDS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.bis.cpp
)
if (BISON_EXECUTABLE)
add_custom_command(
OUTPUT ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.bis.cpp
COMMAND ${BISON_EXECUTABLE}
-p grparser
-o ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.bis.cpp
${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.y
DEPENDS ${psi-toolkit_SOURCE_DIR}/tools/parsers/gobio/translator/grparser.y
COMMENT "Generating grparser.bis.cpp"
)
endif (BISON_EXECUTABLE)
# ====================================================
# Sets compiler
# ====================================================
set(CMAKE_CXX_FLAGS "-g -Wall -Wundef -Wnon-virtual-dtor -Wextra")
if(WITH_LOW_MEMORY_COMPILATION)
message("Setting low memory compilation flags")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --param ggc-min-expand=30 --param ggc-min-heapsize=8192")
endif(WITH_LOW_MEMORY_COMPILATION)
# ----------------------------------------------------
# BASE_TARGETS
# ----------------------------------------------------
set(BASE_TARGETS common common-plugins utf8case sundown fex tiniconv uchardet framework
formats-apertium formats-bracketing formats-dot formats-guessing formats-morphology formats-phrases formats-nkjp formats-psi
formats-simple formats-json-simple formats-txt formats-utt tools-datastructures-psi_query
maxent tools-tokenizers-tp tools-tokenizers-detok tools-segmenters-srx tools-recognizers-langguesser
tools-parsers-gobio tools-parsers-puddle tools-taggers-metagger tools-taggers-inflector tools-translators-bonsai
tools-converters-unumsunt tools-converters-joiner tools-converters-selector tools-converters-antiselector tools-translators-transferer tools-normalizers-simplenorm)
# ----------------------------------------------------
# TESTS_TARGETS
# ----------------------------------------------------
set(TESTS_TARGETS common-tests framework-tests utf8case-tests
formats-bracketing-tests formats-dot-tests formats-utt-tests formats-psi-tests
formats-simple-tests formats-apertium-tests
tools-tokenizers-tp-tests tools-segmenters-srx-tests tools-datastructures-psi_query-tests
tools-recognizers-langguesser-tests tools-parsers-gobio-tests tools-parsers-puddle-tests
tools-taggers-metagger-tests tools-converters-unumsunt-tests tools-translators-transferer-tests tools-normalizers-simplenorm-tests)
set(TARGETS ${BASE_TARGETS} psi-pipe)
if(HAVE_ASPELL)
set(TESTS_TARGETS ${TESTS_TARGETS} tools-spellcheckers-aspell-tests)
endif(HAVE_ASPELL)
if(HAVE_OPENFST)
set(BASE_TARGETS ${BASE_TARGETS} tools-normalizers-iayko)
set(TESTS_TARGETS ${TESTS_TARGETS} tools-normalizers-iayko-tests)
set(BASE_TARGETS ${BASE_TARGETS} tools-normalizers-niema)
set(TESTS_TARGETS ${TESTS_TARGETS} tools-normalizers-niema-tests)
endif(HAVE_OPENFST)
if(USE_JAVA)
set(BASE_TARGETS ${BASE_TARGETS} tools-lemmatizers-morfologik)
set(TESTS_TARGETS ${TESTS_TARGETS} tools-lemmatizers-morfologik-tests)
endif(USE_JAVA)
if(HAVE_SFST)
set(BASE_TARGETS ${BASE_TARGETS} tools-lemmatizers-sfst)
set(TESTS_TARGETS ${TESTS_TARGETS} tools-lemmatizers-sfst-tests)
endif(HAVE_SFST)
if(HAVE_CMPH)
set(BASE_TARGETS ${BASE_TARGETS} tools-datastructures-lexica)
set(TESTS_TARGETS ${TESTS_TARGETS} tools-datastructures-lexica-tests)
set(BASE_TARGETS ${BASE_TARGETS} tools-lexica-bilexicon)
set(TESTS_TARGETS ${TESTS_TARGETS} tools-lexica-bilexicon-tests)
set(BASE_TARGETS ${BASE_TARGETS} tools-lexica-mapper)
# set(TESTS_TARGETS ${TESTS_TARGETS} tools-lexica-mapper-tests)
set(BASE_TARGETS ${BASE_TARGETS} tools-lemmatizers-lamerlemma)
endif(HAVE_CMPH)
if(USE_POSTGRESQL)
set(BASE_TARGETS ${BASE_TARGETS} lex-db)
endif(USE_POSTGRESQL)
if(USE_BONSAI_PARSEGRAPH)
include_directories(${BONSAI_PATH})
endif(USE_BONSAI_PARSEGRAPH)
if(HAVE_GRAPHVIZ)
set(BASE_TARGETS ${BASE_TARGETS} formats-gv)
set(TESTS_TARGETS ${TESTS_TARGETS} formats-gv-tests)
endif(HAVE_GRAPHVIZ)
if(HAVE_POPPLER)
set(BASE_TARGETS ${BASE_TARGETS} formats-pdf)
endif(HAVE_POPPLER)
if(HAVE_DJVULIBRE)
set(BASE_TARGETS ${BASE_TARGETS} formats-djvu)
endif(HAVE_DJVULIBRE)
if(HAVE_LINK_GRAMMAR)
set(BASE_TARGETS ${BASE_TARGETS} tools-parsers-link)
endif(HAVE_LINK_GRAMMAR)
if(USE_DOC_READER)
set(BASE_TARGETS ${BASE_TARGETS} formats-doc)
endif(USE_DOC_READER)
# ----------------------------------------------------
# Include and link directories
# ----------------------------------------------------
set(DIRS common common/plugins maxent formats tools framework server bindings utf8 utf8case sundown fex tiniconv uchardet)
foreach(dir ${DIRS})
include_directories("${psi-toolkit_SOURCE_DIR}/${dir}")
link_directories("${psi-toolkit_BINARY_DIR}/${dir}")
add_subdirectory(${dir})
endforeach(dir)
foreach(dir ${formats_SUBDIRS})
include_directories("${psi-toolkit_SOURCE_DIR}/formats/${dir}")
link_directories("${psi-toolkit_BINARY_DIR}/formats/${dir}")
endforeach(dir)
set(ALL_TARGETS ${TARGETS} ${TESTS_TARGETS})
set_target_properties(${ALL_TARGETS} PROPERTIES
COMPILE_FLAGS "-I${psi-toolkit_SOURCE_DIR}/utf8 -I${psi-toolkit_SOURCE_DIR}/utf8case -I${psi-toolkit_SOURCE_DIR}/tests")
if(USE_BONSAI_PARSEGRAPH)
set_target_properties(tools-parsers-puddle PROPERTIES
COMPILE_FLAGS "-I${psi-toolkit_SOURCE_DIR}/utf8 -I${psi-toolkit_SOURCE_DIR}/utf8case -I${psi-toolkit_SOURCE_DIR}/tests -I${BONSAI_PATH}")
set_target_properties(tools-parsers-puddle-tests PROPERTIES
COMPILE_FLAGS "-I${psi-toolkit_SOURCE_DIR}/utf8 -I${psi-toolkit_SOURCE_DIR}/utf8case -I${psi-toolkit_SOURCE_DIR}/tests -I${BONSAI_PATH}")
set(_WITH_BONSAI_PARSEGRAPH 1)
endif(USE_BONSAI_PARSEGRAPH)
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
set_target_properties(fex PROPERTIES COMPILE_FLAGS "-fPIC")
set_target_properties(tiniconv PROPERTIES COMPILE_FLAGS "-fPIC")
endif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
add_subdirectory(tests)
configure_file(${psi-toolkit_SOURCE_DIR}/common/config.hpp.in
${psi-toolkit_SOURCE_DIR}/common/config.hpp)
# ====================================================
# CMake functions
# ====================================================
function(download_artifact FILE)
download_project_artifact(psi-toolkit-data ${FILE})
endfunction(download_artifact)
function(download_project_artifact PROJECT FILE)
set(_src "${psi-toolkit_SOURCE_DIR}/../psi-toolkit-data/${FILE}")
set(_trg "${psi-toolkit_SOURCE_DIR}/${FILE}")
get_filename_component(_trg_dir "${psi-toolkit_SOURCE_DIR}/${FILE}" DIRECTORY)
message(STATUS "Checking ${_src}...")
if (EXISTS "${_src}")
message(STATUS "Copying ${_src} to ${psi-toolkit_SOURCE_DIR}/${FILE}")
file(COPY "${_src}" DESTINATION "${_trg_dir}")
if (NOT EXISTS "${_trg}")
message(WARNING
"Copying ${_src} failed. Try running cmake with -DDOWNLOAD_DATA=OFF")
endif()
else()
message(WARNING
"Cannot copy ${_src}: no such file or directory. Try running cmake with -DDOWNLOAD_DATA=OFF")
endif()
endfunction(download_project_artifact)
function(download_and_unpack URL FILE CHECKSUM DESTINATION)
message(STATUS "Checking ${URL}...")
set(_downloaded_file "${psi-toolkit_SOURCE_DIR}/${DESTINATION}")
set(_skip_download 0)
if (EXISTS "${_downloaded_file}")
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.7")
execute_process(COMMAND "md5sum" "-b" ${_downloaded_file}
OUTPUT_VARIABLE _file_md5_line
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "^[0-9a-f]+" _file_md5 "${_file_md5_line}")
else()
file(MD5 "${_downloaded_file}" _file_md5)
endif ()
message(STATUS "File ${_downloaded_file} already there with MD5 ${_file_md5}")
message(STATUS "Excpected MD5 is ${CHECKSUM}...")
if ("${CHECKSUM}" STREQUAL "${_file_md5}")
message(STATUS "MD5 is the same, skipping download")
set(_skip_download 1)
endif ()
endif ()
if (NOT "${_skip_download}")
message(STATUS "Downloading ${URL}...")
set(_tmp_archive_file "${psi-toolkit_BINARY_DIR}/pack.tmp.tar.gz")
message(STATUS "${_tmp_archive_file}")
file(DOWNLOAD
"${URL}"
"${_tmp_archive_file}"
STATUS status)
list(GET status 0 _status )
list(GET status 1 _status_message )
if (NOT ${_status} EQUAL 0)
file(REMOVE "${_tmp_archive_file}")
message(FATAL_ERROR
"Cannot download ${_url}:${_status_message}. Try running cmake with -DDOWNLOAD_DATA=OFF")
endif()
message(STATUS "unpacking into ${_downloaded_file}")
execute_process(COMMAND "tar" "zxfO" ${_tmp_archive_file} ${FILE}
OUTPUT_FILE "${_downloaded_file}")
if ("${CMAKE_VERSION}" VERSION_LESS "2.8.7")
execute_process(COMMAND "md5sum" "-b" ${_downloaded_file}
OUTPUT_VARIABLE _file_md5_line
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "^[0-9a-f]+" _file_md5 "${_file_md5_line}")
else()
file(MD5 "${_downloaded_file}" _file_md5)
endif ()
if (NOT "${CHECKSUM}" STREQUAL "${_file_md5}")
message(FATAL_ERROR
"Wrong MD5 checksum for ${URL} (${CHECKSUM} expected ${_file_md5})")
endif()
file(REMOVE "${_tmp_archive_file}")
endif()
endfunction(download_and_unpack)
if(DOWNLOAD_DATA)
download_artifact("tools/parsers/gobio/data/pl/rules.g")
download_artifact("tools/lexica/bilexicon/data/depl.bin")
download_artifact("tools/lexica/bilexicon/data/enpl.bin")
download_artifact("tools/lexica/bilexicon/data/espl.bin")
download_artifact("tools/lexica/bilexicon/data/frpl.bin")
download_artifact("tools/lexica/bilexicon/data/itpl.bin")
download_artifact("tools/lexica/bilexicon/data/plde.bin")
download_artifact("tools/lexica/bilexicon/data/plen.bin")
download_artifact("tools/lexica/bilexicon/data/ples.bin")
download_artifact("tools/lexica/bilexicon/data/plfr.bin")
download_artifact("tools/lexica/bilexicon/data/plit.bin")
download_artifact("tools/lexica/mapper/data/en-lexdb-generation-forms.bin")
download_project_artifact(psi-toolkit-data-sumo "tools/lexica/mapper/data/es-lexdb-generation-forms.bin")
download_artifact("tools/lexica/mapper/data/pl-valency.bin")
# download_project_artifact(psi-toolkit-data-sumo "tools/lemmatizers/lamerlemma/data/pl.bin")
download_artifact("tools/lemmatizers/lamerlemma/data/pl.bin")
download_artifact("tools/lemmatizers/lamerlemma/data/fr.bin")
download_artifact("tools/lemmatizers/lamerlemma/data/de.bin")
download_artifact("tools/lemmatizers/lamerlemma/data/en.bin")
download_artifact("tools/lemmatizers/lamerlemma/data/es.bin")
download_artifact("tools/lemmatizers/lamerlemma/data/it.bin")
if (HAVE_SFST)
file(MAKE_DIRECTORY "${psi-toolkit_SOURCE_DIR}/tools/lemmatizers/sfst/data")
download_and_unpack(
"http://www.let.rug.nl/coltekin/trmorph/trmorph-0.2.1.tar.gz"
"trmorph-0.2.1/trmorph-0.2.1.a"
"0d8a94791fce28f862e2890406e81727"
"tools/lemmatizers/sfst/data/tr.a")
endif()
endif(DOWNLOAD_DATA)
# ====================================================
# Sets prefix for all generated libraries
# ====================================================
# Helping macro
MACRO(LIST_CONTAINS var value)
SET(${var})
FOREACH (value2 ${ARGN})
IF(${value} STREQUAL ${value2})
SET(${var} TRUE)
ENDIF(${value} STREQUAL ${value2})
ENDFOREACH (value2)
ENDMACRO(LIST_CONTAINS)
GET_CMAKE_PROPERTY(all_variables VARIABLES)
FOREACH(variable_name ${all_variables})
if(variable_name MATCHES "_LIB_DEPENDS$")
STRING(REGEX REPLACE "_LIB_DEPENDS.*" "" library_name ${variable_name})
if(TARGET ${library_name})
GET_TARGET_PROPERTY(target_location ${library_name} LOCATION)
if(NOT target_location MATCHES "NOTFOUND")
# the prefix 'libpsitoolkit_' will not be added to any library enumerated
# in regexp below
if(NOT target_location MATCHES
"psitoolkit_perl_simple|python.*_PSIToolkit|psitoolkit_ruby_simple")
SET_TARGET_PROPERTIES(${library_name} PROPERTIES PREFIX ${MY_TARGETLIB_PREFIX})
endif()
endif()
endif()
endif()
endforeach(variable_name)
message("RPATH is: ${CMAKE_INSTALL_RPATH}")
configure_file(
"${psi-toolkit_SOURCE_DIR}/psi-pipe-or-server.sh"
"${psi-toolkit_BINARY_DIR}"
COPYONLY)
if(HAVE_OPENFST)
# target_include_directories(tools-normalizers-openfst-plugin PRIVATE ${OPENFST_INCLUDE_DIRS})
# target_include_directories(tools-normalizers-openfst-plugin PRIVATE /usr/local/include)
# target_compile_options(tools-normalizers-openfst-plugin PRIVATE -fpermissive)
# target_compile_options(tools-normalizers-openfst-plugin PRIVATE -std=c++11)
# target_compile_options(tools-normalizers-openfst-plugin PRIVATE -lfstfar)
# target_compile_options(tools-normalizers-openfst-plugin PRIVATE -lfst)
# target_compile_options(tools-normalizers-openfst-plugin PRIVATE -ldl)
# set_target_properties(tools-normalizers-openfst-plugin PROPERTIES LINK_FLAGS "-lfstfar -lfst -ldl")
set_property(TARGET tools-normalizers-openfst-plugin PROPERTY CXX_STANDARD 11)
endif(HAVE_OPENFST)