-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
307 lines (271 loc) · 12.2 KB
/
CMakeLists.txt
File metadata and controls
307 lines (271 loc) · 12.2 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
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
# generate grackle_float.h AND auto_general.c
# ===========================================
# perform a check to try to help out with the scenario where the classic build
# system in an older Grackle revisions placed auto-generated files in locations
# where a cmake build might mistakenly use the wrong version of the file
# -> this is probably only an issue with grackle_float.h, but we handle all
# auto-generated files for consistency
# -> in modern Grackle revisions, classic-build put these files in better spots
# -> I don't think this is a perfect check. It might not help if you
# 1. configure a cmake-build-directory
# 2. checkout on old grackle revision and perform a classic-build
# 3. return the latest revision and use the cmake-build-directory from 1.
# But, this is a fairly pathological scenario
set(bad_fname_l "grackle_float.h;../include/grackle_float.h;auto_general.c")
foreach(fname IN LISTS bad_fname_l)
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${fname}")
message(FATAL_ERROR
"Please delete the ${CMAKE_CURRENT_SOURCE_DIR}/${fname} file and perform "
"a fresh cmake-build. That file may confuse the cmake-build. Unless you "
"manually added that file yourself, that file is left over from a "
"classic-build in an older Grackle revision")
endif()
endforeach()
# first, declare recipe for generating grackle_float.h:
if (GRACKLE_USE_DOUBLE)
set(GRACKLE_FLOAT_MACRO "GRACKLE_FLOAT_8")
else()
set(GRACKLE_FLOAT_MACRO "GRACKLE_FLOAT_4")
endif()
configure_file(../include/grackle_float.h.in
${GRACKLE_GENERATED_PUBLIC_HEADERS}/grackle_float.h @ONLY)
# next, declare recipe for generating auto_general.c:
# fetch necessary version information via query-version.py script
# -> GIT_BRANCH and GIT_REVISION hold sensible vals when git isn't installed
# -> VERSION_NUM may hold more information than Grackle_VERSION (e.g. like the
# "dev" suffix)
set(_query_version
"${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/query_version.py")
function(query_version option OUTVAR)
execute_process(
COMMAND ${_query_version} ${option}
RESULT_VARIABLE RSLT OUTPUT_VARIABLE OUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(RSLT)
message(FATAL_ERROR "Call to `${_query_version} ${option}` failed")
endif()
set(${OUTVAR} ${OUT} PARENT_SCOPE)
endfunction()
query_version(show-version VERSION_NUM)
query_version(git-branch GIT_BRANCH)
query_version(git-revision GIT_REVISION)
# in the original build-system, the following string also included things like:
# include-args, linking flags, macro definitions, all other compiler flags...
string(REPLACE "\n" "\\n" SHOW_FLAGS_STR "
CC = ${CMAKE_C_COMPILER}
FC = ${CMAKE_Fortran_COMPILER}
LD = ${CMAKE_LINKER}
")
string(REPLACE "\n" "\\n" SHOW_CONFIG_STR "
Built with CMake
GRACKLE_USE_DOUBLE : ${GRACKLE_USE_DOUBLE}
GRACKLE_USE_OPENMP : ${GRACKLE_USE_OPENMP}
BUILD_TYPE : ${CMAKE_BUILD_TYPE}
")
configure_file(auto_general.c.in auto_general.c @ONLY)
# Declare the main target
# =======================
add_library(Grackle_Grackle
# C source files
dynamic_api.c
grackle_units.c
index_helper.c
initialize_cloudy_data.c initialize_cloudy_data.h
initialize_UVbackground_data.c initialize_UVbackground_data.h
rate_functions.c
status_reporting.c status_reporting.h
utils.c
# auto-generated C source files
${CMAKE_CURRENT_BINARY_DIR}/auto_general.c
# here is the companion header file (not generated)
auto_general.h
# C++ Source (and Private Header Files)
calc_tdust_3d.cpp calc_tdust_3d.h
calc_temp_cloudy_g.cpp calc_temp_cloudy_g.h
calculate_cooling_time.cpp
calculate_dust_temperature.cpp
calculate_gamma.cpp
calculate_pressure.cpp
calculate_temperature.cpp
ceiling_species.hpp
collisional_rate_props.cpp collisional_rate_props.hpp
cool1d_multi_g.cpp cool1d_multi_g.hpp
cool_multi_time_g.cpp cool_multi_time_g.h
dust_props.hpp
dust/grain_species_info.cpp dust/grain_species_info.hpp
dust/lookup_dust_rates1d.hpp
full_rxn_rate_buf.hpp
init_misc_species_cool_rates.cpp init_misc_species_cool_rates.hpp
initialize_chemistry_data.cpp
initialize_dust_yields.cpp initialize_dust_yields.hpp
initialize_rates.cpp initialize_rates.hpp
internal_types.cpp internal_types.hpp
lookup_cool_rates1d.hpp
make_consistent.cpp make_consistent.hpp
opaque_storage.hpp
rate_timestep_g.cpp rate_timestep_g.hpp
rate_utils.cpp
solve_chemistry.cpp
scale_fields.cpp scale_fields.hpp
set_default_chemistry_parameters.cpp
solve_rate_cool_g-cpp.cpp solve_rate_cool_g-cpp.h
step_rate_gauss_seidel.hpp
step_rate_newton_raphson.hpp
time_deriv_0d.hpp
update_UVbackground_rates.cpp update_UVbackground_rates.hpp
utils-cpp.cpp utils-cpp.hpp
utils-field.hpp
fortran_func_wrappers.hpp
support/config.hpp
visitor/common.hpp
visitor/copy.hpp
visitor/memory.hpp
visitor/printer.hpp
# Fortran Source Files
calc_all_tdust_gasgr_1d_g.F
calc_tdust_1d_g.F
calc_temp1d_cloudy_g.F
cool1d_cloudy_g.F
cool1d_cloudy_old_tables_g.F
interpolators_g.F
solve_rate_cool_g.F
calc_grain_size_increment_1d.F
gaussj_g.F
# explicitly list the autogenerated header(s)
# -> If we don't explicitly list these (storing it in a list isn't adequate)
# a subtle bug can arise in the scenario when you are freshly building
# Grackle some after a previous build was installed in installed in a
# standard system location (like /usr/local)
# -> In that scenario, CMake doesn't realize it needs to generate the
# header(s) because the compiler can finds versions of the headers from
# the prior build in the standard system location.
${GRACKLE_GENERATED_PUBLIC_HEADERS}/grackle_float.h
# although not strictly necessary, listing out other header files is a "best
# practice" (and is needed to make them show up in certain IDEs)
# C/C++ public headers
../include/grackle.h
../include/grackle_chemistry_data.h
../include/grackle_misc.h
../include/grackle_rate_functions.h
../include/grackle_types.h
# private headers
cie_thin_cooling_rate_tables.h
fortran_func_decls.h
field_data_evolved_species.def # <-- acts as a C header
field_data_misc_fdatamembers.def # <-- acts as a C header
grackle_chemistry_data_fields.def # <-- acts as a C header
grackle_macros.h
index_helper.h
interp_table_utils.h
phys_constants.h
collisional_rxn_rate_members.def # <-- acts as a C header
utils.h
dust_const.def
# Fortran public headers
../include/grackle.def
../include/grackle_fortran_interface.def
../include/grackle_fortran_types.def
# Fortran private headers
phys_const.def
)
target_compile_features(Grackle_Grackle PRIVATE cxx_std_17)
# A downstream application built with CMake generally has 2 inclusion
# approaches (ways that they can make use of this build):
# 1. they can build Grackle as part of the downstream build.
# - in this case, the downstream build calls add_subdirectory on the top
# level directory of Grackle and they can access the targets defined in
# this file.
# 2. they can use the installed library
# - in this case, the downstream build will get access to the targets
# defined in a special CMake export-file created during installation
#
# We take some care to make these approaches as interchangable as possible for
# downstream build. To that end, we take 2 primary steps:
#
# - we name the main target Grackle_Grackle, rather than just [Gg]rackle to
# minimize the chance for name-collisions of targets created by the build of
# the downstream application (this is relevant for approach #1)
#
# - Following existing conventions, the downstream project should access the
# target called Grackle::Grackle. We make use of a namespace to follow
# convention... (they are more useful if we built multiple targets as part of
# the build)
add_library(Grackle::Grackle ALIAS Grackle_Grackle) # for inclusion appraoch #1
# set standard cmake-specific properties
set_target_properties(Grackle_Grackle PROPERTIES
# specify the grackle library is properly named (when it's NOT a shared lib)
OUTPUT_NAME "grackle"
# choose a special name when grackle is compiled as a shared library (to
# reduce the chance that an application linked against one version will try
# to load a newer, incompatible version of the library)
# -> we follow the convention of the classic build-system (and libtool) of
# encode encode the version in the core-part of the library name
# -> for convenience, when Grackle is built and installed as a shared lib,
# custom installation logic is made to link to libgrackle.so (or
# libgrackle.dylib on macOS)
LIBRARY_OUTPUT_NAME "grackle-${VERSION_NUM}"
# specify target name that is made visible in inclusion approach #2. The
# namespace-prefix of this target, "Grackle::", is declared in the
# install(EXPORT ...) command included with the installation rules
EXPORT_NAME Grackle
)
# write custom propeties used to convey information to downstream consumers
# of the Grackle library. To help us expose consistent information regardless
# of how Grackle is consume, we use this custom function that wraps
# set_target_properties (it's important to identify what is a BOOL vs STRING)
include(TargetInfoProps)
set_target_typed_info_properties(Grackle_Grackle STRING_PROPERTIES
GRACKLE_VERSION_STR "${VERSION_NUM}"
)
set_target_typed_info_properties(Grackle_Grackle BOOL_PROPERTIES
GRACKLE_USE_DOUBLE "${GRACKLE_USE_DOUBLE}"
GRACKLE_USE_OPENMP "${GRACKLE_USE_OPENMP}"
)
target_include_directories(Grackle_Grackle
# specify where to search for generated and ordinary headers when building
# grackle AND when linking against grackle under inclusion approach #1
# -> while it may seem unnecessary to specify the ordinary headers' directory
# while building grackle, it's necessary to compile auto_general.c
PUBLIC $<BUILD_INTERFACE:${GRACKLE_GENERATED_PUBLIC_HEADERS}> # generated hdrs
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> # public hdrs
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> # private hdrs
# specify where to search for the other headers when linking against grackle
# (for inclusion approach #2)
INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(Grackle_Grackle
PRIVATE toolchain::m
GRACKLE_HDF5_C
$<$<BOOL:${GRACKLE_USE_OPENMP}>:OpenMP::OpenMP_Fortran>
$<$<BOOL:${GRACKLE_USE_OPENMP}>:OpenMP::OpenMP_C>
)
# add the necessary compiler-specific Fortran flags to ensure proper handling
# of our specific Fortran-dialect and that name mangling is performed as
# expected (these flags only get applied to Fortran source-code files)
include(AddConditionalFortranFlags)
add_conditional_fortran_flags(Grackle_Grackle)
# add the machine-specific compiler optimization options (generally specified
# in host-files) for use in the RELEASE or RELWITHDEBINFO build-configurations
# -> as noted elsewhere, we may stop using these when Grackle isn't the
# top-level project
# -> we explicitly add these directly to the Grackle target rather than
# collecting them in an interface library. This lets us avoid exposing these
# private flags when we compile Grackle_Grackle as a static library (they
# would be exposed once we add support for the ``export`` command to allow
# cmake projects to import Grackle from its build directory).
# -> we can start collecting them in an interface library once CMake 3.26 is our
# minimum version, which provides the $<BUILD_LOCAL_INTERFACE:...> generator
# expression.
target_compile_options(Grackle_Grackle PRIVATE
"$<$<CONFIG:RELEASE>:${GRACKLE_OPTIMIZATION_FLIST}>"
"$<$<CONFIG:RELWITHDEBINFO>:${GRACKLE_OPTIMIZATION_FLIST}>")
# define macros so that the C files know how to properly handle name-mangling
# (if cmake were our only build-system, we could use FortranCInterface module)
if ("${CMAKE_SYSTEM_NAME}" MATCHES "^(Linux)|(Darwin)$")
target_compile_definitions(Grackle_Grackle PRIVATE "LINUX")
endif()
# define macro to suppress warnings about C files using our deprecated public
# headers (the files should include grackle.h instead). We're currently holding
# off on this to minimize conflicts with the newchem-cpp branch
target_compile_definitions(Grackle_Grackle PRIVATE GRIMPL_PUBLIC_INCLUDE=1)