Blame view

CMakeLists.txt 9.09 KB
Michał Lenart authored
1
2

cmake_minimum_required (VERSION 2.8) 
Michał Lenart authored
3
4
project (Morfeusz)
Jan Szejko authored
5
6
set (Morfeusz_VERSION_MAJOR 1)
set (Morfeusz_VERSION_MINOR 9)
Marcin Woliński authored
7
set (Morfeusz_VERSION_PATCH 13)
Michał Lenart authored
8
set (Morfeusz_VERSION "${Morfeusz_VERSION_MAJOR}.${Morfeusz_VERSION_MINOR}.${Morfeusz_VERSION_PATCH}")
Jan Szejko authored
9
set (Morfeusz_LIB_VERSION "${Morfeusz_VERSION}")
Marcin Woliński authored
10
11
12
13
14
15
if (BUILT_ON)
  set (Morfeusz_DEB_VERSION "${Morfeusz_VERSION}-${BUILT_ON}")
else ()
  set (Morfeusz_DEB_VERSION "${Morfeusz_VERSION}")
endif ()
Michał Lenart authored
16
if (DEFAULT_DICT_NAME)
Marcin Woliński authored
17
18
19
20
21
22
23
24
25
26
  set (Morfeusz_VERSION_TWEAK "${DEFAULT_DICT_NAME}")
  if (DICT_VERSION)
    set (Morfeusz_VERSION_TWEAK "${Morfeusz_VERSION_TWEAK}.${DICT_VERSION}")
  endif()
  set (Morfeusz_VERSION "${Morfeusz_VERSION}.${Morfeusz_VERSION_TWEAK}")
  if (NOT DICT_VERSION)
    set (DICT_VERSION "1.0")
    message (WARNING "Dictionary version is missing. Setting default value=1.0")
  endif()
  set (CPACK_PACKAGE_VERSION "${Morfeusz_VERSION}")
Michał Lenart authored
27
elseif (INPUT_DICTIONARIES)
Marcin Woliński authored
28
  message (FATAL_ERROR "DEFAULT_DICT_NAME option is missing.")
Michał Lenart authored
29
elseif (NOT SKIP_DICTIONARY_BUILDING)
Marcin Woliński authored
30
  message (WARNING "Will build WITHOUT DICTIONARY. Set INPUT_DICTIONARIES option to build with dictionary.")
Michał Lenart authored
31
endif ()
Michał Lenart authored
32
33
34
35

if (NOT CMAKE_BUILD_TYPE)
    set (CMAKE_BUILD_TYPE Release)
endif ()
Jan Szejko authored
36
set (CMAKE_SKIP_RPATH ON)
Michał Lenart authored
37
38

