-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
100 lines (88 loc) · 2.26 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
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(nmtkit VERSION 0.1.3 LANGUAGES CXX)
# utility to check if required option is set.
function(my_check_option name)
if(DEFINED ENV{${name}} AND NOT DEFINED ${name})
set(${name} "$ENV{${name}}")
endif()
if(${name})
MESSAGE("-- ${name}: ${${name}}")
else()
MESSAGE(FATAL_ERROR "Please give the variable `${name}`.")
endif()
endfunction()
# compiler requirements and settings
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast -Wall -Werror")
endif()
# Boost
if(DEFINED BOOST_ROOT OR DEFINED BOOSTROOT OR DEFINED ENV{BOOST_ROOT} OR DEFINED ENV{BOOSTROOT})
set(Boost_NO_BOOST_CMAKE ON)
set(Boost_NO_SYSTEM_PATHS ON)
set(Boost_REALPATH ON)
endif()
find_package(Boost 1.56.0 REQUIRED COMPONENTS
filesystem
program_options
serialization
system
unit_test_framework
)
# Eigen3/DyNet/MTEval
my_check_option(EIGEN3_INCLUDE_DIR)
my_check_option(DYNET_INCLUDE_DIR)
my_check_option(DYNET_LIBRARY_DIR)
my_check_option(MTEVAL_INCLUDE_DIR)
my_check_option(MTEVAL_LIBRARY_DIR)
# options
option(USE_GPU
"If ON, NMTKit would use the CUDA backend."
OFF
)
option(USE_VANILLA_LSTM
"If ON, NMTKit would use VanillaLSTMBuilder module instead of LSTMBuilder."
OFF
)
# CUDA
if(USE_GPU)
my_check_option(CUDA_ROOT)
set(CUDA_INCLUDE_DIR "${CUDA_ROOT}/include")
set(CUDA_LIBRARY_DIR "${CUDA_ROOT}/lib64")
set(DYNET_LIBRARIES "gdynet")
MESSAGE("-- Build NMTKit with gDyNet (CUDA).")
else()
set(DYNET_LIBRARIES "dynet")
MESSAGE("-- Build NMTKit with DyNet (CPU).")
endif()
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h
)
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
${DYNET_INCLUDE_DIR}
${MTEVAL_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/submodules/spdlog/include
)
if(USE_GPU)
include_directories(${CUDA_INCLUDE_DIR})
endif()
link_directories(
${Boost_LIBRARY_DIRS}
${DYNET_LIBRARY_DIR}
${MTEVAL_LIBRARY_DIR}
)
if(USE_GPU)
link_directories(${CUDA_LIBRARY_DIR})
endif()
set(BUILD_SHARED_LIBS ON)
enable_testing()
# nmtkit sources
add_subdirectory(bin)
add_subdirectory(nmtkit)
add_subdirectory(test)