-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
442 lines (330 loc) · 15.2 KB
/
CMakeLists.txt
File metadata and controls
442 lines (330 loc) · 15.2 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# Copyright (C) 2008-2014 Conrad Sanderson
# Copyright (C) 2008-2014 NICTA (www.nicta.com.au)
# Copyright (C) 2011 Clement Creusot
# Copyright (C) 2013 Ryan Curtin
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
set(ARMA_MAJOR 4)
set(ARMA_MINOR 200)
set(ARMA_PATCH 0)
message(STATUS "Configuring Armadillo ${ARMA_MAJOR}.${ARMA_MINOR}.${ARMA_PATCH}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build_aux/cmake/Modules/")
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(ARMA_CheckProto)
include(ARMA_CheckMathProto)
project(armadillo CXX)
set(ARMA_USE_LAPACK false)
set(ARMA_USE_BLAS false)
set(ARMA_USE_ATLAS false)
set(ARMA_USE_HDF5 false)
set(ARMA_USE_ARPACK false)
set(ARMA_USE_CXX11_RNG false)
set(ARMA_USE_WRAPPER true )
## NOTE:
## Set ARMA_USE_WRAPPER to false if you're getting linking errors when compiling your programs,
## or if you prefer to directly link with BLAS and/or LAPACK.
## You will then need to link your programs with -lblas -llapack instead of -larmadillo
## If you're using OpenBLAS, link your programs with -lopenblas -llapack instead of -larmadillo
message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}" )
message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}" )
message(STATUS "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "CMAKE_COMPILER_IS_GNUCXX = ${CMAKE_COMPILER_IS_GNUCXX}" )
if(WIN32)
message(STATUS "")
message(STATUS "WARNING:")
message(STATUS "Automatic installation is currently not available for this platform.")
message(STATUS "Please use the manual installation, as described in the README.txt file.")
message(STATUS "You can also use the 'include' folder directly, but you may want to edit")
message(STATUS "'include/armadillo_bits/config.hpp' if you have LAPACK installed.")
message(STATUS "")
endif()
##
## Find LAPACK and BLAS libraries, or their optimised versions
##
if(APPLE)
set(ARMA_OS macos)
set(ARMA_USE_LAPACK true)
set(ARMA_USE_BLAS true)
## Under MacOS, the current version of ARMA_FindCLAPACK can get confused between two incompatible
## versions of "clapack.h" (one provided by the system and one provided by ATLAS).
## As such, use of ATLAS under MacOS is disabled for now.
else()
set(ARMA_OS unix)
include(ARMA_FindMKL)
include(ARMA_FindACMLMP)
include(ARMA_FindACML)
message(STATUS " MKL_FOUND = ${MKL_FOUND}")
message(STATUS "ACMLMP_FOUND = ${ACMLMP_FOUND}")
message(STATUS " ACML_FOUND = ${ACML_FOUND}")
if(MKL_FOUND OR ACMLMP_FOUND OR ACML_FOUND)
set(ARMA_USE_BLAS true)
set(ARMA_USE_LAPACK true)
message(STATUS "")
message(STATUS "*** If the MKL or ACML libraries are installed in")
message(STATUS "*** /opt or /usr/local, make sure the run-time linker can find them.")
message(STATUS "*** On Linux systems this can be done by editing /etc/ld.so.conf")
message(STATUS "*** or modifying the LD_LIBRARY_PATH environment variable.")
message(STATUS "*** On systems with SELinux enabled (eg. Fedora, RHEL),")
message(STATUS "*** you may need to change the SELinux type of all MKL/ACML libraries")
message(STATUS "*** to fix permission problems that may occur during run-time.")
message(STATUS "*** See README.txt for more information")
message(STATUS "")
else()
include(ARMA_FindLAPACK)
include(ARMA_FindOpenBLAS)
include(ARMA_FindBLAS)
include(ARMA_FindCLAPACK)
include(ARMA_FindCBLAS)
message(STATUS " LAPACK_FOUND = ${LAPACK_FOUND}")
message(STATUS " BLAS_FOUND = ${BLAS_FOUND}")
message(STATUS "OpenBLAS_FOUND = ${OpenBLAS_FOUND}")
message(STATUS " CLAPACK_FOUND = ${CLAPACK_FOUND}")
message(STATUS " CBLAS_FOUND = ${CBLAS_FOUND}")
if(LAPACK_FOUND)
set(ARMA_USE_LAPACK true)
endif()
if(BLAS_FOUND)
set(ARMA_USE_BLAS true)
endif()
if(OpenBLAS_FOUND AND CLAPACK_FOUND AND CBLAS_FOUND)
message(STATUS "")
message(STATUS "*** WARNING: both OpenBLAS and ATLAS have been found; ATLAS will not be used")
endif()
if(OpenBLAS_FOUND)
set(ARMA_USE_BLAS true)
message(STATUS "")
message(STATUS "*** If the OpenBLAS library is installed in")
message(STATUS "*** /usr/local/lib or /usr/local/lib64")
message(STATUS "*** make sure the run-time linker can find it.")
message(STATUS "*** On Linux systems this can be done by editing /etc/ld.so.conf")
message(STATUS "*** or modifying the LD_LIBRARY_PATH environment variable.")
message(STATUS "")
else()
if(CLAPACK_FOUND AND CBLAS_FOUND)
message(STATUS "CLAPACK_INCLUDE_DIR = ${CLAPACK_INCLUDE_DIR}")
message(STATUS " CBLAS_INCLUDE_DIR = ${CBLAS_INCLUDE_DIR}")
if(${CLAPACK_INCLUDE_DIR} STREQUAL ${CBLAS_INCLUDE_DIR})
set(ARMA_USE_ATLAS true)
set(ARMA_ATLAS_INCLUDE_DIR ${CLAPACK_INCLUDE_DIR})
endif()
endif()
endif()
endif()
endif()
if(MKL_FOUND OR ACMLMP_FOUND OR ACML_FOUND)
if(MKL_FOUND)
set(ARMA_LIBS ${ARMA_LIBS} ${MKL_LIBRARIES})
if(ACMLMP_FOUND OR ACML_FOUND)
message(STATUS "*** Intel MKL as well as AMD ACML libraries were found.")
message(STATUS "*** Using only the MKL library to avoid linking conflicts.")
message(STATUS "*** If you wish to use ACML instead, please link manually with")
message(STATUS "*** acml or acml_mp instead of the armadillo run-time component.")
message(STATUS "*** Alternatively, remove MKL from your system and rerun")
message(STATUS "*** Armadillo's configuration using ./configure")
endif()
else()
if(ACMLMP_FOUND)
set(ARMA_LIBS ${ARMA_LIBS} ${ACMLMP_LIBRARIES})
message(STATUS "*** Both single-core and multi-core ACML libraries were found.")
message(STATUS "*** Using only the multi-core library to avoid linking conflicts.")
else()
if(ACML_FOUND)
set(ARMA_LIBS ${ARMA_LIBS} ${ACML_LIBRARIES})
endif()
endif()
endif()
else()
if(ARMA_USE_BLAS STREQUAL true)
if(OpenBLAS_FOUND)
set(ARMA_LIBS ${ARMA_LIBS} ${OpenBLAS_LIBRARIES})
else()
set(ARMA_LIBS ${ARMA_LIBS} ${BLAS_LIBRARIES})
endif()
endif()
if(ARMA_USE_LAPACK STREQUAL true)
set(ARMA_LIBS ${ARMA_LIBS} ${LAPACK_LIBRARIES})
endif()
if(ARMA_USE_ATLAS STREQUAL true)
set(ARMA_LIBS ${ARMA_LIBS} ${CBLAS_LIBRARIES})
set(ARMA_LIBS ${ARMA_LIBS} ${CLAPACK_LIBRARIES})
endif()
endif()
if(APPLE)
set(ARMA_LIBS ${ARMA_LIBS} "-framework Accelerate") # or "-framework accelerate" ?
message(STATUS "MacOS X detected. Added '-framework Accelerate' to compiler flags")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
message(STATUS "Clang compiler on MacOS X detected. Added '-stdlib=libc++' to compiler flags")
endif()
endif()
# find_package(HDF5)
# message(STATUS "HDF5_FOUND = ${HDF5_FOUND}")
#
# if(HDF5_FOUND)
# set(ARMA_USE_HDF5 true)
# set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${HDF5_INCLUDE_DIRS})
# set(ARMA_LIBS ${ARMA_LIBS} ${HDF5_LIBRARIES})
# endif()
include(ARMA_FindARPACK)
message(STATUS "ARPACK_FOUND = ${ARPACK_FOUND}")
if(ARPACK_FOUND)
set(ARMA_USE_ARPACK true)
set(ARMA_LIBS ${ARMA_LIBS} ${ARPACK_LIBRARY})
endif()
message(STATUS "")
message(STATUS "*** The run-time library component of Armadillo will use the following libraries:")
message(STATUS "*** ARMA_LIBS = ${ARMA_LIBS}")
message(STATUS "")
message(STATUS "Copying ${PROJECT_SOURCE_DIR}/include/ to ${PROJECT_BINARY_DIR}/build_tmp/include/")
file(COPY ${PROJECT_SOURCE_DIR}/include/ DESTINATION ${PROJECT_BINARY_DIR}/build_tmp/include/)
message(STATUS "Generating ${PROJECT_BINARY_DIR}/build_tmp/include/config.hpp")
configure_file(${PROJECT_BINARY_DIR}/build_tmp/include/armadillo_bits/config.hpp.cmake ${PROJECT_BINARY_DIR}/build_tmp/include/armadillo_bits/config.hpp)
message(STATUS "Generating ${PROJECT_SOURCE_DIR}/examples/Makefile")
configure_file(${PROJECT_SOURCE_DIR}/examples/Makefile.cmake ${PROJECT_SOURCE_DIR}/examples/Makefile)
include_directories(${PROJECT_BINARY_DIR}/build_tmp/include/)
## For any library that is not in a default location,
## embed its path into the Armadillo runtime library.
## Examples of default locations are "/lib", "/usr/lib",
## or as specified in "/etc/ld.so.conf".
##
## Path embedding is not recommended unless you know
## what you're doing. It might be better to add the
## path to the "/etc/ld.so.conf" file and then run "ldconfig".
##
#set(CMAKE_SKIP_BUILD_RPATH FALSE)
#set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
## work around a silly limitation in Mac OS X
if(APPLE)
if(${ARMA_MINOR} GREATER 99)
math(EXPR ARMA_MINOR_ALT "${ARMA_MINOR} / 10")
else()
set(ARMA_MINOR_ALT ${ARMA_MINOR})
endif()
else()
set(ARMA_MINOR_ALT ${ARMA_MINOR})
endif()
## necessary when linking with Intel MKL on Linux systems
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed")
endif()
## enable C++11 mode if available (TODO: replace with native Cmake handling of C++11)
## NOTE: as of gcc 4.8.2, thread_local is broken (link errors)
## NOTE: as of clang 3.3, thread_local is only partially supported (no support in clang libc++ runtime library)
# if(
# (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 4.9)
# OR
# (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT ${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 3.4)
# )
# set(ARMA_USE_CXX11_RNG true)
# add_definitions(-std=c++11)
# message(STATUS "Detected C++11 compiler. Using -std=c++11")
# endif()
if(CMAKE_COMPILER_IS_GNUCXX)
add_definitions(-O2)
endif()
message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}" )
message(STATUS "CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}")
add_library( armadillo SHARED ${PROJECT_SOURCE_DIR}/src/wrapper.cpp )
target_link_libraries( armadillo ${ARMA_LIBS} )
set_target_properties(armadillo PROPERTIES VERSION ${ARMA_MAJOR}.${ARMA_MINOR_ALT}.${ARMA_PATCH} SOVERSION ${ARMA_MAJOR})
################################################################################
# INSTALL CONFIGURATION
# As Red Hat Enterprise Linux (and related systems such as Fedora)
# does not search /usr/local/lib by default, we need to place the
# library in either /usr/lib or /usr/lib64
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
message(STATUS "*** CMAKE_INSTALL_PREFIX was initalised by cmake to the default value of ${CMAKE_INSTALL_PREFIX}")
message(STATUS "*** CMAKE_INSTALL_PREFIX changed to /usr")
unset(CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr")
#set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "install prefix" FORCE)
endif()
# Allow for the "lib" directory to be specified on the command line
if(NOT INSTALL_LIB_DIR)
set(INSTALL_LIB_DIR "lib")
if(UNIX AND NOT APPLE) # I don't know how Mac OS handles 64 bit systems
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "*** Detected 64 bit system")
# use "lib64" only on systems that have it (eg. Fedora, Red Hat).
# if installing in /usr/local/, the use of lib64 might be unreliable on systems which have /usr/local/lib64 but don't use it
if(IS_DIRECTORY "${CMAKE_INSTALL_PREFIX}/lib64")
unset(INSTALL_LIB_DIR)
set(INSTALL_LIB_DIR "lib64")
message(STATUS "*** ${CMAKE_INSTALL_PREFIX}/lib64/ exists, so destination directory for the run-time library changed to ${CMAKE_INSTALL_PREFIX}/lib64/")
message(STATUS "*** Your system and/or compiler must search ${CMAKE_INSTALL_PREFIX}/lib64/ during linking")
endif()
endif()
endif()
endif()
# Allow for the "include" directory to be specified on the command line
if(NOT INSTALL_INCLUDE_DIR)
set(INSTALL_INCLUDE_DIR "include")
endif()
# We use data dir to store files shared with other programs
# like the ArmadilloConfig.cmake file.
if(NOT INSTALL_DATA_DIR)
set(INSTALL_DATA_DIR "share")
endif()
# Make relative paths absolute so we can write them in Config.cmake files
foreach(p LIB INCLUDE DATA)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
message(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
message(STATUS "INSTALL_LIB_DIR = ${INSTALL_LIB_DIR}" )
message(STATUS "INSTALL_INCLUDE_DIR = ${INSTALL_INCLUDE_DIR}" )
message(STATUS "INSTALL_DATA_DIR = ${INSTALL_DATA_DIR}" )
# Note that the trailing / character in "include/" is critical
install(DIRECTORY ${PROJECT_BINARY_DIR}/build_tmp/include/ DESTINATION ${INSTALL_INCLUDE_DIR}
PATTERN ".svn" EXCLUDE
PATTERN "*.cmake" EXCLUDE
PATTERN "*~" EXCLUDE
PATTERN "*orig" EXCLUDE
)
install(TARGETS armadillo
DESTINATION ${INSTALL_LIB_DIR}
EXPORT ArmadilloLibraryDepends)
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE armadillo)
## LOCAL FILES
# Create ArmadilloConfig.cmake file for the use from the build tree
set(ARMADILLO_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
set(ARMADILLO_LIB_DIR "${PROJECT_BINARY_DIR}")
set(ARMADILLO_CMAKE_DIR "${PROJECT_BINARY_DIR}")
message(STATUS "Generating '${PROJECT_BINARY_DIR}/ArmadilloConfig.cmake'")
# copy/change config and configVersion file (modify only the @xyz@ variables)
configure_file(${PROJECT_SOURCE_DIR}/build_aux/cmake/InstallFiles/ArmadilloConfig.cmake.in
"${PROJECT_BINARY_DIR}/ArmadilloConfig.cmake" @ONLY)
message(STATUS "Generating '${PROJECT_BINARY_DIR}/ArmadilloConfigVersion.cmake'")
configure_file(${PROJECT_SOURCE_DIR}/build_aux/cmake/InstallFiles/ArmadilloConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/ArmadilloConfigVersion.cmake" @ONLY)
# Install the export set for use with the install-tree
install(EXPORT ArmadilloLibraryDepends DESTINATION
"${INSTALL_DATA_DIR}/Armadillo/CMake"
COMPONENT dev)
## GLOBAL INSTALL FILES
# Create ArmadilloConfig.cmake file for the use from the install tree
# and install it
set(ARMADILLO_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR}")
set(ARMADILLO_LIB_DIR "${INSTALL_LIB_DIR}")
set(ARMADILLO_CMAKE_DIR "${INSTALL_DATA_DIR}/Armadillo/CMake")
message(STATUS "Generating '${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfig.cmake'")
# copy/change config and configVersion file (modify only the @xyz@ variables)
configure_file(${PROJECT_SOURCE_DIR}/build_aux/cmake/InstallFiles/ArmadilloConfig.cmake.in
"${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfig.cmake" @ONLY)
message(STATUS "Generating '${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfigVersion.cmake'")
configure_file(${PROJECT_SOURCE_DIR}/build_aux/cmake/InstallFiles/ArmadilloConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfigVersion.cmake" @ONLY)
# Install files to be found by cmake users with find_package()
install(FILES
"${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfig.cmake"
"${PROJECT_BINARY_DIR}/InstallFiles/ArmadilloConfigVersion.cmake"
DESTINATION "${ARMADILLO_CMAKE_DIR}" COMPONENT dev)