message ("Version=${Morfeusz_VERSION}")
Michał Lenart authored
39
Michał Lenart authored
40
41
42
43
#if ( (NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") OR ((NOT INPUT_DICTIONARIES) AND NOT (SKIP_DICTIONARY_BUILDING)))
#    set (EMBEDDED_DEFAULT_DICT 1)
#    message (WARNING "Implicitly setting EMBEDDED_DEFAULT_DICT variable to TRUE")
#endif ()
Michał Lenart authored
44
Michał Lenart authored
45
46
47
48
49
if ( (NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") OR ((NOT INPUT_DICTIONARIES) AND NOT (SKIP_DICTIONARY_BUILDING)))
    set (EMBEDDED_DEFAULT_DICT 1)
    message (WARNING "Implicitly setting EMBEDDED_DEFAULT_DICT variable to TRUE")
endif ()
Michał Lenart authored
50
51
52
53
54
55
56
57
58
59
60
61
# INPUT_DICTIONARY_CPP
if (EMBEDDED_DEFAULT_DICT)
    if (NOT ANALYZER_DICTIONARY_CPP)
        set (ANALYZER_DICTIONARY_CPP "default_fsa.cpp")
    endif ()
    if (NOT GENERATOR_DICTIONARY_CPP)
        set (GENERATOR_DICTIONARY_CPP "default_synth_fsa.cpp")
    endif ()
else ()
    if (NOT DEFAULT_DICT_DIR)
        set (DEFAULT_DICT_DIR "${CMAKE_CURRENT_BINARY_DIR}/morfeusz")
    endif ()
Marcin Woliński authored
62
    set (DEFAULT_DICT_INSTALL_DIR "share/morfeusz2/dictionaries")
Michał Lenart authored
63
64
endif ()
Jan Szejko authored
65
add_definitions (-DMORFEUSZ2_VERSION="${Morfeusz_LIB_VERSION}")
Michał Lenart authored
66
add_definitions (-DMORFEUSZ_DEFAULT_DICT_NAME="${DEFAULT_DICT_NAME}")
Michał Lenart authored
67
add_definitions (-DBUILDING_MORFEUSZ)
Michał Lenart authored
68
69
70
71
72
73
74
75
76
77
78
79
if (EMBEDDED_DEFAULT_DICT)
    add_definitions (-DMORFEUSZ_EMBEDDED_DEFAULT_DICT )
else ()
    if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR "${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local")
        add_definitions (-DMORFEUSZ_DICTIONARY_SEARCH_PATH1="/usr/local/${DEFAULT_DICT_INSTALL_DIR}")
        add_definitions (-DMORFEUSZ_DICTIONARY_SEARCH_PATH2="/usr/${DEFAULT_DICT_INSTALL_DIR}")
    else ()
        add_definitions (-DMORFEUSZ_DICTIONARY_SEARCH_PATH1="${CMAKE_INSTALL_PREFIX}/${DEFAULT_DICT_INSTALL_DIR}")
        add_definitions (-DMORFEUSZ_DICTIONARY_SEARCH_PATH2="/usr/local/${DEFAULT_DICT_INSTALL_DIR}")
        add_definitions (-DMORFEUSZ_DICTIONARY_SEARCH_PATH3="/usr/${DEFAULT_DICT_INSTALL_DIR}")
    endif ()
endif ()
Michał Lenart authored
80
Michał Lenart authored
81
82
83
if (NOT CMAKE_CROSSCOMPILING AND NOT SKIP_TESTING)
    enable_testing()
endif ()
Michał Lenart authored
84
Michał Lenart authored
85
##### initialize some vars #####
Michał Lenart authored
86
87
88

# ARCHITECTURE
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
Michał Lenart authored
89
    set (ARCHITECTURE "amd64")
Michał Lenart authored
90
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
Michał Lenart authored
91
    set (ARCHITECTURE "i386")
Marcin Woliński authored
92
93
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686")
    set (ARCHITECTURE "i386")
Michał Lenart authored
94
95
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "")
    message (FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR is not set (should be x86 or x86_64)")
Michał Lenart authored
96
97
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    set (ARCHITECTURE "amd64")
Michał Lenart authored
98
else ()
Michał Lenart authored
99
100
    set (ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
#    message (FATAL_ERROR "Invalid architecture: ${CMAKE_SYSTEM_PROCESSOR}")
Michał Lenart authored
101
102
103
endif ()

# PROJECT_VERSION
Jan Szejko authored
104
#~ set (PROJECT_VERSION "${Morfeusz_LIB_VERSION}")
Michał Lenart authored
105
106
107

### USER DEFINED VARIABLES
Michał Lenart authored
108
109
110
111
112
113
#~ if (CPP_DICTIONARIES_DIR)
    #~ set (INPUT_DICTIONARY_CPP "${CPP_DICTIONARIES_DIR}/${INPUT_DICTIONARY_CPP}")
    #~ set (INPUT_SYNTH_DICTIONARY_CPP "${CPP_DICTIONARIES_DIR}/${INPUT_SYNTH_DICTIONARY_CPP}")
#~ endif ()

if (NOT INPUT_DICTIONARIES)
Michał Lenart authored
114
#   if (EMPTY_INPUT_DICTIONARY)
Michał Lenart authored
115
    set (INPUT_DICTIONARIES ${PROJECT_SOURCE_DIR}/input/empty.txt)
Michał Lenart authored
116
117
118
#   else ()
#    set (INPUT_DICTIONARIES "${PROJECT_SOURCE_DIR}/input/sgjp-hom.tab,${PROJECT_SOURCE_DIR}/input/dodatki.tab")
#   endif ()
Michał Lenart authored
119
endif ()
Michał Lenart authored
120
121

# INPUT_TAGSET
Michał Lenart authored
122
if (NOT INPUT_TAGSET)
Michał Lenart authored
123
   set (INPUT_TAGSET ${PROJECT_SOURCE_DIR}/input/morfeusz-sgjp.tagset)
Michał Lenart authored
124
125
endif ()
Michał Lenart authored
126
# SEGMENT_RULES_FILE
Michał Lenart authored
127
if (NOT SEGMENT_RULES_FILE)
Michał Lenart authored
128
   set (SEGMENT_RULES_FILE "${PROJECT_SOURCE_DIR}/input/segmenty.dat")
Michał Lenart authored
129
130
endif ()
Michał Lenart authored
131
message ("Will use ${INPUT_DICTIONARIES} as default dictionary input, ${INPUT_TAGSET} as tagset and ${SEGMENT_RULES_FILE} as segmentation rules")
Michał Lenart authored
132
Michał Lenart authored
133
134
135
136
137
138
# TARGET_DIR
if ("${TARGET_DIR}" STREQUAL "")
    set (TARGET_DIR "${PROJECT_BINARY_DIR}")
endif ()

### Compilation and linking flags
Michał Lenart authored
139
Michał Lenart authored
140
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
Zbigniew Gawłowicz authored
141
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -pedantic -Wcast-align -Wextra -Wmissing-noreturn -Wconversion -Wcast-qual -Wcast-align -Wno-write-strings")
Michał Lenart authored
142
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND CMAKE_CROSSCOMPILING)
Zbigniew Gawłowicz authored
143
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -O2")
Michał Lenart authored
144
145
146
147
148
    set (CMAKE_SHARED_LIBRARY_PREFIX "")
    # here is some magic - must statically link libstdc++ and libgcc
    # but exclude libgcc_eh.a as it causes "multiple definition of (...)" errors
    set (CMAKE_SHARED_LINKER_FLAGS "-s -Os -static-libstdc++ -static-libgcc -Wl,--exclude-libs,libgcc_eh.a")
    set (CMAKE_EXE_LINKER_FLAGS "-s -Os -static-libstdc++ -static-libgcc")
Michał Lenart authored
149
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Michał Lenart authored
150
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98 -Wall")
Michał Lenart authored
151
    if (NOT INSTALL_NAME_TOOL)
Michał Lenart authored
152
153
        set (INSTALL_NAME_TOOL install_name_tool)
    endif ()
Michał Lenart authored
154
155
156
    #~ set (CMAKE_INSTALL_NAME_DIR @executable_path)
    #~ set (CMAKE_BUILD_WITH_INSTALL_RPATH ON)
    #~ set (MACOSX_RPATH TRUE)
Michał Lenart authored
157
158
endif ()
Michał Lenart authored
159
160
161
########## Configure CPack ##########

# general
Michał Lenart authored
162
set (CPACK_PACKAGE_FILE_NAME "morfeusz2-${Morfeusz_VERSION}-${CMAKE_SYSTEM_NAME}-${ARCHITECTURE}")
Michał Lenart authored
163
164
set (CPACK_PACKAGE_VENDOR "Michał Lenart")
set (CPACK_PACKAGE_CONTACT "michal.lenart@ipipan.waw.pl")
Michał Lenart authored
165
set (CPACK_DEBIAN_PACKAGE_VERSION "${Morfeusz_VERSION}")
Marcin Woliński authored
166
167
168
169
170
if (BUILT_ON)
  set (CPACK_DEBIAN_PACKAGE_RELEASE "${BUILT_ON}")
endif ()
#set (CPACK_DEBIAN_PACKAGE_RELEASE "18.04")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Morphological analyzer and generator for the Polish language.")
Michał Lenart authored
171
172
set (CPACK_PACKAGE_DESCRIPTION "This is the second version of Morfeusz. Among numerous improvements it has better segmentation and case-sensitive lemmas handling. It also makes it possible to perform morphological synthesis and to use your own dictionary")
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/License.txt")
Michał Lenart authored
173
174
175
set (CPACK_OUTPUT_FILE_PREFIX "${TARGET_DIR}")

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
Michał Lenart authored
176
177
    if (NOT CPACK_GENERATOR)
        set (CPACK_GENERATOR "DEB TGZ")
Michał Lenart authored
178
    endif ()
Michał Lenart authored
179
    #debian
Michał Lenart authored
180
    set (CPACK_DEBIAN_PACKAGE_NAME "morfeusz2")
Michał Lenart authored
181
182
    set (CPACK_DEBIAN_PACKAGE_MAINTAINER "Michał Lenart <${CPACK_PACKAGE_CONTACT}>")
    set (CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>= 4.6), libc6")
Michał Lenart authored
183
    set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${ARCHITECTURE}")
Michał Lenart authored
184
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND NOT CPACK_GENERATOR)
Michał Lenart authored
185
186
187
188
189
    if (${ARCHITECTURE} MATCHES "amd64")
        set (CPACK_GENERATOR "NSIS64" "TGZ")
    else ()
        set (CPACK_GENERATOR "NSIS" "TGZ")
    endif ()
