This repository has been archived by the owner on Feb 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
341 lines (305 loc) · 11.5 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
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
cmake_minimum_required(VERSION 3.0.0)
set (CMAKE_CXX_STANDARD 11)
project(vespucci CXX)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMake")
option(BUILD_GUI "Build the GUI application, set to OFF to build only Library" ON)
option(BUILD_SHARED_LIBS "Build shared libraries (.so, .dll, .dylib)" ON)
# If using clang, we have to link against libc++ depending on thea
# 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_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_MODULE_LINKER_FLAGS
"${CMAKE_MODULE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()
# Link everything with -lm.
set(COMPILER_SUPPORT_LIBRARIES ${COMPILER_SUPPORT_LIBRARIES} "m")
set(LIBVESPUCCI_LIBRARIES ${LIBVESPUCCI_LIBRARIES} "m")
endif()
# Debugging CFLAGS. Turn optimizations off; turn debugging symbols on.
if(DEBUG)
if (NOT MSVC)
add_definitions(-DDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -ftemplate-backtrace-limit=0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -g -O0")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
endif()
# mlpack uses it's own mlpack::backtrace class based on Binary File Descriptor
# <bfd.h> and linux Dynamic Loader <libdl.h> and more portable version in future
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(Bfd)
find_package(LibDL)
if(LIBBFD_FOUND AND LIBDL_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
set(LIBVESPUCCI_INCLUDE_DIRS ${LIBVESPUCCI_INCLUDE_DIRS} ${LIBBFD_INCLUDE_DIRS}
${LIBDL_INCLUDE_DIRS})
set(LIBVESPUCCI_LIBRARIES ${LIBVESPUCCI_LIBRARIES} ${LIBBFD_LIBRARIES}
${LIBDL_LIBRARIES})
add_definitions(-DHAS_BFD_DL)
else()
message(WARNING "No libBFD and/or libDL has been found!")
endif()
endif()
else()
add_definitions(-DARMA_NO_DEBUG)
add_definitions(-DNDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -O3")
endif()
# Profiling CFLAGS. Turn profiling information on.
if(CMAKE_COMPILER_IS_GNUCC AND PROFILE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
endif()
# 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
# BOOST_ROOT - root of Boost installation
# BOOST_INCLUDEDIR - include directory for Boost
# BOOST_LIBRARYDIR - library directory for Boost
# MATHJAX_ROOT - root of MathJax installation
find_package(Armadillo 7.200.0 REQUIRED)
#force link lapack and blas,(if ARMA_USE_WRAPPER could be turned off TODO:check )
find_library(LAPACK_LIBRARY
NAMES lapack liblapack lapack_win32_MT lapack_win32
PATHS "C:/Program Files/Armadillo"
PATH_SUFFIXES "examples/lib_win32/")
if (NOT LAPACK_LIBRARY)
message(FATAL_ERROR "Cannot find LAPACK library (.lib)!")
endif ()
find_library(BLAS_LIBRARY
NAMES blas libblas blas_win32_MT blas_win32
PATHS "C:/Program Files/Armadillo"
PATH_SUFFIXES "examples/lib_win32/")
if (NOT BLAS_LIBRARY)
message(FATAL_ERROR "Cannot find BLAS library (.lib)!")
endif ()
# Piggyback LAPACK and BLAS linking into Armadillo link.
set(ARMADILLO_LIBRARIES
${ARMADILLO_LIBRARIES} ${BLAS_LIBRARY} ${LAPACK_LIBRARY})
# 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.55.0" "1.56.0" "1.57.0" "1.58.0" "1.59.0" "1.60.0" "1.61.0" "1.62.0" "1.63.0")
find_package(Boost 1.49
COMPONENTS
program_options
unit_test_framework
serialization
random
math_c99
REQUIRED
)
link_directories(${Boost_LIBRARY_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)
link_directories(${Boost_LIBRARY_DIRS})
set(Boost_LIBRARIES "")
endif ()
set(LIBVESPUCCI_INCLUDE_DIRS ${LIBVESPUCCI_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
set(LIBVESPUCCI_LIBRARIES ${LIBVESPUCCI_LIBRARIES} ${Boost_LIBRARIES})
set(LIBVESPUCCI_LIBRARY_DIRS ${LIBVESPUCCI_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
# Detect OpenMP support in a compiler. If the compiler supports OpenMP, flags
# to compile with OpenMP are returned and added and the HAS_OPENMP definition is
# added for compilation.
#
# This way we can skip calls to functions defined in omp.h with code like:
# #ifdef HAS_OPENMP
# {
# ... openMP code here ...
# }
# #endif
find_package(OpenMP REQUIRED)
if (OPENMP_FOUND)
add_definitions(-DHAS_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
else ()
# Disable warnings for all the unknown OpenMP pragmas.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
endif ()
# Include directories for the previous dependencies.
set(LIBVESPUCCI_INCLUDE_DIRS ${LIBVESPUCCI_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS})
set(LIBVESPUCCI_LIBRARIES ${LIBVESPUCCI_LIBRARIES} ${ARMADILLO_LIBRARIES})
# Store the mlpack include directory in MLPACK_INCLUDE_DIR.
# The PATHS variable may be specified to give hints for where to find core.hpp.
find_path(MLPACK_INCLUDE_DIR
NAMES core.hpp prereqs.hpp
PATHS "$ENV{ProgramFiles}/mlpack/"
/usr/local/include/
/usr/local/include/mlpack
/usr/include
/usr/include/mlpack
${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/mlpack
REQUIRED
)
# Find libmlpack.so (or equivalent) and store it in MLPACK_LIBRARY.
# If this example script were smarter, it would also find other dependencies of mlpack and store them in
# an MLPACK_LIBRARIES variable instead.
find_library(MLPACK_LIBRARY
NAMES mlpack
PATHS "$ENV{ProgramFiles}/mlpack/"
${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/mlpack
/usr/lib64/ /usr/lib/ /usr/local/lib64/ /usr/local/
REQUIRED
)
set(LIBVESPUCCI_INCLUDE_DIRS ${LIBVESPUCCI_INCLUDE_DIRS} ${MLPACK_INCLUDE_DIR})
set(LIBVESPUCCI_LIBRARIES ${LIBVESPUCCI_LIBRARIES} ${MLPACK_LIBRARY})
if (BUILD_GUI)
find_package(Qt5
COMPONENTS
Core
Gui
Svg
Widgets
PrintSupport
REQUIRED
)
set(VESPUCCI_INCLUDE_DIRS ${VESPUCCI_INCLUDE_DIRS}
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Svg_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5PrintSupport_INCLUDE_DIRS})
set(VESPUCCI_LIBRARIES ${VESPUCCI_LIBRARIES}
${Qt5Core_LIBRARIES}
${Qt5Gui_LIBRARIES}
${Qt5Svg_LIBRARES}
${Qt5Widgets_LIBRARIES}
${Qt5PrintSupport_LIBRARIES})
#CMake Qt things
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_path(EMFENGINE_INCLUDE_DIR
NAMES EmfEngine.h emfengine.h
PATHS /usr/include /usr/local/include /usr /usr/local
${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/EmfEngine
REQUIRED
)
find_library(EMFENGINE_LIBRARY
NAMES emfengine EmfEngine
PATHS /usr/lib64 /usr/lib /usr/local/lib64 /usr/local/
${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/EmfEngine/lib
REQUIRED
)
set(VESPUCCI_INCLUDE_DIRS ${VESPUCCI_INCLUDE_DIRS} ${EMFENGINE_INCLUDE_DIR})
set(VESPUCCI_LIBRARIES ${VESPUCCI_LIBRARIES} ${EMFENGINE_LIBRARY})
if (NOT WIN32) #libemf only required for non windows
find_path(LIBEMF_INCLUDE_DIR
NAMES emf.h
PATHS /usr/include/libemf /usr/include /usr/local/include
/usr/local/include/libemf
${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/libemf/include/libemf
REQUIRED
)
find_library(LIBEMF_LIBRARY
NAMES emf EMF
PATHS /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 /usr/local
${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/libemf/lib
REQUIRED
)
set(VESPUCCI_INCLUDE_DIRS ${VESPUCCI_INCLUDE_DIRS} ${LIBEMF_INCLUDE_DIR}
${LIBEMF_INCLUDE_DIR}/..)
set(VESPUCCI_LIBRARIES ${VESPUCCI_LIBRARIES} ${LIBEMF_LIBRARY})
endif()
find_path(YAMLCPP_INCLUDE_DIR
NAMES yaml.h
PATHS ${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/yaml-cpp
/usr/include /usr/local/include /usr /usr/local/
)
find_library(YAMLCPP_LIBRARY
NAMES libyaml-cpp
PATHS ${CMAKE_SOURCE_DIR}/../Vespucci_dependencies/yaml-cpp/lib
/usr/lib64 /usr/lib /usr/local/lib64 /usr/local)
find_package(HDF5
COMPONENTS
CXX
REQUIRED
)
set(VESPUCCI_INCLUDE_DIRS ${VESPUCCI_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS})
set(VESPUCCI_LIBRARIES ${VESPUCCI_LIBRARIES} ${HDF5_LIBRARIES})
include_directories(${VESPUCCI_INCLUDE_DIRS})
message(STATUS ${VESPUCCI_INCLUDE_DIRS})
endif()
include_directories(${CMAKE_SOURCE_DIR})
include_directories(${LIBVESPUCCI_INCLUDE_DIRS})
include_directories(${CMAKE_SOURCE_DIR}/VespucciLibrary/include)
include_directories(${CMAKE_SOURCE_DIR}/Vespucci)
# On Windows, things end up under Debug/ or Release/.
if (WIN32)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
else ()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/)
endif ()
#the above stuff relates to dependencies
#we may need to add more dirs later
set (DIRS
Vespucci
VespucciLibrary
Test
)
set (LIBVESPUCCI_INSTALL_DIRS
${CMAKE_CURRENT_SRC_DIR}/include
)
foreach(dir ${DIRS})
add_subdirectory(${dir})
endforeach()
# LIBVESPUCCI_SRCS is set in subdirs
add_library(libvespucci ${LIBVESPUCCI_SRCS})
target_link_libraries(libvespucci
${LIBVESPUCCI_LIBRARES})
target_compile_definitions(libvespucci PUBLIC -DVESPUCCI_LIBRARY) #to trigger symbol export
if(BUILD_GUI)
add_executable(vespucci ${VESPUCCI_SRCS})
target_link_libraries(vespucci
libvespucci
${LIBVESPUCCI_LIBRARIES}
${VESPUCCI_LIBRARIES}
)
set_target_properties(vespucci
PROPERTIES
VERSION 1.1
)
install (TARGETS vespucci
RUNTIME DESTINATION bin)
endif()
set_target_properties(libvespucci
PROPERTIES
VERSION 1.1
OUTPUT_NAME vespucci
)
#install the files
install(DIRECTORY ${CMAKE_SOURCE_DIR}/VespucciLibrary/include/
DESTINATION include/Vespucci)
install (TARGETS libvespucci
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)