-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
179 lines (148 loc) · 6.18 KB
/
Copy pathCMakeLists.txt
File metadata and controls
179 lines (148 loc) · 6.18 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
cmake_minimum_required(VERSION 3.20)
project(ELEMENTS VERSION 1.0.0 LANGUAGES CXX C)
# --- Global Compiler Fixes (Scoped to this project) ---
# These settings apply to ELEMENTS and all its dependencies (Scotch, etc.)
# but DO NOT leak up to the parent project (the solver).
# Force C11 Standard (Required for PT-Scotch to build with GCC 15)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
# --- Check Scope for Options ---
# We still use this check for things like "Should we build examples?"
# because a solver user likely doesn't want to compile your examples.
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(ELEMENTS_IS_TOP_LEVEL ON)
else()
set(ELEMENTS_IS_TOP_LEVEL OFF)
endif()
# --- Check if building documentation ---
# The default is OFF, but this option can be set to ON from the terminal/cmake command line.
option(ELEMENTS_BUILD_DOCS "Build documentation" OFF)
# Setting -DELEMENTS_BUILD_DOCS=ON from the terminal or cmake-gui will overwrite the default.
# Set module path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
# --- Optional Doxygen and Sphinx dependencies ---
if (ELEMENTS_BUILD_DOCS)
find_package(Doxygen REQUIRED)
find_package(Sphinx REQUIRED)
endif()
# --- Build documentation ---
if (ELEMENTS_BUILD_DOCS)
add_subdirectory(docs)
endif()
# --- Set build type if not already set ---
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
# set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
# --- Find MPI (Required) ---
find_package(MPI REQUIRED)
if(NOT MSVC)
if(MPI_CXX_VERSION LESS 3)
message(WARNING "ELEMENTS requires MPI version 3+. Found ${MPI_CXX_VERSION}.")
endif()
endif()
# --- Options ---
option(ELEMENTS_ENABLE_SERIAL "Enable Serial support in Kokkos" ON)
option(ELEMENTS_ENABLE_OPENMP "Enable OpenMP support in Kokkos" OFF)
option(ELEMENTS_ENABLE_PTHREADS "Enable PThreads support in Kokkos" OFF)
option(ELEMENTS_ENABLE_CUDA "Enable CUDA support in Kokkos" OFF)
option(ELEMENTS_ENABLE_HIP "Enable HIP support in Kokkos" OFF)
option(ELEMENTS_BUILD_EXAMPLES "Build examples" ${ELEMENTS_IS_TOP_LEVEL})
option(ELEMENTS_BUILD_TESTS "Build unit tests" OFF)
include(FetchContent)
# --- Dependency: Kokkos ---
if(NOT TARGET Kokkos::kokkos)
set(Kokkos_ENABLE_SERIAL ${ELEMENTS_ENABLE_SERIAL} CACHE BOOL "" FORCE)
set(Kokkos_ENABLE_OPENMP ${ELEMENTS_ENABLE_OPENMP} CACHE BOOL "" FORCE)
set(Kokkos_ENABLE_PTHREADS ${ELEMENTS_ENABLE_PTHREADS} CACHE BOOL "" FORCE)
set(Kokkos_ENABLE_CUDA ${ELEMENTS_ENABLE_CUDA} CACHE BOOL "" FORCE)
set(Kokkos_ENABLE_HIP ${ELEMENTS_ENABLE_HIP} CACHE BOOL "" FORCE)
FetchContent_Declare(
Kokkos
GIT_REPOSITORY https://github.com/kokkos/kokkos
GIT_TAG 4.3.00
)
FetchContent_MakeAvailable(Kokkos)
endif()
# --- Dependency: MATAR ---
if(NOT TARGET matar::matar)
FetchContent_Declare(
MATAR
GIT_REPOSITORY https://github.com/lanl/MATAR
GIT_TAG main
)
FetchContent_MakeAvailable(MATAR)
if(TARGET matar)
if(NOT TARGET matar::matar)
add_library(matar::matar ALIAS matar)
endif()
FetchContent_GetProperties(MATAR SOURCE_DIR MATAR_SOURCE_DIR)
get_target_property(_matar_includes matar INTERFACE_INCLUDE_DIRECTORIES)
if(NOT "${MATAR_SOURCE_DIR}/src/include" IN_LIST _matar_includes)
target_include_directories(matar INTERFACE
$<BUILD_INTERFACE:${MATAR_SOURCE_DIR}/src/include>
$<BUILD_INTERFACE:${MATAR_SOURCE_DIR}/solvers>
)
endif()
target_compile_definitions(matar INTERFACE HAVE_KOKKOS)
if(MPI_FOUND)
target_compile_definitions(matar INTERFACE HAVE_MPI)
endif()
endif()
endif()
# --- Dependency: Scotch / PT-Scotch ---
if(NOT TARGET ptscotch)
set(SCOTCH_MPI ON CACHE BOOL "Enable MPI for Scotch" FORCE)
set(SCOTCH_BUILD_TESTS OFF CACHE BOOL "Disable Scotch Tests" FORCE)
set(BUILD_FORTRAN OFF CACHE BOOL "Disable Scotch Fortran interface" FORCE)
if(WIN32)
# Scotch does not ship pthreads on Windows; ensure all pthread toggles are off
set(SCOTCH_PTHREAD OFF CACHE BOOL "Disable Scotch pthread on Windows" FORCE)
set(SCOTCH_PTHREAD_MPI OFF CACHE BOOL "Disable Scotch pthread MPI on Windows" FORCE)
set(COMMON_PTHREAD OFF CACHE BOOL "Disable common pthread on Windows" FORCE)
endif()
FetchContent_Declare(
Scotch
GIT_REPOSITORY https://gitlab.inria.fr/scotch/scotch.git
GIT_TAG v7.0.4
GIT_SHALLOW TRUE
PATCH_COMMAND ${CMAKE_COMMAND} -DFileToPatch=CMakeLists.txt -P "${PROJECT_SOURCE_DIR}/cmake/PatchScotch.cmake"
)
FetchContent_MakeAvailable(Scotch)
# FIX: GCC 15 Warning Suppressions (Target-Specific)
# Even though C11 is set globally above, we still need to silence the
# specific GCC 15 warnings for Scotch that are not fixed by C11 alone.
if(NOT MSVC)
set(_scotch_targets
scotch ptscotch scotcherr scotcherrexit
amk_ccc amk_fft2 amk_grf amk_hy amk_m2 amk_p2
gbase gmap gord gout gpart gscat gtst
mcv mmk_m2 mmk_m3 mord mtst
dggath dgmap dgord dgpart dgscat dgtst
)
foreach(_target ${_scotch_targets})
if(TARGET ${_target})
# Silence annoying warnings for legacy C code
target_compile_options(${_target} PRIVATE
$<$<COMPILE_LANGUAGE:C>:-Wno-error=incompatible-pointer-types>
$<$<COMPILE_LANGUAGE:C>:-Wno-error=int-conversion>
$<$<COMPILE_LANGUAGE:C>:-Wno-error=implicit-int>
$<$<COMPILE_LANGUAGE:C>:-Wno-incompatible-pointer-types>
$<$<COMPILE_LANGUAGE:C>:-Wno-int-conversion>
$<$<COMPILE_LANGUAGE:C>:-Wno-implicit-int>
)
endif()
endforeach()
endif()
endif()
# --- Add ELEMENTS Source ---
add_subdirectory(src)
# --- 9. Optional Parts ---
if(ELEMENTS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(ELEMENTS_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()