Michał Lenart authored
190
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT CPACK_GENERATOR)
Michał Lenart authored
191
    set (CPACK_GENERATOR "TGZ")
Michał Lenart authored
192
193
194
195
196
endif ()

include (CPack)

##### END initialize some vars #####
Zbigniew Gawłowicz authored
197
file (COPY fsabuilder doTest.sh testJavaWrapper.sh testPythonWrapper.sh morfeusz/wrappers/python2/test2.py morfeusz/wrappers/python3/test3.py DESTINATION .)
Michał Lenart authored
198
Michał Lenart authored
199
###### add main sources ########
Michał Lenart authored
200
Michał Lenart authored
201
add_subdirectory (morfeusz)
Michał Lenart authored
202
add_subdirectory (fsabuilder)
Marcin Woliński authored
203
add_subdirectory (gui)
Michał Lenart authored
204
Michał Lenart authored
205
########## add tests ##########
Michał Lenart authored
206
Michał Lenart authored
207
macro (test_analyzer analyzerDir)
Michał Lenart authored
208
#    message ("adding test dir ${analyzerDir}")
Michał Lenart authored
209
210
211
212
    get_filename_component (dirname ${analyzerTestDir} NAME)
    add_test(TestAnalyzer_${dirname} ./doTest.sh morfeusz analyzer ${analyzerDir})
