-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
292 lines (271 loc) · 10.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
cmake_minimum_required(VERSION 3.5)
set(CMAKE_BUILD_TYPE Release)
project(cpptamcmc VERSION 1.86.7)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Boost_USE_MULTITHREADED TRUE)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin)
# Check for macOS
if(APPLE)
set(MACOS 1)
else()
set(MACOS 0)
endif()
# Check for Linux
if(CMAKE_COMPILER_IS_GNUCXX)
set(LINUX 1)
else()
set(LINUX 0)
endif()
if(NOT CMAKE_COMPILER_IS_GNUCXX AND NOT MACOS)
message(FATAL_ERROR "This program works only on Mac or Linux")
endif()
option(WITH_STATIC "Link Libraries Statically. Useful to port from one system to another" OFF)
option(WITH_GSL "GSL Library" ON)
option(WITH_OPENMP "OpenMP Library" ON)
option(BUILD_ON_DALMA "Building for NYU DALMA Supercomputer" OFF)
option(BUILD_ON_ZEN2 " Building on AMD Zen2 generation computers " OFF)
if(NOT BUILD_ON_DALMA)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -lstdc++fs")
if(WITH_OPENMP)
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -fopenmp")
endif()
if(BUILD_ON_ZEN2)
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -march=znver2")
endif()
endif()
if(APPLE)
if(WITH_STATIC)
message(FATAL_ERROR "Cannot compile statically on MacOS. Use it only for Linux systems. Turn it off by -DWITH_STATIC=OFF")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
if(WITH_OPENMP)
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -fopenmp")
endif()
endif()
else()
message(STATUS "Building for NYU DALMA Supercomputer...")
message(WARNING " - Remember to load the modules req uired for DALMA before running cmake")
message(STATUS " - Adding optimisation flags for DALMA...")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fopenmp -march=westmere")
option(USE_AVX "Build with AVX support" ON)
if(USE_AVX)
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -mavx2 -mfma -march=haswell")
else()
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -msse4.2")
endif()
endif()
# Check and Load dependencies
find_package(Gnuplot REQUIRED)
if(NOT GNUPLOT_FOUND)
message(FATAL_ERROR "Gnuplot is required for rendering. Cannot pursue. Please install gnuplot")
endif()
# The check for OpenMP is only done once
if (WITH_OPENMP)
find_package(OpenMP REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
#else()
# message(FATAL_ERROR "OpenMP not found. Use -DWITH_OPENMP=OFF to build without OpenMP")
endif()
if(WITH_GSL)
add_definitions(/DTAMCMC_WITH_GSL)
find_package(GSL REQUIRED)
if(NOT GSL_FOUND)
message(FATAL_ERROR "GSL not found. Use -DWITH_GSL=OFF to build without GSL")
endif()
if(WITH_STATIC)
find_library(GSL_LIB
NAMES gsl
PATHS /usr/local/lib /usr/lib/x86_64-linux-gnu
)
get_filename_component(GSL_LIB_DIR ${GSL_LIB} DIRECTORY)
#set(GSL_LIB /usr/local/lib/libgsl.a)
else()
set(GSL_LIB GSL::gsl)
endif()
endif()
#find_package(ZLIB REQUIRED)
# Set LibArchive_INCLUDE_DIR and LibArchive_LIBRARY in your bashrc
if(CMAKE_COMPILER_IS_GNUCXX)
find_package(LibArchive REQUIRED)
find_package(ZLIB REQUIRED)
get_filename_component(ZLIB_LIBRARIES_DIR ${ZLIB_LIBRARIES} DIRECTORY)
else()
include_directories($ENV{LibArchive_INCLUDE_DIR})
find_library(LibArchive_LIBRARY NAMES archive)
find_path(LibArchive_INCLUDE_DIR archive.h)
endif()
get_filename_component(LibArchive_LIBRARY_DIR ${LibArchive_LIBRARY} DIRECTORY)
#Bring the core program sources into the project
set(SOURCES_MAIN #_COMMON
tamcmc/sources/main.cpp
tamcmc/sources/MALA.cpp
tamcmc/sources/matrices.cpp
tamcmc/sources/outputs.cpp
tamcmc/sources/build_lorentzian.cpp
tamcmc/sources/derivatives_handler.cpp
tamcmc/sources/interpol.cpp
tamcmc/sources/model_def.cpp
tamcmc/sources/priors_calc.cpp
tamcmc/sources/config.cpp
tamcmc/sources/diagnostics.cpp
tamcmc/sources/io_ms_global.cpp
tamcmc/sources/io_local.cpp
tamcmc/sources/io_asymptotic.cpp
tamcmc/sources/io_ajfit.cpp
tamcmc/sources/models.cpp
tamcmc/sources/stats_dictionary.cpp
tamcmc/sources/config_presets.cpp
tamcmc/sources/function_rot.cpp
tamcmc/sources/likelihoods.cpp
tamcmc/sources/noise_models.cpp
tamcmc/sources/string_handler.cpp
tamcmc/sources/ben_timer.cpp
tamcmc/sources/multivariate_cholesky.cpp
tamcmc/sources/random_JB.cpp
tamcmc/sources/io_models.cpp
tamcmc/sources/acoefs.cpp
tamcmc/sources/polyfit.cpp
external/ARMM/solver_mm.cpp
external/ARMM/bump_DP.cpp
external/ARMM/linfit.cpp
external/Alm/Alm_cpp/activity.cpp
external/Alm/Alm_cpp/Alm_interpol.cpp
external/Alm/Alm_cpp/bilinear_interpol.cpp
)
#Define the sources for the bin2txt program
set(SOURCES_TOOLS_BIN2TXT
tools/bin2txt_params.cpp
tools/quick_samples_stats.cpp
tamcmc/sources/interpol.cpp
tamcmc/sources/diagnostics.cpp
tamcmc/sources/string_handler.cpp
)
#Define the sources for the getstats program
set(SOURCES_TOOLS_GETSTATS
tools/getstats.cpp
tamcmc/sources/string_handler.cpp
)
#Define the sources for the getevidence program
set(SOURCES_TOOLS_GETEVIDENCE
tools/getevidence.cpp
tools/quick_samples_stats.cpp
tools/bootstrap/bootstrap_algos.cpp
tamcmc/sources/string_handler.cpp
tamcmc/sources/interpol.cpp
tamcmc/sources/diagnostics.cpp
)
#Define the sources for the getmodel program
set(SOURCES_TOOLS_GETMODEL
tools/getmodel.cpp
tamcmc/sources/models.cpp
tamcmc/sources/model_def.cpp
tamcmc/sources/string_handler.cpp
tamcmc/sources/config.cpp
tamcmc/sources/function_rot.cpp
tamcmc/sources/likelihoods.cpp
tamcmc/sources/build_lorentzian.cpp
tamcmc/sources/interpol.cpp
tamcmc/sources/matrices.cpp
tamcmc/sources/io_ms_global.cpp
tamcmc/sources/io_local.cpp
tamcmc/sources/io_asymptotic.cpp
tamcmc/sources/io_ajfit.cpp
tamcmc/sources/noise_models.cpp
tamcmc/sources/priors_calc.cpp
tamcmc/sources/stats_dictionary.cpp
tamcmc/sources/derivatives_handler.cpp
tamcmc/sources/io_models.cpp
tamcmc/sources/linfit.cpp
tamcmc/sources/polyfit.cpp
tamcmc/sources/acoefs.cpp
external/ARMM/solver_mm.cpp
external/ARMM/bump_DP.cpp
external/Alm/Alm_cpp/activity.cpp
external/Alm/Alm_cpp/Alm_interpol.cpp
external/Alm/Alm_cpp/bilinear_interpol.cpp
)
#Look for eigen and explicitly specify to use it. EIGEN3_INCLUDE_DIR Must be specified in the bashrc
include_directories( "$ENV{EIGEN3_INCLUDE_DIR}" )
include_directories(tamcmc/headers)
include_directories(tools/bootstrap)
#Dependencies that are not portable (BOOST)
find_package(Boost COMPONENTS system filesystem iostreams program_options REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
add_executable(${CMAKE_PROJECT_NAME} ${SOURCES_MAIN} ${DIAG_SRC})
add_executable(bin2txt ${SOURCES_TOOLS_BIN2TXT} ${DIAG_SRC})
add_executable(getstats ${SOURCES_TOOLS_GETSTATS})
add_executable(getevidence ${SOURCES_TOOLS_GETEVIDENCE})
add_executable(getmodel ${SOURCES_TOOLS_GETMODEL})
#target_link_libraries(bin2txt ${Boost_SYSTEM_LIBRARY_RELEASE} ${Boost_FILESYSTEM_LIBRARY_RELEASE} ${Boost_IOSTREAMS_LIBRARY_RELEASE} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY})
if (WITH_STATIC)
target_link_libraries(${CMAKE_PROJECT_NAME} -static
${Boost_LIBRARY_DIRS}/libboost_system.a
${Boost_LIBRARY_DIRS}/libboost_filesystem.a
${Boost_LIBRARY_DIRS}/libboost_iostreams.a
${Boost_LIBRARY_DIRS}/libboost_program_options.a
#/usr/local/lib/libgsl.a
${GSL_LIB_DIR}/libgsl.a
-lz
${LibArchive_LIBRARY_DIR}/libarchive.a
${ZLIB_LIBRARIES_DIR}/libz.a)
target_link_libraries(bin2txt -static
${Boost_LIBRARY_DIRS}/libboost_system.a
${Boost_LIBRARY_DIRS}/libboost_filesystem.a
${Boost_LIBRARY_DIRS}/libboost_iostreams.a
${Boost_LIBRARY_DIRS}/libboost_program_options.a
#/usr/local/lib/libgsl.a
${GSL_LIB_DIR}/libgsl.a
-lz
${LibArchive_LIBRARY_DIR}/libarchive.a
${ZLIB_LIBRARIES_DIR}/libz.a)
target_link_libraries(getstats -static
${Boost_LIBRARY_DIRS}/libboost_system.a
${Boost_LIBRARY_DIRS}/libboost_filesystem.a
${Boost_LIBRARY_DIRS}/libboost_iostreams.a
${Boost_LIBRARY_DIRS}/libboost_program_options.a
${GSL_LIB_DIR}/libgsl.a
#/usr/local/lib/libgsl.a
-lz
${LibArchive_LIBRARY_DIR}/libarchive.a
${ZLIB_LIBRARIES_DIR}/libz.a)
target_link_libraries(getevidence -static
${Boost_LIBRARY_DIRS}/libboost_system.a
${Boost_LIBRARY_DIRS}/libboost_filesystem.a
${Boost_LIBRARY_DIRS}/libboost_iostreams.a
${Boost_LIBRARY_DIRS}/libboost_program_options.a
${GSL_LIB_DIR}/libgsl.a
#/usr/local/lib/libgsl.a
-lz
${LibArchive_LIBRARY_DIR}/libarchive.a
${ZLIB_LIBRARIES_DIR}/libz.a)
target_link_libraries(getmodel -static
${Boost_LIBRARY_DIRS}/libboost_system.a
${Boost_LIBRARY_DIRS}/libboost_filesystem.a
${Boost_LIBRARY_DIRS}/libboost_iostreams.a
${Boost_LIBRARY_DIRS}/libboost_program_options.a
${GSL_LIB_DIR}/libgsl.a
#/usr/local/lib/libgsl.a
-lz)
else()
if(MACOS)
find_package(Eigen3 REQUIRED NO_MODULE)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE MACOS)
target_link_libraries(${CMAKE_PROJECT_NAME} ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY} Eigen3::Eigen ) # ${ZLIB_LIBRARIES}
target_link_libraries(bin2txt ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY} Eigen3::Eigen ) # ${ZLIB_LIBRARIES}
target_link_libraries(getstats ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY} Eigen3::Eigen )
target_link_libraries(getevidence ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY} Eigen3::Eigen )
target_link_libraries(getmodel ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} Eigen3::Eigen )
elseif(LINUX)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE LINUX)
target_link_libraries(${CMAKE_PROJECT_NAME} ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY}) # ${ZLIB_LIBRARIES}
target_link_libraries(bin2txt ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY}) # ${ZLIB_LIBRARIES}
target_link_libraries(getstats ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY})
target_link_libraries(getevidence ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ${LibArchive_LIBRARY})
target_link_libraries(getmodel ${Boost_LIBRARIES} ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY})
endif()
endif()