-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
1029 lines (893 loc) · 45.4 KB
/
CMakeLists.txt
File metadata and controls
1029 lines (893 loc) · 45.4 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SPDX-License-Identifier: MIT
# Intel ifx/icx CI support
# Developer's note:
# CMake has extensive documentation available online. Searching "cmake <variable>"
# or "cmake <function_name>" will return a cmake.org page with more information
# than you might expect to find or need. Note that any variable or symbol
# prefixed by CMAKE_ is reserved by CMake and has special meaning.
cmake_minimum_required(VERSION 3.20)
# We include C as a language because - for some reason
# FIND_LIBRARY_USE_LIB64_PATHS is otherwise ignored.
project(MFC LANGUAGES C CXX Fortran)
# Build options exposed to users and their default values.
option(MFC_MPI "Build with MPI" ON)
option(MFC_OpenACC "Build with OpenACC" OFF)
option(MFC_OpenMP "Build with OpenMP" OFF)
option(MFC_GCov "Build with GCov" OFF)
option(MFC_Unified "Build with unified CPU & GPU memory (GH-200 only)" OFF)
option(MFC_Fastmath "Build with -gpu=fastmath on NV GPUs" OFF)
option(MFC_PRE_PROCESS "Build pre_process" OFF)
option(MFC_SIMULATION "Build simulation" OFF)
option(MFC_POST_PROCESS "Build post_process" OFF)
option(MFC_SYSCHECK "Build syscheck" OFF)
option(MFC_DOCUMENTATION "Build documentation" OFF)
option(MFC_ALL "Build everything" OFF)
option(MFC_SINGLE_PRECISION "Build single precision" OFF)
option(MFC_MIXED_PRECISION "Build mixed precision" OFF)
if (MFC_ALL)
set(MFC_PRE_PROCESS ON FORCE)
set(MFC_SIMULATION ON FORCE)
set(MFC_POST_PROCESS ON FORCE)
set(MFC_DOCUMENTATION ON FORCE)
endif()
# Validate CMAKE_BUILD_TYPE to catch typos (CMake is case-sensitive).
set(_VALID_BUILD_TYPES "Debug" "Release" "RelDebug" "")
if (NOT CMAKE_BUILD_TYPE IN_LIST _VALID_BUILD_TYPES)
message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE '${CMAKE_BUILD_TYPE}'. Valid: Debug, RelDebug, Release")
endif()
# RelDebug: a lighter debug mode for CI. Compiler-specific blocks below add the
# actual flags; these defaults just tell CMake it is a recognised build type.
set(CMAKE_C_FLAGS_RELDEBUG "-g" CACHE STRING "")
set(CMAKE_CXX_FLAGS_RELDEBUG "-g" CACHE STRING "")
set(CMAKE_Fortran_FLAGS_RELDEBUG "-g" CACHE STRING "")
if (MFC_SINGLE_PRECISION)
add_compile_definitions(MFC_SINGLE_PRECISION)
else()
add_compile_definitions(MFC_DOUBLE_PRECISION)
endif()
if (MFC_MIXED_PRECISION)
add_compile_definitions(MFC_MIXED_PRECISION)
endif()
# CMake Library Imports
include(GNUInstallDirs)
include(ExternalProject)
include(CheckIPOSupported)
include(CMakeParseArguments)
include(CheckFortranCompilerFlag)
# Check Compiler Support: Some compilers, especially old ones, are known not to
# be able to compile MFC. We throw our own error early - at configure time - in
# such cases.
set(__err_msg "\
CMake detected the ${CMAKE_Fortran_COMPILER_ID} Fortran compiler \
v${CMAKE_Fortran_COMPILER_VERSION}. If you intended to use a different \
compiler (or a different version thereof), please:\n\
- Install the compiler or load its module. (e.g. module load gcc/10.1)\n\
- Set/Export the C, CXX, and FC environment variables. (e.g. 'export CC=gcc', \
'export CXX=g++', and 'export FC=gfortran'.\n\
- If using mfc.sh, delete the build/<code name> directory and try again. (e.g. 'rm -rf build/pre_process')")
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 5)
message(FATAL_ERROR "ERROR: GNU v5.0 or newer is required to build MFC.\n${__err_msg}")
endif()
if (MFC_OpenACC)
message(FATAL_ERROR "ERROR: MFC with GPU processing is not currently compatible with GNU compilers. Please use NVIDIA or Cray compilers.\n${__err_msg}")
endif()
elseif ((CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_Fortran_COMPILER_ID STREQUAL "PGI"))
if (CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 21.7)
message(FATAL_ERROR "ERROR: When using NVHPC, v21.7 or newer is required to build MFC.\n${__err_msg}")
endif()
if ((CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 24.5) AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelDebug") AND MFC_OpenACC)
message(FATAL_ERROR "ERROR: When using NVHPC, MFC with Debug and GPU options requires NVHPC v24.5 or newer.\n${__err_msg}")
endif()
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "AppleClang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
message(FATAL_ERROR "ERROR: MFC does not support the Apple Clang compilers. Please consult the documentation.\n${__err_msg}")
endif()
# Fypp is required to build MFC. We try to locate it. The path to the binary is
# returned in FYPP_EXE upon success. This is used later.
find_program(FYPP_EXE fypp REQUIRED)
# Miscellaneous Configuration:
# * Explicitly link to -ldl (or system equivalent)
# * Request that FIND_LIBRARY searches <prefix>/lib/ and <prefix>/lib64/
# * Let FindXXX use custom scripts from toolchain/cmake/.
link_libraries("${CMAKE_DL_LIBS}")
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/cmake/regular")
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/cmake/cce")
endif()
# Compiler Flags: Here, we specify our own compiler flags for both release and
# debug builds. These include optimization and debug flags, as well as some that
# are required for a successful build of MFC.
set(FYPP_GCOV_OPTS "")
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-ffree-line-length-none>
)
if (MFC_GCov)
# Warning present in gcc versions >= 12 that is treated as an error
# This flag doesn't exist in gcc versions < 12
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 12)
add_compile_options(
-Wno-error=coverage-invalid-line-number
)
endif()
add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-fprofile-arcs>
$<$<COMPILE_LANGUAGE:Fortran>:-ftest-coverage>
)
add_link_options(
$<$<COMPILE_LANGUAGE:Fortran>:-lgcov>
$<$<COMPILE_LANGUAGE:Fortran>:--coverage>
)
# Override Release -O3 with -O1 for gcov: coverage instrumentation is
# inaccurate at -O3, and aggressive codegen (e.g. AVX-512 FP16 on
# Granite Rapids) can emit instructions that older assemblers reject.
set(CMAKE_Fortran_FLAGS_RELEASE "-O1 -DNDEBUG" CACHE STRING "" FORCE)
# Use gfortran5 line markers so gcov can map coverage to .fpp sources.
set(FYPP_GCOV_OPTS "--line-marker-format=gfortran5")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(
-Wall
-Wextra
-fcheck=all,no-array-temps
-fbacktrace
-fimplicit-none
-fsignaling-nans
-finit-real=snan
-finit-integer=-99999999
-Wconversion
-Wintrinsic-shadow
-Wunderflow
-Wrealloc-lhs
-Wsurprising
)
elseif (CMAKE_BUILD_TYPE STREQUAL "RelDebug")
add_compile_options(
-Og
-Wall
-Wextra
-fcheck=bounds,pointer
-fbacktrace
-fimplicit-none
-fsignaling-nans
-finit-real=snan
-finit-integer=-99999999
-Wconversion
-Wintrinsic-shadow
-Wunderflow
-Wrealloc-lhs
-Wsurprising
)
endif()
if (CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER 10)
add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-fallow-invalid-boz>
$<$<COMPILE_LANGUAGE:Fortran>:-fallow-argument-mismatch>
)
endif()
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
add_compile_options(
"SHELL:-M 296,878,1391,1069,990,5025,7208,7212,7242"
"SHELL:-h static" "SHELL:-h keepfiles"
"SHELL:-h acc_model=auto_async_none"
"SHELL: -h acc_model=no_fast_addr"
"SHELL: -h list=adm"
"SHELL: -munsafe-fp-atomics" # Not unsafe for operations we do
)
add_link_options("SHELL:-hkeepfiles")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(
"SHELL:-h acc_model=auto_async_none"
"SHELL: -h acc_model=no_fast_addr"
"SHELL: -K trap=fp" "SHELL: -g" "SHELL: -O0"
)
add_link_options("SHELL: -K trap=fp" "SHELL: -g" "SHELL: -O0")
elseif (CMAKE_BUILD_TYPE STREQUAL "RelDebug")
add_compile_options(
"SHELL:-h acc_model=auto_async_none"
"SHELL: -h acc_model=no_fast_addr"
"SHELL: -K trap=fp" "SHELL: -g" "SHELL: -O1"
)
add_link_options("SHELL: -K trap=fp" "SHELL: -g" "SHELL: -O1")
endif()
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Flang")
add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-Mfreeform>
$<$<COMPILE_LANGUAGE:Fortran>:-Mpreprocess>
$<$<COMPILE_LANGUAGE:Fortran>:-fdefault-real-8>
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelDebug")
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-O1> $<$<COMPILE_LANGUAGE:Fortran>:-g>)
endif()
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-free>)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(-g -Og -traceback -debug -check all)
elseif (CMAKE_BUILD_TYPE STREQUAL "RelDebug")
add_compile_options(-g -Og -traceback -check bounds)
endif()
elseif ((CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC") OR (CMAKE_Fortran_COMPILER_ID STREQUAL "PGI"))
add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-Mfreeform>
$<$<COMPILE_LANGUAGE:Fortran>:-cpp>
$<$<COMPILE_LANGUAGE:Fortran>:-Minfo=inline>
$<$<COMPILE_LANGUAGE:Fortran>:-Minfo=accel>
)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-O0>
$<$<COMPILE_LANGUAGE:Fortran>:-C>
$<$<COMPILE_LANGUAGE:Fortran>:-g>
$<$<COMPILE_LANGUAGE:Fortran>:-traceback>
$<$<COMPILE_LANGUAGE:Fortran>:-Minform=inform>
$<$<COMPILE_LANGUAGE:Fortran>:-Mbounds>
)
elseif (CMAKE_BUILD_TYPE STREQUAL "RelDebug")
add_compile_options(
$<$<COMPILE_LANGUAGE:Fortran>:-O1>
$<$<COMPILE_LANGUAGE:Fortran>:-g>
$<$<COMPILE_LANGUAGE:Fortran>:-traceback>
$<$<COMPILE_LANGUAGE:Fortran>:-Mbounds>
)
endif()
if (DEFINED ENV{MFC_CUDA_CC})
string(REGEX MATCHALL "[0-9]+" MFC_CUDA_CC $ENV{MFC_CUDA_CC})
message(STATUS "Found $MFC_CUDA_CC specified. GPU code will be generated for compute capability(ies) ${MFC_CUDA_CC}.")
endif()
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
# Processor tuning: Check if we can target the host's native CPU's ISA.
# Skip for gcov builds — -march=native on newer CPUs (e.g. Granite Rapids)
# can emit instructions the system assembler doesn't support.
if (NOT MFC_GCov)
CHECK_FORTRAN_COMPILER_FLAG("-march=native" SUPPORTS_MARCH_NATIVE)
if (SUPPORTS_MARCH_NATIVE)
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-march=native>)
# Disable AVX-512 FP16: gfortran >=12 emits vmovw instructions on
# Granite Rapids CPUs, but binutils <2.38 cannot assemble them.
# FP16 is unused in MFC's double-precision computations.
CHECK_FORTRAN_COMPILER_FLAG("-mno-avx512fp16" SUPPORTS_MNO_AVX512FP16)
if (SUPPORTS_MNO_AVX512FP16)
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-mno-avx512fp16>)
endif()
else()
CHECK_FORTRAN_COMPILER_FLAG("-mcpu=native" SUPPORTS_MCPU_NATIVE)
if (SUPPORTS_MCPU_NATIVE)
add_compile_options($<$<COMPILE_LANGUAGE:Fortran>:-mcpu=native>)
endif()
endif()
endif()
# Enable LTO/IPO if supported (skip for gcov — LTO interferes with coverage
# instrumentation and can trigger assembler errors on newer architectures).
if (MFC_GCov)
message(STATUS "LTO/IPO disabled for gcov build")
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
if (MFC_Unified)
message(STATUS "LTO/IPO is not available with NVHPC using Unified Memory")
else()
message(STATUS "Performing IPO using -Mextract followed by -Minline")
set(NVHPC_USE_TWO_PASS_IPO TRUE)
endif()
else()
CHECK_IPO_SUPPORTED(RESULT SUPPORTS_IPO OUTPUT IPO_ERROR)
if (SUPPORTS_IPO)
message(STATUS "Enabled IPO / LTO")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO / LTO is NOT available")
endif()
endif()
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelDebug")
add_compile_definitions(MFC_DEBUG)
endif()
# HANDLE_SOURCES: Given a target (herein <target>):
#
# * Locate all source files for <target> of the type
#
# src/[<target>,common]/[.,include]/*.[f90,fpp].
#
# * For each .fpp file found with filepath <dirpath>/<filename>.fpp, using a
# custom command, instruct CMake how to generate a file with path
#
# src/<target>/fypp/<filename>.f90
#
# by running Fypp on <dirpath>/<filename>.fpp. It is important to understand
# that this does not actually run the pre-processor. Rather, it instructs
# CMake what to do when it finds a src/<target>/fypp/<filename>.f90 path
# in the source list for a target. Thus, an association is made from an .f90
# file to its corresponding .fpp file (if applicable) even though the
# generation is of the form .fpp -> .f90.
#
# This design has one limitation: If an .fpp file depends on another, for
# example if it '#:include's it and uses a macro defined in it, then the
# dependency will not be tracked. A modification to the .fpp file it depends
# on will not trigger a re-run of Fypp on the .fpp file that depends on it.
# As a compromise, both in speed and complexity, all .f90 files generated
# from .fpp files are re-generated not only when their corresponding .fpp
# file is modified, but also when any file with filepath of the form
#
# src/[<target>,common]/include/*.fpp
#
# is modified. This is a reasonable compromise as modifications to .fpp files
# in the include directories will be rare - by design. Other approaches would
# have required a more complex CMakeLists.txt file (perhaps parsing the .fpp
# files to determine their dependencies) or the endurment of longer
# compilation times (by way of re-running Fypp on all .fpp files every time
# one of them is modified).
#
# .fpp files in src/common are treated as if they were in src/<target> (not
# pre-processed to src/common/fypp/) so as not to clash with other targets'
# .fpp files (this has caused problems in the past).
#
# * Export, in the variable <target>_SRCs, a list of all source files (.f90)
# that would compile to produce <target>. If <target> includes .fpp files,
# then the list will include the paths to the corresponding .f90 files that
# Fypp would generate from the .fpp files.
#
# This design allows us to be flexible in our use of Fypp as we don't have to
# worry about running the pre-processor on .fpp files when we create executables
# and generate documentation. Instead, we can simply include the list of .f90
# files that will eventually be used to compile <target>.
macro(HANDLE_SOURCES target useCommon)
set(${target}_DIR "${CMAKE_SOURCE_DIR}/src/${target}")
set(common_DIR "${CMAKE_SOURCE_DIR}/src/common")
string(TOUPPER ${target} ${target}_UPPER)
# Gather:
# * src/[<target>,(common)]/*.f90
# * (if any) <build>/modules/<target>/*.f90
file(GLOB ${target}_F90s CONFIGURE_DEPENDS "${${target}_DIR}/*.f90"
"${CMAKE_BINARY_DIR}/modules/${target}/*.f90")
set(${target}_SRCs ${${target}_F90s})
if (${useCommon})
file(GLOB common_F90s CONFIGURE_DEPENDS "${common_DIR}/*.f90")
list(APPEND ${target}_SRCs ${common_F90s})
endif()
# Gather:
# * src/[<target>,(common)]/*.fpp]
# * (if any) <build>/modules/<target>/*.fpp
file(GLOB ${target}_FPPs CONFIGURE_DEPENDS "${${target}_DIR}/*.fpp"
"${CMAKE_BINARY_DIR}/modules/${target}/*.fpp")
if (${useCommon})
file(GLOB common_FPPs CONFIGURE_DEPENDS "${common_DIR}/*.fpp")
# If we're building post_process, exclude m_compute_levelset.fpp
if("${target}" STREQUAL "post_process")
list(FILTER common_FPPs EXCLUDE REGEX ".*/m_compute_levelset\.fpp$")
list(FILTER common_FPPs EXCLUDE REGEX ".*/m_ib_patches\.fpp$")
endif()
list(APPEND ${target}_FPPs ${common_FPPs})
endif()
# Gather:
# * src/[<target>,common]/include/*.fpp
# * (if any) <build>/include/<target>/*.fpp
file(GLOB ${target}_incs CONFIGURE_DEPENDS "${${target}_DIR}/include/*.fpp"
"${CMAKE_BINARY_DIR}/include/${target}/*.fpp")
if (${useCommon})
file(GLOB common_incs CONFIGURE_DEPENDS "${common_DIR}/include/*.fpp")
list(APPEND ${target}_incs ${common_incs})
endif()
# /path/to/*.fpp (used by <target>) -> <build>/fypp/<target>/*.f90
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/fypp/${target}")
foreach(fpp ${${target}_FPPs})
cmake_path(GET fpp FILENAME fpp_filename)
set(f90 "${CMAKE_BINARY_DIR}/fypp/${target}/${fpp_filename}.f90")
add_custom_command(
OUTPUT ${f90}
COMMAND ${FYPP_EXE} -m re
-I "${CMAKE_BINARY_DIR}/include/${target}"
-I "${${target}_DIR}/include"
-I "${common_DIR}/include"
-I "${common_DIR}"
-D MFC_${CMAKE_Fortran_COMPILER_ID}
-D MFC_${${target}_UPPER}
-D MFC_COMPILER="${CMAKE_Fortran_COMPILER_ID}"
-D MFC_CASE_OPTIMIZATION=False
-D chemistry=False
--line-numbering
--no-folding
--line-length=999
--line-numbering-mode=nocontlines
${FYPP_GCOV_OPTS}
"${fpp}" "${f90}"
DEPENDS "${fpp};${${target}_incs}"
COMMENT "Preprocessing (Fypp) ${fpp_filename}"
VERBATIM
)
list(APPEND ${target}_SRCs ${f90})
endforeach()
endmacro()
HANDLE_SOURCES(pre_process ON)
HANDLE_SOURCES(simulation ON)
HANDLE_SOURCES(post_process ON)
HANDLE_SOURCES(syscheck OFF)
# MFC_SETUP_TARGET: Given a target (herein <target>), this macro creates a new
# executable <target> with the appropriate sources, compiler definitions, and
# linked libraries (assuming HANDLE_SOURCES was called on <target>).
#
# Inputs:
# * TARGET Target name (<target>)
# * SOURCES List of source files (.f90)
# * OpenACC (optional) Can be compiled with OpenACC.
# * MPI (optional) Can be compiled with MPI.
# * SILO (optional) Should be linked with SILO.
# * HDF5 (optional) Should be linked with HDF5.
# * FFTW (optional) Should be linked with an FFTW-like library (fftw/cufftw),
# depending on whether OpenACC is enabled and which compiler is
# being used.
# * LAPACK (optional) Should be linked with LAPACK
function(MFC_SETUP_TARGET)
cmake_parse_arguments(ARGS "OpenACC;MPI;SILO;HDF5;FFTW;LAPACK;OpenMP" "TARGET" "SOURCES" ${ARGN})
add_executable(${ARGS_TARGET} ${ARGS_SOURCES})
set(IPO_TARGETS ${ARGS_TARGET})
# Here we need to split into "library" and "executable" to perform IPO on the NVIDIA compiler.
# A little hacky, but it *is* an edge-case for *one* compiler.
if (NVHPC_USE_TWO_PASS_IPO AND NOT(MFC_OpenMP AND ARGS_OpenMP))
# nvfortran -Mextract does not produce .o files, only inline library
# data. An OBJECT library with -Mextract causes CMake to rebuild
# everything on every build because the expected .o outputs never
# exist. We use a wrapper script as RULE_LAUNCH_COMPILE that runs
# the compiler and then touches the expected .o output file.
set(_ipo_wrapper "${CMAKE_BINARY_DIR}/${ARGS_TARGET}_extract_wrapper.sh")
file(WRITE "${_ipo_wrapper}" [=[#!/bin/sh
# Find the -o argument (the object file CMake expects)
out=
prev=
for arg do
if [ "$prev" = "-o" ]; then out="$arg"; break; fi
prev="$arg"
done
# Run the compiler; propagate its exit status on failure
"$@"
status=$?
[ "$status" -eq 0 ] || exit "$status"
# Touch the .o so CMake's dependency tracking sees it
[ -n "$out" ] && touch "$out"
exit 0
]=])
file(CHMOD "${_ipo_wrapper}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
add_library(${ARGS_TARGET}_lib OBJECT ${ARGS_SOURCES})
set_target_properties(${ARGS_TARGET}_lib PROPERTIES
RULE_LAUNCH_COMPILE "${_ipo_wrapper}")
target_compile_options(${ARGS_TARGET}_lib PRIVATE
$<$<COMPILE_LANGUAGE:Fortran>:-Mextract=lib:${ARGS_TARGET}_lib>
$<$<COMPILE_LANGUAGE:Fortran>:-Minline>
)
add_dependencies(${ARGS_TARGET} ${ARGS_TARGET}_lib)
target_compile_options(${ARGS_TARGET} PRIVATE -Minline=lib:${ARGS_TARGET}_lib,except:f_is_default,except:s_compute_dt,except:my_inquire,except:s_mpi_abort,except:s_mpi_barrier,except:s_prohibit_abort,except:s_int_to_str,except:s_associate_cbc_coefficients_pointers)
# Exclude m_start_up and m_cbc from cross-file inlining: these are
# initialization/boundary code that trigger NVHPC 25.x fort2 ICE when
# too many functions are cross-inlined into them. GPU hot-path files
# (m_rhs, m_riemann_solvers, m_viscous, m_weno, etc.) keep full IPO.
foreach(_no_inline_file m_start_up m_cbc)
set_source_files_properties(
"${CMAKE_BINARY_DIR}/fypp/${ARGS_TARGET}/${_no_inline_file}.fpp.f90"
TARGET_DIRECTORY ${ARGS_TARGET}
PROPERTIES COMPILE_OPTIONS "-Mnoinline"
)
endforeach()
list(PREPEND IPO_TARGETS ${ARGS_TARGET}_lib)
endif()
foreach (a_target ${IPO_TARGETS})
set_target_properties(${a_target} PROPERTIES Fortran_PREPROCESS ON)
message(STATUS ${CMAKE_Fortran_COMPILER_ID})
target_include_directories(${a_target} PRIVATE
"${CMAKE_SOURCE_DIR}/src/common"
"${CMAKE_SOURCE_DIR}/src/common/include"
"${CMAKE_SOURCE_DIR}/src/${ARGS_TARGET}")
if (EXISTS "${CMAKE_SOURCE_DIR}/src/${ARGS_TARGET}/include")
target_include_directories(${a_target} PRIVATE
"${CMAKE_SOURCE_DIR}/src/${ARGS_TARGET}/include")
endif()
string(TOUPPER "${ARGS_TARGET}" ${ARGS_TARGET}_UPPER)
target_compile_definitions(
${a_target} PRIVATE MFC_${CMAKE_Fortran_COMPILER_ID}
MFC_${${ARGS_TARGET}_UPPER}
)
if (MFC_MPI AND ARGS_MPI)
find_package(MPI COMPONENTS Fortran REQUIRED)
target_compile_definitions(${a_target} PRIVATE MFC_MPI)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
target_compile_options(${a_target} PRIVATE "$ENV{CRAY_MPICH_INC}")
target_link_libraries(${a_target} PRIVATE $ENV{CRAY_MPICH_LIB})
else()
target_link_libraries(${a_target} PRIVATE MPI::MPI_Fortran)
endif()
endif()
if (ARGS_SILO)
find_package(SILO REQUIRED)
target_link_libraries(${a_target} PRIVATE SILO::SILO stdc++)
endif()
if (ARGS_HDF5)
find_package(HDF5 REQUIRED)
target_link_libraries(${a_target} PRIVATE HDF5::HDF5)
endif()
if (ARGS_FFTW)
if ((MFC_OpenACC AND ARGS_OpenACC) OR (MFC_OpenMP AND ARGS_OpenMP))
if (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
find_package(CUDAToolkit REQUIRED)
target_link_libraries(${a_target} PRIVATE CUDA::cudart CUDA::cufft)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
target_link_libraries(${a_target} PRIVATE $ENV{CRAY_HIPFORT_LIB})
else()
find_package(hipfort COMPONENTS hipfft CONFIG REQUIRED)
target_link_libraries(${a_target} PRIVATE hipfort::hipfft)
endif()
else()
find_package(FFTW REQUIRED)
target_link_libraries(${a_target} PRIVATE FFTW::FFTW)
endif()
endif()
if (ARGS_LAPACK)
find_package(LAPACK REQUIRED)
target_link_libraries(${a_target} PRIVATE LAPACK::LAPACK)
endif()
if ((MFC_OpenACC AND ARGS_OpenACC) OR (MFC_OpenMP AND ARGS_OpenMP))
if ((MFC_OpenACC AND ARGS_OpenACC))
find_package(OpenACC)
# This should be equivalent to if (NOT OpenACC_FC_FOUND)
if (NOT TARGET OpenACC::OpenACC_Fortran)
message(FATAL_ERROR "OpenACC + Fortran is unsupported.")
endif()
target_link_libraries(${a_target} PRIVATE OpenACC::OpenACC_Fortran)
target_compile_definitions(${a_target} PRIVATE MFC_OpenACC MFC_GPU)
elseif((MFC_OpenMP AND ARGS_OpenMP))
find_package(OpenMP)
# This should be equivalent to if (NOT OpenACC_FC_FOUND)
if (NOT TARGET OpenMP::OpenMP_Fortran)
message(FATAL_ERROR "OpenMP + Fortran is unsupported.")
endif()
set(ENV{OMP_TARGET_OFFLOAD} [MANDATORY])
# target_link_libraries(${a_target} PRIVATE OpenMP::OpenMP_Fortran)
target_compile_definitions(${a_target} PRIVATE MFC_OpenMP MFC_GPU)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
target_compile_options(${a_target} PRIVATE "-mp=gpu" "-Minfo=mp")
target_link_options(${a_target} PRIVATE "-mp=gpu")
set_target_properties(${a_target} PROPERTIES Fortran_FLAGS "-mp=gpu -gpu=ccall")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
target_compile_options(${a_target} PRIVATE -fopenmp -fopenmp-targets=spir64)
target_link_options(${a_target} PRIVATE -fopenmp -fopenmp-targets=spir64)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
target_compile_options(${a_target} PRIVATE -fopenmp)
target_link_options(${a_target} PRIVATE -fopenmp)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
target_compile_options(${a_target} PRIVATE -fopenmp --offload-arch=gfx90a -fopenmp-target-fast -fopenmp-assume-threads-oversubscription -fopenmp-assume-teams-oversubscription)
target_link_options(${a_target} PRIVATE -fopenmp --offload-arch=gfx90a)
endif()
endif()
if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
# FIXME: This should work with other cards than gfx90a ones.
target_compile_options(${a_target} PRIVATE
"-foffload=amdgcn-amdhsa='-march=gfx90a'"
"-foffload-options=-lgfortran\ -lm"
"-fno-exceptions")
if (MFC_Fastmath)
message(WARNING "--fastmath has no effect with the GNU compiler")
endif()
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
foreach (cc ${MFC_CUDA_CC})
target_compile_options(${a_target}
PRIVATE -gpu=cc${cc}
)
endforeach()
target_compile_options(${a_target}
PRIVATE -gpu=keep,ptxinfo,lineinfo
)
if (MFC_Fastmath)
target_compile_options(${a_target}
PRIVATE -gpu=fastmath
)
endif()
# GH-200 Unified Memory Support
if (MFC_Unified)
target_compile_options(${ARGS_TARGET}
PRIVATE -gpu=mem:unified:managedalloc -cuda
)
# "This option must appear in both the compile and link lines" -- NVHPC Docs
target_link_options(${ARGS_TARGET}
PRIVATE -gpu=mem:unified:managedalloc -cuda
)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelDebug")
target_compile_options(${a_target}
PRIVATE -gpu=debug
)
endif()
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
# Frontier Unified Memory Support
if (MFC_Unified)
target_compile_options(${ARGS_TARGET}
PRIVATE -DFRONTIER_UNIFIED)
endif()
if (MFC_Fastmath)
message(WARNING "--fastmath has no effect with the CCE")
endif()
find_package(hipfort COMPONENTS hip CONFIG REQUIRED)
target_link_libraries(${a_target} PRIVATE hipfort::hip hipfort::hipfort-amdgcn)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
if (MFC_Unified)
target_compile_options(${ARGS_TARGET}
PRIVATE -DFRONTIER_UNIFIED)
endif()
find_package(hipfort COMPONENTS hip CONFIG REQUIRED)
target_link_libraries(${a_target} PRIVATE hipfort::hip hipfort::hipfort-amdgcn flang_rt.hostdevice)
endif()
elseif (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
target_compile_options(${a_target} PRIVATE "SHELL:-h noacc" "SHELL:-x acc")
if (MFC_Fastmath)
message(WARNING "--fastmath has no effect with the CCE")
endif()
endif()
if (CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC" OR CMAKE_Fortran_COMPILER_ID STREQUAL "PGI")
find_package(CUDAToolkit REQUIRED)
if (TARGET CUDA::nvToolsExt) # CUDA <= 12.8
target_link_libraries(${a_target} PRIVATE CUDA::nvToolsExt)
else() # CUDA >= 12.9
target_link_libraries(${a_target} PRIVATE nvhpcwrapnvtx)
target_link_options(${a_target} PRIVATE "-cudalib=nvtx3")
endif()
endif()
endforeach()
install(TARGETS ${ARGS_TARGET} RUNTIME DESTINATION bin)
endfunction()
if (MFC_PRE_PROCESS)
MFC_SETUP_TARGET(TARGET pre_process
SOURCES "${pre_process_SRCs}"
MPI)
if(CMAKE_Fortran_COMPILER_ID STREQUAL "Cray")
target_compile_options(pre_process PRIVATE -hfp0)
endif()
endif()
if (MFC_SIMULATION)
MFC_SETUP_TARGET(TARGET simulation
SOURCES "${simulation_SRCs}"
MPI FFTW OpenACC OpenMP)
# CCE 19.0.0 IPA workaround: disable interprocedural analysis for files
# that trigger compiler crashes during IPA:
# m_bubbles_EL: castIsValid assertion (InstCombine/foldIntegerTypedPHI)
# m_phase_change: bring_routine_resident SIGSEGV
# Not applied to Cray+OpenMP because thermochem uses !DIR$ INLINEALWAYS,
# which requires IPA to inline device calls. On OpenACC the pyrometheus
# patch emits !$acc routine seq instead (no IPA needed). See PR #1286.
if (CMAKE_Fortran_COMPILER_ID STREQUAL "Cray" AND NOT MFC_OpenMP)
set_source_files_properties(
"${CMAKE_BINARY_DIR}/fypp/simulation/m_bubbles_EL.fpp.f90"
"${CMAKE_BINARY_DIR}/fypp/simulation/m_phase_change.fpp.f90"
PROPERTIES COMPILE_OPTIONS "-Oipa0"
)
endif()
endif()
if (MFC_POST_PROCESS)
MFC_SETUP_TARGET(TARGET post_process
SOURCES "${post_process_SRCs}"
MPI SILO HDF5 FFTW LAPACK)
# -O0 is in response to https://github.com/MFlowCode/MFC-develop/issues/95
target_compile_options(post_process PRIVATE -O0)
endif()
if (MFC_SYSCHECK)
MFC_SETUP_TARGET(TARGET syscheck
SOURCES "${syscheck_SRCs}"
MPI OpenACC OpenMP)
endif()
if (MFC_DOCUMENTATION)
# Files in examples/ are used to generate docs/documentation/examples.md
file(GLOB_RECURSE examples_DOCs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/examples/*")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/examples.md"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/docs/examples.sh;${examples_DOCs}"
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/examples.sh"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating examples.md"
VERBATIM
)
# Generate case_constraints.md and physics_constraints.md together.
# Both are produced by gen_constraints.sh, so a single command avoids races.
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/case_constraints.md"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/physics_constraints.md"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/gen_case_constraints_docs.py"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/gen_physics_docs.py"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/case_validator.py"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/params/definitions.py"
"${examples_DOCs}"
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_constraints.sh"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating case_constraints.md and physics_constraints.md"
VERBATIM
)
# Generate cli-reference.md from cli/commands.py
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/cli-reference.md"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/cli/commands.py"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/cli/docs_gen.py"
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_cli_reference.sh"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating cli-reference.md"
VERBATIM
)
# Generate parameters.md from parameter registry
# docs_gen.py now AST-parses case_validator.py, so it must be a dependency
file(GLOB_RECURSE params_SRCs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/params/*.py")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/parameters.md"
DEPENDS "${params_SRCs}"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/case_validator.py"
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_parameters.sh"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating parameters.md"
VERBATIM
)
file(GLOB common_DOCs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/docs/*")
# GEN_DOCS: Given a target name (herein <target>), this macro sets up a
# target, <target>_docs, that generates documentation for <target> using
# Doxygen. It is then added as a dependency of the documentation target.
# Doxygen outputs HTML to the binary (build) directory. It is installed into
# its own directory: <prefix>/docs/mfc/<target>. We use configure_file to
# generate the Doxyfile for each target using paths that only apply to that
# target (or when relative paths are impractical), specified by CMake.
macro(GEN_DOCS target name)
set(DOXYGEN_PROJECT_NAME "\"${name}\"")
set(DOXYGEN_INPUT "\"${CMAKE_CURRENT_SOURCE_DIR}/docs/${target}\"")
foreach (f90 ${${target}_SRCs})
set(DOXYGEN_INPUT "${DOXYGEN_INPUT} \"${f90}\"")
endforeach()
set(DOXYGEN_HTML_HEADER "\"${CMAKE_CURRENT_SOURCE_DIR}/docs/header.html\"")
set(DOXYGEN_HTML_FOOTER "\"${CMAKE_CURRENT_SOURCE_DIR}/docs/footer.html\"")
set(DOXYGEN_HTML_OUTPUT "\"${CMAKE_CURRENT_BINARY_DIR}/${target}\"")
set(DOXYGEN_MATHJAX_CODEFILE "\"${CMAKE_CURRENT_SOURCE_DIR}/docs/config.js\"")
set(DOXYGEN_PROJECT_LOGO "\"${CMAKE_CURRENT_SOURCE_DIR}/docs/res/icon.ico\"")
set(DOXYGEN_CITE_BIB_FILES "\"${CMAKE_CURRENT_SOURCE_DIR}/docs/references.bib\"")
set(DOXYGEN_IMAGE_PATH "\"${CMAKE_CURRENT_SOURCE_DIR}/docs/res\"\
\"${CMAKE_CURRENT_SOURCE_DIR}/docs/${target}\"")
set(DOXYGEN_WARN_LOGFILE "\"${CMAKE_CURRENT_BINARY_DIR}/${target}-doxygen-warnings.log\"")
file(MAKE_DIRECTORY "${DOXYGEN_OUTPUT_DIRECTORY}")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in"
"${CMAKE_CURRENT_BINARY_DIR}/${target}-Doxyfile" @ONLY)
set(opt_example_dependency "")
set(opt_constraints_dependency "")
set(opt_physics_dependency "")
set(opt_cli_reference_dependency "")
set(opt_parameters_dependency "")
if (${target} STREQUAL documentation)
set(opt_example_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/examples.md")
set(opt_constraints_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/case_constraints.md")
set(opt_physics_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/physics_constraints.md")
set(opt_cli_reference_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/cli-reference.md")
set(opt_parameters_dependency "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/parameters.md")
endif()
file(GLOB_RECURSE ${target}_DOCs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/docs/${target}/*")
list(APPEND ${target}_DOCs "${common_DOCs}")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${target}/html/index.html"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${target}-Doxyfile"
"${opt_example_dependency}"
"${opt_constraints_dependency}"
"${opt_physics_dependency}"
"${opt_cli_reference_dependency}"
"${opt_parameters_dependency}"
"${${target}_SRCs}" "${${target}_DOCs}"
COMMAND "${DOXYGEN_EXECUTABLE}" "${target}-Doxyfile"
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/docs/postprocess_citations.py"
"${CMAKE_CURRENT_BINARY_DIR}/${target}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "${target}: Generating documentation"
)
add_custom_target(
"${target}_doxygen" ALL
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${target}/html/index.html"
)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${target}"
DESTINATION "docs/mfc")
add_dependencies("${target}_doxygen" doxygen-awesome-css)
add_dependencies(documentation "${target}_doxygen")
endmacro()
add_custom_target(documentation)
find_package(Doxygen REQUIRED dot REQUIRED)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
# > Fetch CSS Theme
ExternalProject_Add(doxygen-awesome-css
PREFIX doxygen-awesome-css
GIT_REPOSITORY "https://github.com/jothepro/doxygen-awesome-css"
GIT_TAG "v2.4.1"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
set(theme_dirpath
"${CMAKE_CURRENT_BINARY_DIR}/doxygen-awesome-css/src/doxygen-awesome-css")
set(DOXYGEN_HTML_EXTRA_STYLESHEET
"\"${theme_dirpath}/doxygen-awesome.css\"\
\"${theme_dirpath}/doxygen-awesome-sidebar-only.css\"\
\"${CMAKE_CURRENT_SOURCE_DIR}/docs/custom.css\"")
# > Generate Documentation & Landing Page
GEN_DOCS(pre_process "MFC")
GEN_DOCS(simulation "MFC")
GEN_DOCS(post_process "MFC")
GEN_DOCS(api "MFC")
GEN_DOCS(documentation "MFC")
# Generate API landing pages for pre_process, simulation, post_process.
# Scans src/{target}/*.fpp to produce module lists in docs/{target}/readme.md.
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen-api-landing.stamp"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_api_landing.py"
${pre_process_FPPs} ${pre_process_F90s}
${simulation_FPPs} ${simulation_F90s}
${post_process_FPPs} ${post_process_F90s}
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_api_landing.py"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/gen-api-landing.stamp"
COMMENT "Generating API landing pages"
VERBATIM
)
add_custom_target(gen_api_landing DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gen-api-landing.stamp")
add_dependencies(pre_process_doxygen gen_api_landing)
add_dependencies(simulation_doxygen gen_api_landing)
add_dependencies(post_process_doxygen gen_api_landing)
add_dependencies(api_doxygen gen_api_landing)
# Fix @file/@brief headers to match actual module/program declarations.
# Handles mixed-case Fortran names and catches stale module renames.
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/fix-file-briefs.stamp"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/docs/fix_file_briefs.py"
${pre_process_FPPs} ${pre_process_F90s}
${simulation_FPPs} ${simulation_F90s}
${post_process_FPPs} ${post_process_F90s}
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/docs/fix_file_briefs.py"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/fix-file-briefs.stamp"
COMMENT "Fixing @file brief headers"
VERBATIM
)
add_custom_target(fix_file_briefs DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/fix-file-briefs.stamp")
add_dependencies(pre_process_doxygen fix_file_briefs)
add_dependencies(simulation_doxygen fix_file_briefs)
add_dependencies(post_process_doxygen fix_file_briefs)
# Generate architecture.md from template + module_categories.json + source briefs.
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/gen-architecture.stamp"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_architecture.py"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/module_categories.json"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/architecture.md.in"
${pre_process_FPPs} ${pre_process_F90s}
${simulation_FPPs} ${simulation_F90s}
${post_process_FPPs} ${post_process_F90s}
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_architecture.py"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${CMAKE_COMMAND}" -E touch "${CMAKE_CURRENT_BINARY_DIR}/gen-architecture.stamp"
COMMENT "Generating architecture page"
VERBATIM
)
add_custom_target(gen_architecture DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/gen-architecture.stamp")
add_dependencies(documentation_doxygen gen_architecture)
# Inject per-page last-updated dates into documentation markdown files.
# Runs after auto-generated .md files exist, before Doxygen processes them.
# Uses a stamp file so it only runs once per build.
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/inject-dates.stamp"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/examples.md"
"${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/case_constraints.md"