-
Notifications
You must be signed in to change notification settings - Fork 70
/
CMakeLists.txt
114 lines (98 loc) · 3.04 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
cmake_minimum_required(VERSION 3.1.0)
project(OpenNMTTokenizer)
option(WITH_ICU "Compile with ICU" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
set(INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/include
)
set(PUBLIC_HEADERS
include/onmt/Alphabet.h
include/onmt/AnnotatedToken.h
include/onmt/BPE.h
include/onmt/BPELearner.h
include/onmt/CaseModifier.h
include/onmt/ITokenizer.h
include/onmt/SpaceTokenizer.h
include/onmt/SubwordEncoder.h
include/onmt/SubwordLearner.h
include/onmt/Tokenizer.h
)
set(SOURCES
src/Alphabet.cc
src/AnnotatedToken.cc
src/BPE.cc
src/BPELearner.cc
src/CaseModifier.cc
src/ITokenizer.cc
src/SpaceTokenizer.cc
src/SubwordEncoder.cc
src/SubwordLearner.cc
src/Tokenizer.cc
src/unicode/Unicode.cc
)
list(APPEND LINK_LIBRARIES "")
if (WITH_ICU)
find_package(ICU REQUIRED)
add_definitions(-DWITH_ICU)
list(APPEND INCLUDE_DIRECTORIES ${ICU_INCLUDE_DIRS})
list(APPEND LINK_LIBRARIES ${ICU_LIBRARIES})
else()
list(APPEND SOURCES src/unicode/Data.cc)
endif()
find_library(SP_LIBRARY NAMES sentencepiece)
find_path(SP_INCLUDE_DIR NAMES sentencepiece_processor.h)
if(NOT SP_LIBRARY OR NOT SP_INCLUDE_DIR)
message(WARNING "sentencepiece not found; will not be supported")
else()
message(STATUS "Found sentencepiece: ${SP_LIBRARY}")
add_definitions(-DWITH_SP)
list(APPEND PUBLIC_HEADERS include/onmt/SentencePiece.h)
list(APPEND SOURCES src/SentencePiece.cc)
list(APPEND INCLUDE_DIRECTORIES ${SP_INCLUDE_DIR})
list(APPEND LINK_LIBRARIES ${SP_LIBRARY})
find_library(SP_TRAIN_LIBRARY NAMES sentencepiece_train)
if(SP_TRAIN_LIBRARY)
add_definitions(-DWITH_SP_TRAIN)
message(STATUS "Found sentencepiece_train: ${SP_TRAIN_LIBRARY}")
list(APPEND PUBLIC_HEADERS include/onmt/SPMLearner.h)
list(APPEND SOURCES src/SPMLearner.cc)
list(APPEND LINK_LIBRARIES ${SP_TRAIN_LIBRARY})
else()
message(WARNING "sentencepiece_train not found: training SentencePiece models will not be supported")
endif()
file(STRINGS ${SP_INCLUDE_DIR}/sentencepiece_processor.h HAS_SAMPLE_ENCODE REGEX "SampleEncode")
if(HAS_SAMPLE_ENCODE)
add_definitions(-DSP_HAS_SAMPLE_ENCODE)
endif()
file(STRINGS ${SP_INCLUDE_DIR}/sentencepiece_processor.h HAS_VOCAB_RESTRICTION REGEX "SetVocabulary")
if(HAS_VOCAB_RESTRICTION)
add_definitions(-DSP_HAS_VOCAB_RESTRICTION)
endif()
endif()
add_library(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PUBLIC ${INCLUDE_DIRECTORIES})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})
if (NOT LIB_ONLY)
add_subdirectory(cli)
add_subdirectory(test)
endif()
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib/
LIBRARY DESTINATION lib/
)
install(FILES
${PUBLIC_HEADERS}
DESTINATION include/onmt/
)
install(FILES
include/onmt/unicode/Unicode.h
DESTINATION include/onmt/unicode
)