forked from kramergroup/openImpala
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
199 lines (172 loc) · 7.7 KB
/
CMakeLists.txt
File metadata and controls
199 lines (172 loc) · 7.7 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
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
# ==============================================================================
# OpenImpala - CMake Build System
# ==============================================================================
#
# Usage (inside the Singularity/Apptainer container):
# mkdir build && cd build
# cmake ..
# make -j$(nproc)
# ctest
#
# Usage (native build with custom dependency paths):
# cmake .. -DCMAKE_PREFIX_PATH="/path/to/amrex;/path/to/hypre;/path/to/hdf5;/path/to/libtiff"
#
# ==============================================================================
cmake_minimum_required(VERSION 3.18)
# ---------------------------------------------------------------------------
# Derive project version from the latest Git tag (e.g. v4.0.1 → 4.0.1).
# Falls back to 0.0.0 when building outside a Git repository or when no
# tag is reachable (e.g. shallow clone without --tags).
# ---------------------------------------------------------------------------
set(OPENIMPALA_FALLBACK_VERSION "4.0.1")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --match "v[0-9]*" --abbrev=0
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE _git_tag
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
RESULT_VARIABLE _git_result
)
if(_git_result EQUAL 0 AND _git_tag MATCHES "^v([0-9]+\\.[0-9]+\\.[0-9]+)")
set(_detected_version "${CMAKE_MATCH_1}")
endif()
endif()
if(NOT _detected_version)
set(_detected_version "${OPENIMPALA_FALLBACK_VERSION}")
message(STATUS "Git tag not found — using fallback version ${_detected_version}")
else()
message(STATUS "Version from Git tag: ${_detected_version}")
endif()
project(OpenImpala
VERSION ${_detected_version}
LANGUAGES C CXX Fortran
DESCRIPTION "Image-based simulation of transport properties in porous media"
)
# ==============================================================================
# GPU Acceleration
# ==============================================================================
# Set GPU_BACKEND to CUDA, HIP, or NONE (default) to enable GPU-accelerated
# HYPRE solves. When enabled, AMReX and HYPRE must also be built with matching
# GPU support. The CUDA or HIP language is added to the project automatically.
set(GPU_BACKEND "NONE" CACHE STRING "GPU backend: NONE, CUDA, or HIP")
set_property(CACHE GPU_BACKEND PROPERTY STRINGS NONE CUDA HIP)
if(GPU_BACKEND STREQUAL "CUDA")
enable_language(CUDA)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
add_compile_definitions(OPENIMPALA_USE_GPU OPENIMPALA_USE_CUDA)
message(STATUS "GPU acceleration enabled: CUDA")
elseif(GPU_BACKEND STREQUAL "HIP")
enable_language(HIP)
add_compile_definitions(OPENIMPALA_USE_GPU OPENIMPALA_USE_HIP)
message(STATUS "GPU acceleration enabled: HIP")
else()
message(STATUS "GPU acceleration: disabled")
endif()
# ==============================================================================
# C++ Standard
# ==============================================================================
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ==============================================================================
# Build type defaults
# ==============================================================================
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo)
endif()
# ==============================================================================
# Custom CMake modules
# ==============================================================================
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# ==============================================================================
# Dependencies
# ==============================================================================
# --- nlohmann/json (header-only, for structured JSON output) ---
include(FetchContent)
FetchContent_Declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(nlohmann_json)
# --- MPI ---
find_package(MPI REQUIRED COMPONENTS CXX)
# --- OpenMP ---
find_package(OpenMP REQUIRED COMPONENTS CXX)
# --- AMReX ---
# AMReX ships AMReXConfig.cmake when installed via CMake.
# The container sets CMAKE_PREFIX_PATH to include the AMReX install prefix.
find_package(AMReX REQUIRED)
# --- HYPRE ---
# HYPRE is built with autoconf in the container, so we use our own FindHYPRE.cmake.
# If HYPRE was built with CMake and installed, find_package(HYPRE CONFIG) would work instead.
find_package(HYPRE REQUIRED)
# --- HDF5 ---
# We need the C++ bindings (hdf5_cpp).
find_package(HDF5 REQUIRED COMPONENTS C CXX)
# --- Transitive dependencies for static TIFF ---
find_package(ZLIB REQUIRED)
find_package(JPEG REQUIRED)
# libtiff 4.6.0 statically links the math library and exports CMath::CMath.
# We must manually define this target so CMake can resolve TIFF::tiff.
find_library(MATH_LIBRARY m)
if(MATH_LIBRARY AND NOT TARGET CMath::CMath)
add_library(CMath::CMath UNKNOWN IMPORTED)
set_target_properties(CMath::CMath PROPERTIES IMPORTED_LOCATION "${MATH_LIBRARY}")
endif()
# --- TIFF ---
find_package(TIFF REQUIRED)
# ==============================================================================
# Compiler flags
# ==============================================================================
# AMReX requires -DOMPI_SKIP_MPICXX to prevent inclusion of the deprecated MPI C++ bindings.
add_compile_definitions(OMPI_SKIP_MPICXX)
# ==============================================================================
# Code Coverage
# ==============================================================================
option(ENABLE_COVERAGE "Enable code coverage instrumentation (GCC/Clang --coverage)" OFF)
option(OPENIMPALA_PYTHON "Build Python bindings via pybind11" OFF)
if(ENABLE_COVERAGE)
message(STATUS "Code coverage enabled — appending --coverage to compile and link flags")
add_compile_options(--coverage)
add_link_options(--coverage)
endif()
# ==============================================================================
# TinyProfiler
# ==============================================================================
# AMReX emits a function-level BL_PROFILE timing table at AMReX::Finalize() when
# AMReX itself is built with -DAMReX_TINY_PROFILE=ON. That flag is exported via
# the AMReX::amrex target's INTERFACE_COMPILE_DEFINITIONS, so every target that
# links against AMReX::amrex picks up AMREX_TINY_PROFILE automatically — no
# OpenImpala-side option is needed. The wheel CI sets -DAMReX_TINY_PROFILE=ON
# when building AMReX from source.
# ==============================================================================
# Library targets
# ==============================================================================
add_subdirectory(src)
# ==============================================================================
# Testing
# ==============================================================================
include(CTest)
if(BUILD_TESTING)
# --- Catch2 (for lightweight unit tests) ---
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.2
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras)
add_subdirectory(tests)
endif()
# ==============================================================================
# Python Bindings
# ==============================================================================
if(OPENIMPALA_PYTHON)
add_subdirectory(python)
endif()