Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
120 lines (99 loc) · 3.74 KB
/
Copy pathCMakeLists.txt
File metadata and controls
120 lines (99 loc) · 3.74 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
cmake_minimum_required(VERSION 3.28..3.30)
project(fVTKHDF VERSION 0.8.0 LANGUAGES Fortran C)
# CMake does not currently provide the PIC flag for LLVMFlang on Linux.
# LLVMFlang 23 requires it for shared-library builds; older tested versions
# happen to link without it. Remove this once CMake handles LLVMFlang PIC.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND
CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang" AND
CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL 23 AND
CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 24 AND
NOT CMAKE_Fortran_COMPILE_OPTIONS_PIC)
set(CMAKE_Fortran_COMPILE_OPTIONS_PIC "-fPIC")
endif()
# --- Options ---
option(ENABLE_MPI "Enable MPI support" ON)
option(USE_MPI_F08 "Expose mpi_f08 communicator overloads when MPI is enabled" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(ENABLE_STD_MOD_PROC_NAME "Build with -assume std_mod_proc_name when using Intel" OFF)
option(BUILD_HTML "Build HTML documentation" OFF)
option(BUILD_EXAMPLES "Build example programs" OFF)
# Default to Release build if not specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build" FORCE)
endif()
# Standardize install paths (lib64, bin, include)
include(GNUInstallDirs)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(Version)
# --- Dependencies ---
# 1. MPI
if(ENABLE_MPI)
find_package(MPI REQUIRED COMPONENTS C Fortran)
set(HDF5_PREFER_PARALLEL True)
add_compile_definitions(USE_MPI)
if(USE_MPI_F08)
add_compile_definitions(USE_MPI_F08)
endif()
else()
set(HDF5_PREFER_PARALLEL False)
set(USE_MPI_F08 OFF)
endif()
# 2. HDF5
find_package(HDF5 REQUIRED COMPONENTS C)
# Older FindHDF5 modules do not map the HDF5 2.x package flag to HDF5_IS_PARALLEL.
if(ENABLE_MPI AND NOT (HDF5_IS_PARALLEL OR HDF5_PROVIDES_PARALLEL))
message(FATAL_ERROR "Parallel HDF5 is required when MPI is enabled, but only serial HDF5 was found.")
endif()
# Older parallel HDF5 can write data from ranks with H5S_NULL memory spaces.
if(ENABLE_MPI AND HDF5_VERSION VERSION_LESS "1.13.0")
add_compile_definitions(HDF5_NULL_MEMSPACE_BUG)
endif()
# 3. Python & Fypp
find_package(Python3 REQUIRED COMPONENTS Interpreter)
find_program(FYPP_EXECUTABLE fypp)
if(NOT FYPP_EXECUTABLE)
message(FATAL_ERROR "fypp not found.\nInstall with: ${Python3_EXECUTABLE} -m pip install fypp")
endif()
# --- Compiler Settings ---
# Disable assertions in Release
add_compile_definitions("$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
# Fortran Flags
add_compile_options(
"$<$<COMPILE_LANG_AND_ID:Fortran,GNU>:-ffree-line-length-none>"
"$<$<COMPILE_LANG_AND_ID:Fortran,NAG>:-w=longlines>"
)
# Intel Standard Semantics
add_compile_options(
"$<$<COMPILE_LANG_AND_ID:Fortran,Intel,IntelLLVM>:-standard-semantics>"
"$<$<AND:$<NOT:$<BOOL:${ENABLE_STD_MOD_PROC_NAME}>>,$<COMPILE_LANG_AND_ID:Fortran,Intel,IntelLLVM>>:SHELL:-assume nostd_mod_proc_name>"
)
# Compiler Bug Workarounds
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
add_compile_definitions(INTEL_BUG20240327)
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
add_compile_definitions(GNU_PR123899)
if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS "16.1.0")
add_compile_definitions(GNU_BUG20261103)
endif()
endif()
# --- Subdirectories ---
include(Fypp)
add_subdirectory(src)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
if(BUILD_HTML)
find_program(SPHINX_EXECUTABLE NAMES sphinx-build
DOC "Path to sphinx-build executable"
)
if(NOT SPHINX_EXECUTABLE)
message(FATAL_ERROR "sphinx-build not found. Please install Sphinx.")
endif()
add_subdirectory(doc/sphinx)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(example)
endif()