-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
333 lines (288 loc) · 11.4 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
# ============================================================================
# vSMC/CMakeLists.txt
# ----------------------------------------------------------------------------
# vSMC: Scalable Monte Carlo
# ----------------------------------------------------------------------------
# Copyright (c) 2013-2016, Yan Zhou
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
# ============================================================================
CMAKE_MINIMUM_REQUIRED(VERSION 3.0.0)
# Disable in source build
IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
MESSAGE(FATAL_ERROR "In-source builds not allowed")
ENDIF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
PROJECT(vSMC C CXX)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
# Options
OPTION(VSMC_ENABLE_LIBRARY "Enable building of library" ON)
OPTION(VSMC_ENABLE_EXAMPLE "Enable building of example" ON)
# User configurations
IF(EXISTS ${PROJECT_SOURCE_DIR}/user_options.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/user_options.cmake)
ENDIF(EXISTS ${PROJECT_SOURCE_DIR}/user_options.cmake)
# Configuration files
FILE(READ ${PROJECT_SOURCE_DIR}/README.md README)
FILE(READ ${PROJECT_SOURCE_DIR}/NEWS.md NEWS)
SET(DOC_SOURCE ${PROJECT_SOURCE_DIR}/doc)
SET(DOC_INCLUDE ${PROJECT_SOURCE_DIR}/include)
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/config/Doxyfile.in
${PROJECT_BINARY_DIR}/Doxyfile)
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/config/main.md.in
${PROJECT_SOURCE_DIR}/doc/main.md)
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/config/news.md.in
${PROJECT_SOURCE_DIR}/doc/news.md)
# Installation
IF(NOT VSMC_INSTALL_INC_DIR)
SET(VSMC_INSTALL_INC_DIR include)
ENDIF(NOT VSMC_INSTALL_INC_DIR)
INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/include/vsmc
DESTINATION ${VSMC_INSTALL_INC_DIR}/vsmc
PATTERN ".DS_Store" EXCLUDE PATTERN "*.swp" EXCLUDE)
# Documentations
INCLUDE(FindDoxygen)
FILE(GLOB_RECURSE DOC_SOURCE_FILES ${PROJECT_SOURCE_DIR}/doc/*.*)
FILE(GLOB_RECURSE DOC_INCLUDE_FILES_C ${PROJECT_SOURCE_DIR}/include/*.h)
FILE(GLOB_RECURSE DOC_INCLUDE_FILES_CPP ${PROJECT_SOURCE_DIR}/include/*.hpp)
IF(DOXYGEN_FOUND)
ADD_CUSTOM_COMMAND(
OUTPUT ${PROJECT_BINARY_DIR}/doc
DEPENDS ${PROJECT_BINARY_DIR}/Doxyfile
${DOC_SOURCE_FILES} ${DOC_INCLUDE_FILES_C} ${DOC_INCLUDE_FILES_CPP}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND ${DOXYGEN_EXECUTABLE} ARGS Doxyfile)
ADD_CUSTOM_TARGET(docs DEPENDS ${PROJECT_BINARY_DIR}/doc)
ENDIF(DOXYGEN_FOUND)
IF(NOT VSMC_ENABLE_LIBRARY AND NOT VSMC_ENABLE_EXAMPLE)
RETURN()
ENDIF(NOT VSMC_ENABLE_LIBRARY AND NOT VSMC_ENABLE_EXAMPLE)
##############################################################################
# Essential
##############################################################################
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
-D__STDC_CONSTANT_MACROS)
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
-D__CL_ENABLE_EXCEPTIONS)
IF(APPLE)
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -U__OBJC__)
SET(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -U__OBJC2__)
ENDIF(APPLE)
SET(VSMC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
SET(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${VSMC_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${VSMC_INCLUDE_DIR})
##############################################################################
# Check backends
##############################################################################
SET(SMP_EXECUTABLES)
# Sequential
SET(BACKENDS "Sequential")
SET(SMP_EXECUTABLES ${SMP_EXECUTABLES} seq)
# Thread
INCLUDE(FindThread)
IF(THREAD_FOUND)
SET(VSMC_LINK_LIBRARIES ${VSMC_LINK_LIBRARIES} ${Thread_LINK_LIBRARIES})
ENDIF(THREAD_FOUND)
# Intel TBB
INCLUDE(FindTBB)
IF(TBB_FOUND)
SET(BACKENDS ${BACKENDS} "Intel TBB")
SET(SMP_EXECUTABLES ${SMP_EXECUTABLES} tbb)
ADD_DEFINITIONS(${TBB_DEFINITIONS})
ADD_DEFINITIONS(-DVSMC_HAS_TBB=1)
INCLUDE_DIRECTORIES(SYSTEM ${TBB_INCLUDE_DIR})
SET(VSMC_LINK_LIBRARIES ${VSMC_LINK_LIBRARIES} ${TBB_LINK_LIBRARIES})
ELSE(TBB_FOUND)
UNSET(TBB_FOUND CACHE)
SET(TBB_FOUND FALSE CACHE BOOL "NOT Found Intel TBB")
ENDIF(TBB_FOUND)
# OpenMP
IF(NOT DEFINED OPENMP_FOUND)
INCLUDE(FindOpenMP)
ENDIF(NOT DEFINED OPENMP_FOUND)
IF(OPENMP_FOUND)
SET(BACKENDS ${BACKENDS} "OpenMP")
SET(SMP_EXECUTABLES ${SMP_EXECUTABLES} omp)
SET(OPENMP_FOUND TRUE CACHE BOOL "Found OpenMP")
ELSE(OPENMP_FOUND)
UNSET(OPENMP_FOUND CACHE)
SET(OPENMP_FOUND FALSE CACHE BOOL "NOT Found OpenMP")
ENDIF(OPENMP_FOUND)
# SMP executables
FOREACH(smp ${SMP_EXECUTABLES})
ADD_CUSTOM_TARGET(example_${smp})
ENDFOREACH(smp)
##############################################################################
# Check features
##############################################################################
SET(FEATURES)
# Boost
INCLUDE(FindBoost)
IF(Boost_FOUND)
SET(FEATURES ${FEATURES} "Boost")
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
ENDIF(Boost_FOUND)
# 128-bits integer type
INCLUDE(FindInt128)
IF(INT128_FOUND)
SET(FEATURES ${FEATURES} "128-bits integer type")
ADD_DEFINITIONS(-DVSMC_HAS_INT128=1)
ADD_DEFINITIONS(-DVSMC_INT128=${INT128_TYPE})
ELSE(INT128_FOUND)
ADD_DEFINITIONS(-DVSMC_HAS_INT128=0)
UNSET(INT128_FOUND)
SET(INT128_FOUND FALSE CACHE BOOL "NOT Found int128")
ENDIF(INT128_FOUND)
# MKL
INCLUDE(FindMKL)
IF(MKL_FOUND)
SET(FEATURES ${FEATURES} "Intel MKL")
SET(VSMC_LINK_LIBRARIES ${VSMC_LINK_LIBRARIES} ${MKL_LINK_LIBRARIES})
ADD_DEFINITIONS(-DVSMC_HAS_MKL=1)
INCLUDE_DIRECTORIES(SYSTEM ${MKL_INCLUDE_DIR})
ELSE(MKL_FOUND)
UNSET(MKL_FOUND CACHE)
SET(MKL_FOUND FALSE CACHE BOOL "NOT Found Intel MKL")
INCLUDE(FindBLAS)
IF(BLAS_FOUND)
SET(VSMC_LINK_LIBRARIES ${VSMC_LINK_LIBRARIES} ${BLAS_LIBRARIES})
ENDIF(BLAS_FOUND)
ENDIF(MKL_FOUND)
# TBB malloc
IF(TBB_FOUND AND TBB_MALLOC_LINK_LIBRARIES)
SET(FEATURES ${FEATURES} "Intel TBB scalable allocator")
SET(TBB_MALLOC_FOUND TRUE CACHE BOOL "Found Intel TBB malloc")
SET(VSMC_LINK_LIBRARIES ${VSMC_LINK_LIBRARIES}
${TBB_MALLOC_LINK_LIBRARIES})
ADD_DEFINITIONS(-DVSMC_HAS_TBB_MALLOC=1)
ELSE(TBB_FOUND AND TBB_MALLOC_LINK_LIBRARIES)
ADD_DEFINITIONS(-DVSMC_HAS_TBB_MALLOC=0)
UNSET(TBB_MALLOC_FOUND CACHE)
SET(TBB_MALLOC_FOUND FALSE CACHE BOOL "NOT Found Intel TBB malloc")
ENDIF(TBB_FOUND AND TBB_MALLOC_LINK_LIBRARIES)
# AES-NI
INCLUDE(FindAESNI)
IF(AESNI_FOUND)
SET(FEATURES ${FEATURES} "AES-NI")
ADD_DEFINITIONS(-DVSMC_HAS_AES_NI=1)
ELSE(AESNI_FOUND)
ADD_DEFINITIONS(-DVSMC_HAS_AES_NI=0)
UNSET(AESNI_FOUND CACHE)
SET(AESNI_FOUND FALSE CACHE BOOL "NOT Found AES-NI")
ENDIF(AESNI_FOUND)
# AVX2
INCLUDE(FindAVX2)
IF(AVX2_FOUND)
SET(FEATURES ${FEATURES} "AVX2")
ADD_DEFINITIONS(-DVSMC_HAS_AVX2=1)
ELSE(AVX2_FOUND)
ADD_DEFINITIONS(-DVSMC_HAS_AVX2=0)
UNSET(AVX2_FOUND CACHE)
SET(AVX2_FOUND FALSE CACHE BOOL "NOT Found AVX2")
ENDIF(AVX2_FOUND)
# SSE2
INCLUDE(FindSSE2)
IF(SSE2_FOUND)
SET(FEATURES ${FEATURES} "SSE2")
ADD_DEFINITIONS(-DVSMC_HAS_SSE2=1)
ELSE(SSE2_FOUND)
ADD_DEFINITIONS(-DVSMC_HAS_SSE2=0)
UNSET(SSE2_FOUND CACHE)
SET(SSE2_FOUND FALSE CACHE BOOL "NOT Found SSE2")
ENDIF(SSE2_FOUND)
# RDRAND
INCLUDE(FindRDRAND)
IF(RDRAND_FOUND)
SET(FEATURES ${FEATURES} "RDRAND")
ADD_DEFINITIONS(-DVSMC_HAS_RDRAND=1)
ELSE(RDRAND_FOUND)
ADD_DEFINITIONS(-DVSMC_HAS_RDRAND=0)
UNSET(RDRAND_FOUND CACHE)
SET(RDRAND_FOUND FALSE CACHE BOOL "NOT Found RDRAND")
ENDIF(RDRAND_FOUND)
# Linux librt
IF(UNIX AND NOT APPLE AND NOT DEFINED LINUX_LIBRT)
FIND_LIBRARY(LINUX_LIBRT rt)
ENDIF(UNIX AND NOT APPLE AND NOT DEFINED LINUX_LIBRT)
IF(LINUX_LIBRT)
SET(VSMC_LINK_LIBRARIES ${VSMC_LINK_LIBRARIES} ${LINUX_LIBRT})
ENDIF(LINUX_LIBRT)
# HDF5
INCLUDE(FindHDF5)
IF(HDF5_FOUND)
SET(FEATURES ${FEATURES} "HDF5")
ADD_DEFINITIONS(-DVSMC_HAS_HDF5=1)
INCLUDE_DIRECTORIES(SYSTEM ${HDF5_INCLUDE_DIRS})
SET(VSMC_LINK_LIBRARIES ${VSMC_LINK_LIBRARIES} ${HDF5_LIBRARIES})
ELSE(HDF5_FOUND)
UNSET(HDF5_FOUND CACHE)
SET(HDF5_FOUND FALSE CACHE BOOL "NOT Found HDF5")
ENDIF(HDF5_FOUND)
##############################################################################
# Macros
##############################################################################
# Make sure __STDC_CONSTANT_MACROS is defined
ADD_DEFINITIONS(-D__STDC_CONSTANT_MACROS)
# Workaround for vanilla GCC on Mac OS X
IF(APPLE)
ADD_DEFINITIONS(-U__OBJC__)
ADD_DEFINITIONS(-U__OBJC2__)
ENDIF(APPLE)
# Disable MSVC iterator warning
IF(MSVC)
ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)
ENDIF(MSVC)
##############################################################################
# Enable backends
##############################################################################
MESSAGE(STATUS "=================== Enable backends ===================")
FOREACH(backend ${BACKENDS})
MESSAGE(STATUS ${backend})
ENDFOREACH(backend ${BACKENDS})
##############################################################################
# Enable features
##############################################################################
MESSAGE(STATUS "=================== Enable features ===================")
FOREACH(feature ${FEATURES})
MESSAGE(STATUS ${feature})
ENDFOREACH(feature ${FEATURES})
MESSAGE(STATUS "Linked libraries: ${VSMC_LINK_LIBRARIES}")
##############################################################################
# Library
##############################################################################
IF(VSMC_ENABLE_LIBRARY AND MKL_FOUND)
ADD_CUSTOM_TARGET(lib)
ADD_SUBDIRECTORY(lib EXCLUDE_FROM_ALL)
ADD_DEFINITIONS(-DVSMC_HAS_RUNTIME_LIBRARY=1)
ELSE(VSMC_ENABLE_LIBRARY AND MKL_FOUND)
ADD_DEFINITIONS(-DVSMC_HAS_RUNTIME_LIBRARY=0)
ENDIF(VSMC_ENABLE_LIBRARY AND MKL_FOUND)
##############################################################################
# Example
##############################################################################
IF(VSMC_ENABLE_EXAMPLE AND (MKL_FOUND OR BLAS_FOUND))
ADD_CUSTOM_TARGET(example)
ADD_CUSTOM_TARGET(check)
ADD_CUSTOM_TARGET(pdf)
ADD_SUBDIRECTORY(example EXCLUDE_FROM_ALL)
ENDIF(VSMC_ENABLE_EXAMPLE AND (MKL_FOUND OR BLAS_FOUND))