This repository has been archived by the owner on Apr 28, 2022. It is now read-only.
forked from OpenNMT/CTranslate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
158 lines (127 loc) · 3.54 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
cmake_minimum_required(VERSION 3.1.0)
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.18.66.tar.gz"
SHA1 "26028d26e2a9e0496fd7c896fa04e05b309ab6fd"
)
project(onmt)
option(LIB_ONLY "Do not compile clients" OFF)
option(WITH_OPENMP "Use OpenMP if available" ON)
option(WITH_CUDA "Use CUDA if available" ON)
option(WITH_MKL "Use Intel® MKL if available" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
set(CMAKE_CXX_STANDARD 11)
# Set Release build type by default to get sane performance.
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type: " ${CMAKE_BUILD_TYPE})
if(WITH_OPENMP)
find_package(OpenMP)
if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else()
message(WARNING "OpenMP not found: Compilation will not use OpenMP")
endif()
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
####
# Installation (https://github.com/forexample/package-example) {
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")
set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(targets_export_name "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")
include(CMakePackageConfigHelpers)
# Use:
# * targets_export_name
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)
install(
FILES "${project_config}"
DESTINATION "${config_install_dir}"
)
install(
EXPORT "${targets_export_name}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
# }
hunter_add_package(Eigen)
find_package(Eigen3 3.3 CONFIG REQUIRED)
add_subdirectory(lib/TH)
if(NOT TARGET OpenNMTTokenizer::OpenNMTTokenizer)
hunter_add_package(OpenNMTTokenizer)
find_package(OpenNMTTokenizer CONFIG REQUIRED)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(NOT HUNTER_ENABLED)
find_package(CUDA 6.5 QUIET)
endif()
set(SOURCES
src/th/Env.cc
src/th/Obj.cc
src/th/Utils.cc
src/Dictionary.cc
src/PhraseTable.cc
src/Profiler.cc
src/ITranslator.cc
src/TranslatorFactory.cc
src/TranslationResult.cc
src/Threads.cc
)
if (MKL_FOUND)
add_definitions(-DEIGEN_USE_MKL_ALL)
list(APPEND INCLUDE_DIRECTORIES ${MKL_INCLUDE_DIR})
endif()
if (CUDA_FOUND)
add_definitions(-DWITH_CUDA)
cuda_include_directories(${INCLUDE_DIRECTORIES})
cuda_add_library(${PROJECT_NAME}
${SOURCES}
src/cuda/Utils.cc
src/cuda/Kernels.cu
)
cuda_add_cublas_to_target(${PROJECT_NAME})
else()
add_library(${PROJECT_NAME} ${SOURCES})
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC
OpenNMTTokenizer::OpenNMTTokenizer
TH)
if(ANDROID)
if(ANDROID_STL MATCHES "gnustl")
target_compile_definitions(${PROJECT_NAME} PUBLIC "ANDROID_GNUSTL_COMPAT")
endif()
endif()
target_include_directories(
${PROJECT_NAME}
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/lib>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
)
if (NOT LIB_ONLY)
add_subdirectory(cli)
endif()
install(
TARGETS ${PROJECT_NAME}
EXPORT "${targets_export_name}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
install(
DIRECTORY include/onmt
DESTINATION include
FILES_MATCHING PATTERN "*.h*"
)