endmacro()
Michał Lenart authored
213
macro (test_generator generatorDir)
Michał Lenart authored
214
#    message ("adding test dir ${generatorDir}")
Michał Lenart authored
215
216
217
218
    get_filename_component (dirname ${generatorTestDir} NAME)
    add_test(TestGenerator_${dirname} ./doTest.sh morfeusz generator ${generatorDir})
endmacro()
Michał Lenart authored
219
220
221
222
223
224
225
file (GLOB analyzerTestDirs "tests/analyzer/*")
if (UNIX)
    foreach (analyzerTestDir ${analyzerTestDirs})
        test_analyzer(${analyzerTestDir})
    endforeach()
endif()
Michał Lenart authored
226
227
228
229
230
231
232
file (GLOB generatorTestDirs "tests/generator/*")
if (UNIX)
    foreach (generatorTestDir ${generatorTestDirs})
        test_generator(${generatorTestDir})
    endforeach()
endif()
Michał Lenart authored
233
if (UNIX AND EMBEDDED_DEFAULT_DICT)
Michał Lenart authored
234
    add_test(TestJavaWrapper ./testJavaWrapper.sh "${CMAKE_CURRENT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
Michał Lenart authored
235
    add_test(TestPythonWrapper ./testPythonWrapper.sh "${PROJECT_BINARY_DIR}")
Michał Lenart authored
236
237
else ()
    message(WARNING "Will skip Java and Python wrapper tests - must be on UNIX and with EMBEDDED_DEFAULT_DICT on to run them")
Michał Lenart authored
238
endif ()