forked from RHESSys/RHESSys
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
188 lines (171 loc) · 7.07 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
# ----------------------------------------------------------------------------
# Root CMake file for RHESSys.
# The Regional Hydro-Ecologic Simulation System
#
# Please from the off-tree build directory, invoke:
# $ cmake <path/to/RHESSys>
# Available arguments:
# -DEXTEND_CLIM=1
# -DOFDEBUG=1
#
# Routine testing platforms and compilers include:
# 1. Windows 10 with msys2/mingw64 (GCC-latest)
# 2. macOS 12.x with AppleClang-13.x (Xcode built-in and brew installed)
# and GCC-12.x (brew installed)
#
# Created and maintained by Liangjun Zhu (zlj@lreis.ac.cn)
# Latest updated: Aug. 28, 2022
#
# Copyright (C) 2018-2022 Lreis, IGSNRR, CAS
# ----------------------------------------------------------------------------
### 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(rhessys_all C CXX)
### 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}
)
### 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(CMAKE_INSTALL_PREFIX ${INSTALL_DIR})
### Detect compiler and target platform architecture.
INCLUDE(Utils)
### 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(-D_OPENMP)
INCLUDE(SetFlagOpenMP)
MESSAGE(STATUS "Compiling with OpenMP...")
ENDIF()
### Find NetCDF which is required.
FIND_PACKAGE(NetCDF REQUIRED)
### Find Bison and Flex which are required.
find_package(BISON REQUIRED)
find_package(FLEX REQUIRED)
### Add subdirectories.
ADD_SUBDIRECTORY(./rhessys)
### 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 OpenMP:" OPENMP_FOUND THEN "YES" ELSE "NO")
STATUS(" Use NetCDF:" NETCDF_FOUND THEN "YES (LIB: ${NETCDF_LIBRARIES}, INC: ${NETCDF_INCLUDES})" ELSE "NO")
STATUS(" Use Bison:" BISON_FOUND THEN "YES (EXEC: ${BISON_EXECUTABLE}, VERSION: ${BISON_VERSION})" ELSE "NO")
STATUS(" Use FLEX:" FLEX_FOUND THEN "YES (LIB: ${FLEX_LIBRARIES}, INC: ${FLEX_INCLUDE_DIRS})" ELSE "NO")
### Auxiliary.
STATUS("")
STATUS(" Install path:" ${INSTALL_DIR})
STATUS("")