forked from Chrismarsh/CHM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
executable file
·365 lines (286 loc) · 11.9 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
cmake_minimum_required (VERSION 3.16)
project (CHM-project CXX Fortran)
# In CMake 3.12 and above the find_package(<PackageName>) command now searches prefixes specified by the <PackageName>_ROOT
# CMake variable and the <PackageName>_ROOT environment variable.
#https://cmake.org/cmake/help/latest/policy/CMP0074.html
cmake_policy(SET CMP0074 NEW)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
#http://stackoverflow.com/questions/31561309/cmake-warnings-under-os-x-macosx-rpath-is-not-specified-for-the-following-targe
#https://cmake.org/cmake/help/v3.0/policy/CMP0042.html
set(CMAKE_MACOSX_RPATH 1)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
set(CMAKE_FIND_FRAMEWORK NEVER) #Can cause frameworks to take priority over superbuild libraries
endif()
# Options. Turn on with 'cmake -Dmyvarname=ON'.
option(USE_MPI "Enable MPI" OFF )
option(USE_OMP "Enable OpenMP" ON )
option(BUILD_TESTS "Build all tests." OFF ) # Makes boolean 'test' available.
option(MATLAB "Enable Matlab linkage" OFF )
option(STATIC_ANLAYSIS "Enable PVS static anlaysis" OFF)
option(USE_TCMALLOC "Use tcmalloc from gperftools " ON)
option(BUILD_DOCS "Builds documentation" OFF)
set(ENABLE_SAFE_CHECKS FALSE CACHE BOOL "Enable variable map checking. Runtime perf cost. Enable to debug")
option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." TRUE)
if (${FORCE_COLORED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()
LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}")
LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/CMake/")
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/")
#########
# Helper macro that removes cxx flag flags
macro(remove_cxx_flag flag)
string(REPLACE "${flag}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endmacro()
# lovely CMake script to integrate git hashes
# http://xit0.org/2013/04/cmake-use-git-branch-and-commit-details-in-project/
# Get the current working branch
# Generate gitrevision.hh if Git is available
# and the .git directory is present
# this is the case when the software is checked out from a Git repo
find_program(GIT_SCM git DOC "Git version control")
mark_as_advanced(GIT_SCM)
find_file(GITDIR NAMES .git PATHS ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${GITDIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${GITDIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
configure_file(
src/version.h.in
src/version.h
)
#ignore these two under Clion as CGAL will complain
if(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo OR
CMAKE_BUILD_TYPE MATCHES MinSizeRel OR
NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# ---------------------------------------------------------------
# ------ Start of find_package section --------------------------
# ---------------------------------------------------------------
# Need to check for MPI before building external libraries
find_package(MPI)
if(MPI_FOUND AND USE_MPI)
message(STATUS "Found MPI at ${MPI_CXX_INCLUDE_DIRS}")
add_definitions(-DUSE_MPI)
file(READ ${CMAKE_BINARY_DIR}/FindBoost.cmake txt)
string(FIND "${txt}" "boost_mpi" RETCODE)
if(${RETCODE} EQUAL -1) # -1 is not found retcode from find
message(FATAL_ERROR "MPI was asked for, however boost was not built with mpi. Please build boost (--build boost) locally with a working MPI. See wiki for more information.")
endif()
else()
message(WARNING "MPI not enabled. Building for single process.")
endif()
if(USE_MPI AND NOT MPI_FOUND)
message(FATAL_ERROR "MPI was asked for, but not found")
endif()
if(USE_MPI AND MPI_FOUND)
find_package(Boost
1.71.0
COMPONENTS
system
filesystem
date_time
log
thread
regex
iostreams
program_options
mpi
serialization
REQUIRED)
else()
find_package(Boost
1.71.0
COMPONENTS
system
filesystem
date_time
log
thread
regex
iostreams
program_options
REQUIRED
)
endif()
#need this for calling the logger from multiple modules
ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
#Set this as CGAL, etc can try to look for Boost as well
set(BOOST_ROOT ${Boost_INCLUDE_DIR}/../)
#as per http://cgal-discuss.949826.n4.nabble.com/CMake-and-flags-td949906.html
#don't override internal settings
set( CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE )
find_package(cgal REQUIRED)
if(CGAL_FOUND)
message(STATUS "Found CGAL ")
# There is a bug in clang <11 (so far), that has a compiler parse error w/ boost 1.71
# https://bugs.llvm.org/show_bug.cgi?id=43266
# https://github.com/Oslandia/SFCGAL/issues/188
# https://stackoverflow.com/questions/57857572/why-does-boost-log-break-boost-gmp-multiprecision
# But CGAL uses boost/mp which appears to cause this problem. So if we see clang, disable boost MP usage.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" )
ADD_DEFINITIONS(-DCGAL_DO_NOT_USE_BOOST_MP)
message(WARNING "Disabling CGAL's use of boost mp to avoid clang compiler parse error.")
endif()
endif()
#remove this flag as it destroys the build on -O1 and spams warnings, #thankscgal
remove_cxx_flag("-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2")
remove_cxx_flag("-O2")
remove_cxx_flag("-O3")
#reset these back
if (CMAKE_BUILD_TYPE MATCHES Debug)
message(WARNING "Debug mode")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.7")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O1 -fno-inline") #new to 4.8 https://gcc.gnu.org/gcc-4.8/changes.html
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -O1 -fno-inline -ggdb")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSAFE_CHECKS")
else()
if(ENABLE_SAFE_CHECKS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSAFE_CHECKS")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 ")
endif()
#Setup CXX flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-variable -Wno-unknown-pragmas")
#GAL requires strict rounding
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -qoverride-limits -fp-model strict -msse4 -finline ") #-frounding-math needed for cgal
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") # OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frounding-math")
endif()
########
if(USE_OMP)
find_package(OpenMP )
if(OpenMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
#should correctly work with cmake 3.12+ https://iscinumpy.gitlab.io/post/omp-on-high-sierra/
endif()
endif()
if(MATLAB)
#for matlab to run you need csh installed
find_package(Matlab REQUIRED)
endif()
find_package(meteoio REQUIRED)
find_package(armadillo REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(sparsehash)
# The trilinos library may have been built against a custom location blas/openblas
# If so, conaninfo.txt has information on the custom blas location if given with the -o trilinos:blas_root=<root> option
# If conaninfo.txt has a custom blas location, extract it and pass it as a hint to find_package(blas) which will detect any blas.
# Then use the find_package link target in CHM to fully avoid any problems of linking against the wrong blas or not being able to find it.
if(EXISTS "${CMAKE_BINARY_DIR}/conaninfo.txt")
file(READ ${CMAKE_BINARY_DIR}/conaninfo.txt conaninfotxt)
string(REGEX MATCH "trilinos:blas_root=([^ ]+)lib" blasloc "${conaninfotxt}") # because cmake regex is only greedy
if(NOT "${blasloc}" STREQUAL "")
string(REPLACE "\n" "" blasloc ${CMAKE_MATCH_1}) # strip out a new line we've picked up
message(WARNING "Using the conaninfo.txt trilinos:blas_root=${blasloc}")
set(BLAS_ROOT ${blasloc})
endif()
elseif()
set(blasloc "")
endif()
if(MACOSX AND "${blasloc}" STREQUAL "")
execute_process(
COMMAND brew --prefix openblas
RESULT_VARIABLE BREW_BLAS
OUTPUT_VARIABLE BREW_BLAS_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(BREW_BLAS EQUAL 0)
message(WARNING "Found homebrew OpenBLAS ${BREW_BLAS_PREFIX}" )
set(BLAS_ROOT ${BREW_BLAS_PREFIX})
set(BLA_VENDOR Generic)
endif()
endif()
find_package(BLAS
REQUIRED
)
# cmake < 3.18 doesn't produce a BLAS target
if(NOT TARGET BLAS::BLAS)
add_library(BLAS::BLAS INTERFACE IMPORTED)
set_property(TARGET BLAS::BLAS PROPERTY INTERFACE_LINK_LIBRARIES ${BLAS_LIBRARIES})
set_property(TARGET BLAS::BLAS PROPERTY INTERFACE_COMPILE_OPTIONS ${BLAS_LINKER_FLAGS})
endif()
#sparsehash doesn't compile with gcc 4.6.x - 4.8.x because of this
# https://bugs.launchpad.net/ubuntu/+source/gcc-4.6/+bug/1269803
# so we need to optionally disable it
if( SPARSEHASH_FOUND )
add_definitions(-DUSE_SPARSEHASH)
else()
set(SPARSEHASH_INCLUDE_DIRS "")
endif()
find_package(gperftools)
if(gperftools_FOUND) #gperftools may not compile on machines w/o nanosleep so we need to optionall disable if it fails to compile
message(STATUS "Found Tcmalloc, disabling builtin malloc, free")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free")
else()
set(Tcmalloc_INCLUDE_DIR "")
set(Tcmalloc_LIBRARY "")
endif()
find_package(func REQUIRED)
find_package(gdal 2.4 REQUIRED )
find_package (Threads REQUIRED)
find_package(tbb REQUIRED tbb)
find_package(gsl REQUIRED)
set(NETCDF_CXX "YES")
find_package(netcdf-cxx REQUIRED)
message(STATUS "netcdf lib ${NETCDF_LIBRARIES}")
#To avoid issues #104, newer VTK version needs to be used.
#8.1+ needs to be used so that proj4 name-collisions are resolved
# http://vtk.1045678.n5.nabble.com/Don-t-build-vtkproj4-td5746073.html
#N.B: The find VTK doesn't allow for compatibility between major versions. That is, if we ask for v7, v8 won't be allowed.
#Therefore we need to ensure this version is up-to-date with what we are building. There are likely issues with VTK6 as per issue #104
# so for now, we will accept finding *any* VTK version, but will flag it and error if we find <=6
find_package(vtk
COMPONENTS
CommonCore
CommonDataModel
CommonTransforms
FiltersCore
FiltersGeneral
FiltersGeometry
FiltersSources
IOXML
REQUIRED)
if(VTK_MAJOR_VERSION LESS 7)
#https://github.com/Chrismarsh/CHM/issues/104
message( FATAL_ERROR "VTK > 6 is required, please see issue #104. You can build a compatible VTK using -DBUILD_VTK=ON." )
endif()
if(VTK_MAJOR_VERSION EQUAL 8 AND VTK_MINOR_VERSION LESS 1)
message( FATAL_ERROR "VTK >= 8.1 is required to avoid libproj4 name collision. You can build a compatible VTK using -DBUILD_VTK=ON." )
endif()
find_program(GVPR gvpr)
find_program(DOT dot)
if(NOT GVPR OR NOT DOT)
message(STATUS "Could not find gvpr and/or dot, module output to pdf will not function.")
else()
message(STATUS "gvpr and dot present, module output to pdf will function.")
endif()
find_package(trilinos REQUIRED)
#setup src dirs
include(third_party/CMakeLists.txt)
add_subdirectory(src)
if(BUILD_DOCS)
add_subdirectory(docs)
endif()