forked from mlpack/models
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
230 lines (199 loc) · 8.49 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
project(models C CXX)
# Enables testing for the project.
enable_testing()
set(CEREAL_VERSION "1.1.2")
# First, define all the compilation options.
# We default to debugging mode for developers.
option(DOWNLOAD_ENSMALLEN "If ensmallen is not found, download it." ON)
option(USE_OPENMP "If available, use OpenMP for parallelization." ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Include modules in the CMake directory.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
# Set the CFLAGS and CXXFLAGS.
# Set the CFLAGS and CXXFLAGS depending on the options the user specified.
# Only GCC-like compilers support -Wextra, and other compilers give tons of
# output for -Wall, so only -Wall and -Wextra on GCC.
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -Wall -Wextra -ftemplate-depth=1000 -pthread")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
endif()
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif ()
# If using clang, we have to link against libc++ depending on the
# OS (at least on some systems). Further, gcc sometimes optimizes calls to
# math.h functions, making -lm unnecessary with gcc, but it may still be
# necessary with clang.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF (APPLE)
# detect OS X version. Use '/usr/bin/sw_vers -productVersion' to
# extract V from '10.V.x'.)
EXEC_PROGRAM(/usr/bin/sw_vers ARGS
-productVersion OUTPUT_VARIABLE MACOSX_VERSION_RAW)
string(REGEX REPLACE
"10\\.([0-9]+).*" "\\1"
MACOSX_VERSION
"${MACOSX_VERSION_RAW}")
# OSX Lion (10.7) and OS X Mountain Lion (10.8) doesn't automatically
# select the right stdlib.
if(${MACOSX_VERSION} LESS 9)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif(${MACOSX_VERSION} LESS 9)
endif(APPLE)
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# Now, find the libraries we need to compile against. Several variables can be
# set to manually specify the directory in which each of these libraries
# resides.
# ARMADILLO_LIBRARY - location of libarmadillo.so / armadillo.lib
# ARMADILLO_INCLUDE_DIR - directory containing <armadillo>
# ARMADILLO_INCLUDE_DIRS - directories necessary for Armadillo includes
# MLPACK_INCLUDE_DIR - include directory for mlpack
# MLPACK_LIBRARY - library directory for mlpack
find_package(Armadillo 8.400.0 REQUIRED)
find_package(cereal "${CEREAL_VERSION}" REQUIRED)
# If Armadillo was compiled without ARMA_64BIT_WORD and we are on a 64-bit
# system (where size_t will be 64 bits), suggest to the user that they should
# compile Armadillo with 64-bit words. Note that with Armadillo 5.000.0 and
# newer, ARMA_64BIT_WORD is enabled by default.
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
# Check the version, to see if ARMA_64BIT_WORD is enabled by default.
set(ARMA_HAS_64BIT_WORD 0)
if(NOT (${ARMADILLO_VERSION_MAJOR} LESS 5))
set(ARMA_HAS_64BIT_WORD 1)
else()
# Can we open the configuration file? If not, issue a warning.
if(NOT EXISTS "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp")
message(WARNING "Armadillo configuration file "
"(${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp) does not exist!")
else()
# We are on a 64-bit system. Does Armadillo have ARMA_64BIT_WORD enabled?
file(READ "${ARMADILLO_INCLUDE_DIR}/armadillo_bits/config.hpp" ARMA_CONFIG)
string(REGEX MATCH
"[\r\n][ ]*#define ARMA_64BIT_WORD"
ARMA_HAS_64BIT_WORD_PRE
"${ARMA_CONFIG}")
string(LENGTH "${ARMA_HAS_64BIT_WORD_PRE}" ARMA_HAS_64BIT_WORD)
endif()
endif()
if(ARMA_HAS_64BIT_WORD EQUAL 0)
message(WARNING "This is a 64-bit system, but Armadillo was compiled "
"without 64-bit index support. Consider recompiling Armadillo with "
"ARMA_64BIT_WORD to enable 64-bit indices (large matrix support). "
"mlpack will still work without ARMA_64BIT_WORD defined, but will not "
"scale to matrices with more than 4 billion elements.")
endif()
else()
# If we are on a 32-bit system, we must manually specify the size of the word
# to be 32 bits, since otherwise Armadillo will produce a warning that it is
# disabling 64-bit support.
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
add_definitions(-DARMA_32BIT_WORD)
endif ()
endif()
if (WIN32)
find_package(LAPACK REQUIRED)
find_package(BLAS REQUIRED)
# Piggyback LAPACK and BLAS linking into Armadillo link.
set(ARMADILLO_LIBRARIES
${ARMADILLO_LIBRARIES} ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES})
endif ()
find_package(MLPACK REQUIRED)
find_package(Ensmallen 1.10.0)
if (NOT ENSMALLEN_FOUND)
if (DOWNLOAD_ENSMALLEN)
file(DOWNLOAD http://www.ensmallen.org/files/ensmallen-latest.tar.gz
"${CMAKE_BINARY_DIR}/deps/ensmallen-latest.tar.gz"
STATUS ENS_DOWNLOAD_STATUS_LIST LOG ENS_DOWBLOAD_LOG
SHOW_PROGRESS)
list(GET ENS_DOWNLOAD_STATUS_LIST 0 ENS_DOWNLOAD_STATUS)
if (ENS_DOWNLOAD_STATUS EQUAL 0)
execute_process(COMMAND ${CMAKE_COMMAND} -E
tar xzf "${CMAKE_BINARY_DIR}/deps/ensmallen-latest.tar.gz"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/deps/")
# Get the name of the directory.
file (GLOB ENS_DIRECTORIES RELATIVE "${CMAKE_BINARY_DIR}/deps/"
"${CMAKE_BINARY_DIR}/deps/ensmallen-[0-9]*.[0-9]*.[0-9]*")
list(LENGTH ENS_DIRECTORIES ENS_DIRECTORIES_LEN)
if (ENS_DIRECTORIES_LEN EQUAL 1)
list(GET ENS_DIRECTORIES 0 ENSMALLEN_INCLUDE_DIR)
set(ENSMALLEN_INCLUDE_DIR
"${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/include")
message(STATUS
"Successfully downloaded ensmallen into ${CMAKE_BINARY_DIR}/deps/${ENSMALLEN_INCLUDE_DIR}/")
else ()
message(FATAL_ERROR "Problem unpacking ensmallen! Expected only one directory ensmallen-x.y.z/; found ${ENS_DIRECTORIES}. Try removing the directory ${CMAKE_BINARY_DIR}/deps and reconfiguring.")
endif ()
else ()
list(GET ENS_DOWNLOAD_STATUS_LIST 1 ENS_DOWNLOAD_ERROR)
message(FATAL_ERROR
"Could not download ensmallen! Error code ${ENS_DOWNLOAD_STATUS}: ${ENS_DOWNLOAD_ERROR}! Error log: ${ENS_DOWBLOAD_LOG}")
endif ()
else ()
# Release versions will have ensmallen packaged with the release so we can
# just reference that.
if (EXISTS "${CMAKE_SOURCE_DIR}/src/mlpack/core/optimizers/ensmallen/ensmallen.hpp")
set(ENSMALLEN_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/src/mlpack/core/optimizers/ensmallen")
else ()
message(FATAL_ERROR
"Cannot find ensmallen headers! Try setting ENSMALLEN_INCLUDE_DIR!")
endif ()
endif ()
endif ()
# Unfortunately this configuration variable is necessary and will need to be
# updated as time goes on and new versions are released.
set(Boost_ADDITIONAL_VERSIONS
"1.49.0" "1.50.0" "1.51.0" "1.52.0" "1.53.0" "1.54.0" "1.55.0")
find_package(Boost 1.49
COMPONENTS
filesystem
system
regex
REQUIRED
)
if (USE_OPENMP)
message(WARNING "Only use OpenMP if mlpack has been compiled with OpenMP.")
find_package(OpenMP)
endif ()
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()
# In Visual Studio, automatic linking is performed, so we don't need to worry
# about it. Clear the list of libraries to link against and let Visual Studio
# handle it.
if (MSVC)
link_directories(${Boost_LIBRARY_DIRS})
set(Boost_LIBRARIES "")
endif ()
link_directories(${Boost_LIBRARY_DIRS})
# Include directories for the previous dependencies.
set(MODELS_INCLUDE_DIRS ${MLPACK_INCLUDE_DIR}
${ENSMALLEN_INCLUDE_DIR}
${ARMADILLO_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
${CEREAL_INCLUDE_DIR})
set(MODELS_LIBRARIES ${MLPACK_LIBRARY}
${ARMADILLO_LIBRARIES}
${Boost_LIBRARIES})
include_directories(${MODELS_INCLUDE_DIRS})
# In Visual Studio, automatic linking is performed, so we don't need to worry
# about it. Clear the list of libraries to link against and let Visual Studio
# handle it.
if (MSVC)
set(MODELS_LIBRARIES "")
endif ()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
# Recurse into each directory.
set(DIRS
utils/
ensmallen_utils/
dataloader/
models/
tests/
)
foreach(dir ${DIRS})
add_subdirectory(${dir})
endforeach()