-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
160 lines (128 loc) · 5.48 KB
/
Copy pathCMakeLists.txt
File metadata and controls
160 lines (128 loc) · 5.48 KB
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
# CMake >= 3.28 strongly suggested for CMake build graph reliability.
# CMake >= 3.25 required for fine-grained scope with block() and enabling configure time tests
# CMake >= 3.24: find_package(... GLOBAL) and FetchContent_Declare(... FIND_PACKAGE_ARGS)
# CMake >= 3.21: *_IS_TOP_LEVEL variable used to manage subproject dependencies
cmake_minimum_required(VERSION 3.25...4.3)
# --- CMAKE_BUILD_TYPE default
# The simulations are 10x slower for default to Debug.
# Thus, for single config generators, set build type to Release
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(NOT is_multi_config AND NOT (CMAKE_BUILD_TYPE OR DEFINED ENV{CMAKE_BUILD_TYPE}))
set(CMAKE_BUILD_TYPE Release CACHE STRING "Release can be 10x faster simulation run time for gemini3d.run vs. Debug")
endif()
if(CMAKE_GENERATOR MATCHES "^Visual Studio")
message(FATAL_ERROR "${CMAKE_GENERATOR} is not supported. Use \"cmake -G Ninja\" option.")
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.26.0 AND CMAKE_VERSION VERSION_LESS 3.28.0)
message(WARNING "CMake 3.26 and 3.27 have known bugs causing build failures due to incorrectly graphing Fortran module dependencies, regardless of operating system or compiler.
Suggest CMake 3.28 or newer https://github.com/Kitware/CMake/releases
If on Linux HPC, do like 'module avail cmake' to see if a suitable CMake version is available.")
endif()
# --- main Gemini3D build
project(gemini3d
LANGUAGES C CXX Fortran
# Gemini3D is Fortran, but external libraries use C, and some find_package need C.
DESCRIPTION "3-D ionospheric model"
HOMEPAGE_URL https://github.com/gemini3d/gemini
VERSION 2.0.0
)
enable_testing() # keep this so BUILD_TESTING=off doesn't remove all tests
include(CTest)
include(FetchContent)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
# This project isn't using C++ modules; avoid bugs in module scanning CMake 3.28, 3.29 with GCC >= 14.
include(cmake/package/git_rev.cmake)
include(options.cmake)
set(CMAKE_CXX_STANDARD 17)
set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
file(READ cmake/libraries.json json)
# Fortran filesystem library "ffilesystem"
set(ffilesystem_fallback true)
set(ffilesystem_extra false)
set(HAVE_F03TYPE false)
# may need fallback for old or slightly broken compilers
string(JSON _stem GET "${json}" "ffilesystem" "stem")
string(JSON _archive GET "${json}" "ffilesystem" "archive")
set(ffilesystem_url ${_stem}${_archive})
FetchContent_Declare(ffilesystem URL ${ffilesystem_url})
FetchContent_MakeAvailable(ffilesystem)
# find python before excluding Anaconda
include(cmake/python.cmake)
# --- MPI
# NOTE: our find_package(MPI) needs to be before find_package(MUMPS), which also calls find_package(MPI)
# Conda e.g. scikit-learn can cause problems with finding MPI, so exclude Conda from search
# --- avoid Anaconda libraries
if(DEFINED ENV{CONDA_PREFIX})
list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
list(APPEND CMAKE_IGNORE_PATH $ENV{CONDA_PREFIX}/bin)
# need CMAKE_IGNORE_PATH for CMake < 3.23
# and to ensure system env var PATH doesn't interfere
# despite CMAKE_IGNORE_PREFIX_PATH
endif()
include(cmake/mpi.cmake)
# --- end MPI
# --- HDF5
string(JSON _stem GET "${json}" "h5fortran" "stem")
string(JSON _archive GET "${json}" "h5fortran" "archive")
set(h5fortran_url "${_stem}${_archive}")
FetchContent_Declare(h5fortran URL ${h5fortran_url})
FetchContent_MakeAvailable(h5fortran)
# this also implicitly finds HDF5.
# h5fortran is a high-level, object-oriented HDF5 interface.
# HDF5 bug #3663 for HDF5 1.14.2..2.1
# https://github.com/HDFGroup/hdf5/issues/3663
# https://github.com/HDFGroup/hdf5/pull/4701
if(WIN32 AND CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
message(DEBUG "HDF5: applying workaround for HDFGroup/HDF5 bug Issue 3663 with Intel oneAPI on Windows")
target_link_libraries(h5fortran INTERFACE shlwapi)
endif()
# --- end HDF5
include(cmake/compilers.cmake)
# --- linear algebra libraries
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(NOT DEFINED ENV{MKLROOT} AND NOT LAPACK_VENDOR MATCHES "^MKL")
# oneMKL MKLConfig.cmake must be invoked only once, and MUMPS invokes it.
find_package(LAPACK REQUIRED GLOBAL)
else()
find_package(SCALAPACK REQUIRED GLOBAL)
endif()
set(BUILD_SINGLE off)
set(BUILD_DOUBLE on)
set(BUILD_COMPLEX off)
set(BUILD_COMPLEX16 off)
string(JSON _stem GET "${json}" "mumps" "stem")
string(JSON _archive GET "${json}" "mumps" "archive")
set(mumps_url "${_stem}${_archive}")
FetchContent_Declare(mumps URL ${mumps_url})
FetchContent_MakeAvailable(mumps)
# --- climate models
if(gemini3d_glow)
string(JSON _stem GET "${json}" "glow" "stem")
string(JSON _archive GET "${json}" "glow" "archive")
set(glow_url "${_stem}${_archive}")
FetchContent_Declare(glow URL ${glow_url})
FetchContent_MakeAvailable(glow)
endif()
if(gemini3d_hwm14)
string(JSON _stem GET "${json}" "hwm14" "stem")
string(JSON _archive GET "${json}" "hwm14" "archive")
set(hwm14_url "${_stem}${_archive}")
FetchContent_Declare(hwm14 URL ${hwm14_url})
FetchContent_MakeAvailable(hwm14)
endif()
# --- MSISE00 / MSIS 2.x
set(msis_BUILD_UTILS on)
string(JSON _stem GET "${json}" "msis" "stem")
string(JSON _archive GET "${json}" "msis" "archive")
set(msis_url "${_stem}${_archive}")
FetchContent_Declare(msis URL ${msis_url})
FetchContent_MakeAvailable(msis)
# --- Gemini3D library
add_subdirectory(src)
# --- Gemini3D self test
include(${CMAKE_CURRENT_SOURCE_DIR}/test/mpi_launcher.cmake) # for MPI tests
add_subdirectory(test)
# summary print
include(cmake/summary.cmake)
# packaging
include(cmake/package/install.cmake)