Blame view

CMakeLists.txt 7.05 KB
Michał Lenart authored
1
2

cmake_minimum_required (VERSION 2.8) 
Michał Lenart authored
3
4
project (Morfeusz)
Michał Lenart authored
5
6
7
set (Morfeusz_VERSION_MAJOR 2)
set (Morfeusz_VERSION_MINOR 0)
set (Morfeusz_VERSION_PATCH 0)
Michał Lenart authored
8
set (CMAKE_BUILD_TYPE "Debug")
Michał Lenart authored
9
10

enable_testing()
Michał Lenart authored
11
Michał Lenart authored
12
##### initialize some vars #####
Michał Lenart authored
13
14
15

# ARCHITECTURE
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
Michał Lenart authored
16
    set (ARCHITECTURE "amd64")
Michał Lenart authored
17
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86")
Michał Lenart authored
18
    set (ARCHITECTURE "i386")
Michał Lenart authored
19
20
elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "")
    message (FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR is not set (should be x86 or x86_64)")
Michał Lenart authored
21
22
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    set (ARCHITECTURE "amd64")
Michał Lenart authored
23
else ()
Michał Lenart authored
24
    message (FATAL_ERROR "Invalid architecture: ${CMAKE_SYSTEM_PROCESSOR}")
Michał Lenart authored
25
26
27
28
29
30
31
32
endif ()

# PROJECT_VERSION
set (PROJECT_VERSION "${Morfeusz_VERSION_MAJOR}.${Morfeusz_VERSION_MINOR}.${Morfeusz_VERSION_PATCH}")

### USER DEFINED VARIABLES

# INPUT_DICTIONARY_CPP
Michał Lenart authored
33
34
set (INPUT_DICTIONARY_CPP "${PROJECT_SOURCE_DIR}/../default_fsa.cpp")
set (INPUT_SYNTH_DICTIONARY_CPP "${PROJECT_SOURCE_DIR}/../default_synth_fsa.cpp")
Michał Lenart authored
35
if ("${INPUT_DICTIONARIES}" STREQUAL "")
Michał Lenart authored
36
   if ("${EMPTY_INPUT_DICTIONARY}" STREQUAL "TRUE")
Michał Lenart authored
37
    set (INPUT_DICTIONARIES ${PROJECT_SOURCE_DIR}/input/empty.txt)
Michał Lenart authored
38
   else ()
Michał Lenart authored
39
    set (INPUT_DICTIONARIES "${PROJECT_SOURCE_DIR}/input/sgjp-hom.tab,${PROJECT_SOURCE_DIR}/input/dodatki.tab")
Michał Lenart authored
40
41
   endif ()
endif ()
Michał Lenart authored
42
43

# INPUT_TAGSET
Michał Lenart authored
44
45
46
47
if ("${INPUT_TAGSET}" STREQUAL "")
   set (INPUT_TAGSET ${PROJECT_SOURCE_DIR}/input/polimorf.tagset)
endif ()
Michał Lenart authored
48
49
# SEGMENT_RULES_FILE
if ("${SEGMENT_RULES_FILE}" STREQUAL "")
Michał Lenart authored
50
   set (SEGMENT_RULES_FILE "${PROJECT_SOURCE_DIR}/input/segmenty.dat")
Michał Lenart authored
51
52
endif ()
Michał Lenart authored
53
message ("Will use ${INPUT_DICTIONARIES} as default dictionary input, ${INPUT_TAGSET} as tagset and ${SEGMENT_RULES_FILE} as segmentation rules")
Michał Lenart authored
54
Michał Lenart authored
55
56
57
58
59
60
# TARGET_DIR
if ("${TARGET_DIR}" STREQUAL "")
    set (TARGET_DIR "${PROJECT_BINARY_DIR}")
endif ()

### Compilation and linking flags
Michał Lenart authored
61
Michał Lenart authored
62
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
Michał Lenart authored
63
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98 -Wall -pedantic -Wcast-align -Wextra -Wmissing-noreturn -Wconversion -Wcast-qual -Wcast-align")
Michał Lenart authored
64
65
66
    #~ if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
        #~ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
    #~ endif ()
Michał Lenart authored
67
68
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -O2")
Michał Lenart authored
69
70
71
72
73
    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
74
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Michał Lenart authored
75
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++98")
Michał Lenart authored
76
77
78
    if ("${INSTALL_NAME_TOOL}" STREQUAL "")
        set (INSTALL_NAME_TOOL install_name_tool)
    endif ()
Michał Lenart authored
79
80
81
    #~ set (CMAKE_INSTALL_NAME_DIR @executable_path)
    #~ set (CMAKE_BUILD_WITH_INSTALL_RPATH ON)
    #~ set (MACOSX_RPATH TRUE)
Michał Lenart authored
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
endif ()

########## Setup RPATH ##########

# use, i.e. don't skip the full RPATH for the build tree
set (CMAKE_SKIP_BUILD_RPATH  FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 

set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)


# the RPATH to be used when installing, but only if it's not a system directory
list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if ("${isSystemDir}" STREQUAL "-1")
   SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
Michał Lenart authored
104
105
endif ()
Michał Lenart authored
106
107
108
########## Configure CPack ##########

# general
Michał Lenart authored
109
set (CPACK_PACKAGE_FILE_NAME "morfeusz2-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${ARCHITECTURE}")
Michał Lenart authored
110
111
112
113
114
115
set (CPACK_PACKAGE_VENDOR "Michał Lenart")
set (CPACK_PACKAGE_CONTACT "michal.lenart@ipipan.waw.pl")
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Morphological analyzer for Polish language.")
set (CPACK_OUTPUT_FILE_PREFIX "${TARGET_DIR}")

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
Michał Lenart authored
116
    set (CPACK_GENERATOR "DEB" "TGZ")
Michał Lenart authored
117
    #debian
Michał Lenart authored
118
    set (CPACK_DEBIAN_PACKAGE_NAME "morfeusz2")
Michał Lenart authored
119
120
    set (CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_CONTACT}")
    set (CPACK_DEBIAN_PACKAGE_DEPENDS "libstdc++6 (>= 4.6)")
Michał Lenart authored
121
    set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${ARCHITECTURE}")
Michał Lenart authored
122
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
Michał Lenart authored
123
124
125
126
127
    if (${ARCHITECTURE} MATCHES "amd64")
        set (CPACK_GENERATOR "NSIS64" "TGZ")
    else ()
        set (CPACK_GENERATOR "NSIS" "TGZ")
    endif ()
Michał Lenart authored
128
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Michał Lenart authored
129
    set (CPACK_GENERATOR "TGZ")
Michał Lenart authored
130
131
132
133
134
endif ()

include (CPack)

##### END initialize some vars #####
Michał Lenart authored
135
file (COPY fsabuilder testfiles input DESTINATION .)
Michał Lenart authored
136
Michał Lenart authored
137
138
139
140
141
configure_file (
  "${PROJECT_SOURCE_DIR}/morfeusz/MorfeuszConfig.hpp.in"
  "${PROJECT_BINARY_DIR}/morfeusz/MorfeuszConfig.hpp"
)
Michał Lenart authored
142
143
###### add main sources ########
Michał Lenart authored
144
include_directories("${PROJECT_BINARY_DIR}" )
Michał Lenart authored
145
Michał Lenart authored
146
add_subdirectory (morfeusz)
Michał Lenart authored
147
add_subdirectory (fsabuilder)
Michał Lenart authored
148
Michał Lenart authored
149
########## add tests ##########
Michał Lenart authored
150
Michał Lenart authored
151
macro (test_build_and_recognize fname method)
Michał Lenart authored
152
153
    add_test (TestBuild-${method}-${fname} python fsabuilder/buildfsa.py --analyzer --input-files testfiles/${fname} -o /tmp/test-${method}-${fname}.fsa --tagset-file=testfiles/polimorf.tagset --segments-file=testfiles/segmenty.dat --serialization-method=${method})
    add_test (TestBuild4Synth-${method}-${fname} python fsabuilder/buildfsa.py --generator --input-files testfiles/${fname} -o /tmp/test-synth-${method}-${fname}.fsa --tagset-file=testfiles/polimorf.tagset --serialization-method=${method})
Michał Lenart authored
154
    add_test (TestRecognize-${method}-${fname} morfeusz/test_recognize_dict /tmp/test-${method}-${fname}.fsa testfiles/${fname})
Michał Lenart authored
155
156
    # add_test (TestNOTRecognize-${method}-${fname} fsa/test_not_recognize /tmp/test-${method}-${fname}.fsa testfiles/out_of_dict)
    # add_test (TestSpeed-${method}-${fname} fsa/test_speed /tmp/test-${method}-${fname}.fsa testfiles/speed_test_data)
Michał Lenart authored
157
endmacro ()
Michał Lenart authored
158
Michał Lenart authored
159
160
macro (test_result_equals inputFilename requiredOutputFilename encoding)
    # add_test (TestBuild4ResultEquals-${dictFilename}-${requiredOutputFilename} python fsabuilder/fsa/buildfsa.py -i ${dictFilename} -o /tmp/test.fsa --tagset-file=testfiles/polimorf.tagset --output-format=BINARY --serialization-method=SIMPLE)
Michał Lenart authored
161
    add_test (TestResultEquals-${inputFilename}-${requiredOutputFilename} morfeusz/test_result_equals ${inputFilename} ${requiredOutputFilename} ${encoding})
Michał Lenart authored
162
endmacro ()
Michał Lenart authored
163
Michał Lenart authored
164
165
166
test_build_and_recognize(PoliMorfSmall.tab SIMPLE)
test_build_and_recognize(PoliMorfSmall.tab V1)
test_build_and_recognize(PoliMorfSmall.tab V2)
Michał Lenart authored
167
Michał Lenart authored
168
169
170
test_result_equals (testfiles/test1.txt             testfiles/test1.txt.out             UTF8)
test_result_equals (testfiles/test1.txt.ISO8859-2   testfiles/test1.txt.out.ISO8859-2   ISO8859_2)
test_result_equals (testfiles/test1.txt.CP1250      testfiles/test1.txt.out.CP1250      CP1250)
Michał Lenart authored
171
test_result_equals (testfiles/test1.txt.CP852     testfiles/test1.txt.out.CP852     CP852)