-
Notifications
You must be signed in to change notification settings - Fork 34
/
CMakeLists.txt
289 lines (263 loc) · 10.3 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
# ----------------------------------------------------------------------------
# Root CMake file for SEIMS.
# Spatially Explicit Integrated Modeling System
#
# Please from the off-tree build directory, invoke:
# $ cmake <path/to/SEIMS>
#
# Optional cmake options:
# -DINSTALL_PREFIX=<path/to/install>
# -DLLVM_ROOT_DIR Specific the root directory of brew installed LLVM, e.g., /usr/local/opt/llvm
# -DSEIMS_DOC=1 means build SEIMS documentation based on doxygen
# -DBUILD_TAUDEMEXT=0 means do not build TauDEM_ext
#
# Routine testing platforms and compilers include:
# 1. Windows 10 with Visual Studio 2010/2013/2015, MSMPI-v8.1, GDAL-1.11.4
# 2. Windows 10 with msys2/mingw64 (GCC-9.1.0), MSMPI-v8.1, GDAL-3.0
# 3. CentOS 6.2 (cluster) with GCC-4.8.4, mongo-c-driver-1.5.5, GDAL-1.9.0
# 4. Red Hat Server 6.2 (cluster) with ICC-12.1.0, mongo-c-driver-1.6.1, GDAL-1.11.5 (Without UnitTest)
# 5. macOS 10.14.5 with Clang-10.0 with Xcode, OpenMPI-4.0.1, GDAL-2.4.2 (brew installed)
#
# Created and maintained by Liangjun Zhu ([email protected])
# Latest updated: Jun 12, 2024
#
# Copyright (C) 2013-2024 Lreis, IGSNRR, CAS, and NJNU
# ----------------------------------------------------------------------------
### Disable in-source builds to prevent source tree corruption.
IF(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}")
MESSAGE(FATAL_ERROR "
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.")
ENDIF()
CMAKE_MINIMUM_REQUIRED(VERSION 3.1 FATAL_ERROR)
cmake_policy(SET CMP0015 NEW)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0077 NEW)
cmake_policy(SET CMP0079 NEW)
SET(CMAKE_SH "CMAKE_SH-NOTFOUND")
### Set coding language
PROJECT(SEIMS_ALL CXX C)
### SEIMS Version.
SET(PRJNAME "SEIMS")
### Build Postfix
SET(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Default Debug postfix")
SET(CMAKE_RELEASE_POSTFIX "" CACHE STRING "Default Release postfix")
SET(CMAKE_RELWITHDEBINFO_POSTFIX "rd" CACHE STRING "Default RelWithDebInfo postfix")
SET(CMAKE_MINSIZEREL_POSTFIX "s" CACHE STRING "Default MinSizeRel postfix")
IF (CMAKE_BUILD_TYPE MATCHES "Release")
SET(CMAKE_BUILD_POSTFIX "${CMAKE_RELEASE_POSTFIX}")
ELSEIF (CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
SET(CMAKE_BUILD_POSTFIX "${CMAKE_MINSIZEREL_POSTFIX}")
ELSEIF(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
SET(CMAKE_BUILD_POSTFIX "${CMAKE_RELWITHDEBINFO_POSTFIX}")
ELSEIF(CMAKE_BUILD_TYPE MATCHES "Debug")
SET(CMAKE_BUILD_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
ELSE()
SET(CMAKE_BUILD_POSTFIX "")
ENDIF()
### Set cmake find path
set(CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake
${CMAKE_MODULE_PATH}
)
# Global flag to cause add_library to create shared libraries if on, otherwise static library.
option(BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
# libraries built with hunter link against the dynamic CRT on windows
option(BUILD_WITH_STATIC_CRT "Build against dynamic CRT on windows." ON)
# Build documatation by doxygen
option(SEIMS_DOC "Build SEIMS documentation." OFF)
# Build TauDEM_ext or not
option(BUILD_TAUDEMEXT "Do not build TauDEM_ext" ON)
### Detect compiler and target platform architecture.
INCLUDE(Utils)
SET(ENABLE_CXX11 1)
INCLUDE(DetectCXXCompiler)
### Use statically or dynamically linked CRT? Default: dynamic
IF(MSVC)
INCLUDE(CRTLinkage)
ENDIF(MSVC)
### In case of Makefiles if the user does not setup CMAKE_BUILD_TYPE, assume it's Release.
IF(CMAKE_GENERATOR MATCHES "Makefiles|Ninja" AND "${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE Release)
ENDIF()
### Set default or specified installation directory.
IF (INSTALL_PREFIX)
SET(INSTALL_DIR ${INSTALL_PREFIX} CACHE PATH "Set specified install path" FORCE)
ELSE()
IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(INSTALL_DIR ${PROJECT_BINARY_DIR} CACHE PATH "Set specified install path" FORCE)
ELSE ()
SET(INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CACHE PATH "Set default install path" FORCE)
ENDIF ()
ENDIF ()
SET(INSTALL_PREFIX ${INSTALL_DIR} CACHE PATH "Set INSTALL_PREFIX cache" FORCE)
SET(CMAKE_INSTALL_PREFIX ${INSTALL_DIR} CACHE PATH "Set CMAKE_INSTALL_PREFIX cache" FORCE)
SET(DOC_INSTALL_DIR "${INSTALL_DIR}/doc" CACHE PATH "Set path of the documentation to cache" FORCE)
### Allow project folders in MSVC and Xcode.
IF(MSVC OR XCODE)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
ENDIF()
### OS platform.
if (WIN32)
add_definitions(-DWINDOWS)
if (MSVC)
add_definitions(-DMSVC)
endif ()
elseif (APPLE)
add_definitions(-DMACOSX)
else ()
add_definitions(-DLINUX)
endif ()
### Assume built-in pthreads on macOS X
IF(APPLE)
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(CMAKE_USE_WIN32_THREADS_INIT 0)
set(CMAKE_USE_PTHREADS_INIT 1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
ENDIF()
### Break in case of popular CMake configuration mistakes.
IF(NOT CMAKE_SIZEOF_VOID_P GREATER 0)
MESSAGE(FATAL_ERROR "CMake fails to determine the bitness of the target platform.
Please check your CMake and compiler installation.")
ENDIF()
### Add standard paths or specified paths for Find libraries and headers.
INCLUDE(AddFindPaths)
### Find MPI which is required
FIND_PACKAGE(MPI REQUIRED)
IF(MPI_FOUND)
SET(WITH_MPI 1)
SET(PRJNAME ${PRJNAME}_MPI)
INCLUDE(SetFlagMPI)
MESSAGE(STATUS "Compiling with MPI...")
ELSE()
MESSAGE(FATAL_ERROR "FATAL: Could not find MPI, which is required for TauDEM and SEIMS!")
ENDIF()
### Find OMP which is optional
# Refers to https://mac.r-project.org/openmp/ for further method to handle openmp in AppleClang
IF(NOT CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
IF(CV_CLANG)
message(STATUS "Find OpenMP from LLVM")
# To use OpenMP in Clang built by CMake, the recommended way is to
# install llvm alone by 'brew install llvm', which has builtin 'libomp'
IF (NOT LLVM_ROOT_DIR)
SET(LLVM_ROOT_DIR "/opt/homebrew/opt/llvm")
ENDIF ()
FIND_PACKAGE(LLVM)
IF(LLVM_VERSION_MAJOR)
geo_include_directories(${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_BASE_STRING}/include)
SET(OpenMP_CXX_FLAGS "-fopenmp")
SET(OpenMP_C_FLAGS "-fopenmp")
FIND_LIBRARY(OpenMP_LIBRARY
NAMES "omp"
HINTS ${LLVM_LIBRARY_DIRS})
SET(OPENMP_FOUND 1)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LDFLAGS}")
ENDIF ()
ELSE ()
FIND_PACKAGE(OpenMP)
ENDIF ()
ENDIF ()
IF(OPENMP_FOUND)
SET(WITH_OPENMP 1)
ADD_DEFINITIONS(-DSUPPORT_OMP)
SET(PRJNAME ${PRJNAME}_OMP)
INCLUDE(SetFlagOpenMP)
MESSAGE(STATUS "Compiling with OpenMP...")
ENDIF()
SET(PRJNAME ${PRJNAME}_ALL)
PROJECT(${PRJNAME})
### Find GDAL which is required.
FIND_PACKAGE(GDAL REQUIRED)
IF (GDAL_FOUND)
SET(WITH_GDAL 1)
ADD_DEFINITIONS(-DUSE_GDAL)
INCLUDE(SetFlagGDAL)
ELSE ()
MESSAGE(FATAL_ERROR "FATAL: Could not find GDAL!")
ENDIF ()
### Bson and MongoC.
IF(BSON_ROOT)
SET(ENV{BSON_ROOT} ${BSON_ROOT})
SET(ENV{BSON_DIR} ${BSON_ROOT})
SET(ENV{BSON_ROOT_DIR} ${BSON_ROOT})
ENDIF()
IF(MONGOC_ROOT)
SET(ENV{MONGOC_ROOT} ${MONGOC_ROOT})
SET(ENV{MONGOC_DIR} ${MONGOC_ROOT})
SET(ENV{MONGOC_ROOT_DIR} ${MONGOC_ROOT})
ENDIF()
INCLUDE(FindBson)
INCLUDE(FindMongoC)
### Set bits of float pointing number, i.e., float32 or float64(double)
IF(FLOAT64)
add_definitions(-DUSE_FLOAT64)
ENDIF()
### Add subdirectories.
ADD_SUBDIRECTORY(./seims)
IF(SEIMS_DOC)
ADD_SUBDIRECTORY(./doc)
ENDIF()
### Build platform.
STATUS("")
STATUS(" Platform:")
IF(NOT CMAKE_VERSION VERSION_LESS 2.8.11 AND NOT BUILD_INFO_SKIP_TIMESTAMP)
STRING(TIMESTAMP TIMESTAMP "" UTC)
IF(TIMESTAMP)
STATUS(" Timestamp:" ${TIMESTAMP})
ENDIF()
ENDIF()
STATUS(" Host:" ${CMAKE_HOST_SYSTEM_NAME} ${CMAKE_HOST_SYSTEM_VERSION} ${CMAKE_HOST_SYSTEM_PROCESSOR})
IF(CMAKE_CROSSCOMPILING)
STATUS(" Target:" ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION} ${CMAKE_SYSTEM_PROCESSOR})
ENDIF()
STATUS(" CMake:" ${CMAKE_VERSION})
STATUS(" CMake generator:" ${CMAKE_GENERATOR})
STATUS(" CMake build tool:" ${CMAKE_BUILD_TOOL})
IF(MSVC)
STATUS(" MSVC:" ${MSVC_VERSION})
ENDIF()
IF(CMAKE_GENERATOR MATCHES Xcode)
STATUS(" Xcode:" ${XCODE_VERSION})
ENDIF()
IF(NOT CMAKE_GENERATOR MATCHES "Xcode|Visual Studio")
STATUS(" Configuration:" ${CMAKE_BUILD_TYPE})
ENDIF()
### C/C++ options.
IF(CMAKE_CXX_COMPILER_VERSION)
SET(GEO_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} (ver ${CMAKE_CXX_COMPILER_VERSION})")
ELSE()
SET(GEO_COMPILER_STR "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
ENDIF()
STRING(STRIP "${GEO_COMPILER_STR}" GEO_COMPILER_STR)
STATUS("")
STATUS(" C/C++:")
IF(ENABLE_CXX11 OR HAVE_CXX11)
STATUS(" C++11:" HAVE_CXX11 THEN YES ELSE NO)
ENDIF()
STATUS(" C++ Compiler:" ${GEO_COMPILER_STR})
STATUS(" C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
STATUS(" C++ flags (Debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG})
STATUS(" C Compiler:" ${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1})
STATUS(" C flags (Release):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE})
STATUS(" C flags (Debug):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG})
IF(WIN32)
STATUS(" Linker flags (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE})
STATUS(" Linker flags (Debug):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
ELSE()
STATUS(" Linker flags (Release):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_RELEASE})
STATUS(" Linker flags (Debug):" ${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_DEBUG})
ENDIF()
### Dependencies.
STATUS("")
STATUS(" Use MPI:" MPI_FOUND THEN "YES (LIB: ${MPI_LIBRARIES}, INC: ${MPI_INCLUDE_PATH})" ELSE "NO")
STATUS(" Use OpenMP:" OPENMP_FOUND THEN "YES" ELSE "NO")
STATUS(" Use GDAL:" GDAL_FOUND THEN "YES (LIB: ${GDAL_LIBRARIES}, INC: ${GDAL_INCLUDE_DIR})" ELSE "NO")
STATUS(" Use BSON:" BSON_FOUND THEN "YES (LIB: ${BSON_LIBRARIES}, INC: ${BSON_INCLUDE_DIR})" ELSE "NO")
STATUS(" Use MongoC:" MONGOC_FOUND THEN "YES (LIB: ${MONGOC_LIBRARIES}, INC: ${MONGOC_INCLUDE_DIR})" ELSE "NO")
STATUS(" Run Doxygen:" SEIMS_DOC THEN "YES" ELSE "NO")
### Auxiliary.
STATUS("")
STATUS(" Install path:" ${INSTALL_DIR})
STATUS("")