-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
252 lines (209 loc) · 9.26 KB
/
CMakeLists.txt
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
cmake_minimum_required (VERSION 3.14)
project (stellarator_tools)
enable_testing ()
include (FetchContent)
find_package (Git)
#-------------------------------------------------------------------------------
# Setup build types.
#-------------------------------------------------------------------------------
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
Debug
Release
Sanitized
)
# Make sure the prefix path appears as a ccmake variable.
set (CMAKE_PREFIX_PATH "" CACHE PATH "Search paths for dependency look up.")
#-------------------------------------------------------------------------------
# Sanitizer options
#-------------------------------------------------------------------------------
add_library (sanitizer INTERFACE)
target_compile_options (sanitizer
INTERFACE
$<$<CONFIG:Sanitized>:-g>
)
macro (register_sanitizer_option name default)
string (TOUPPER ${name} upper_name)
option (SANITIZE_${upper_name} "Enable the ${name} sanitizer" ${default})
target_compile_options (sanitizer
INTERFACE
$<$<CONFIG:Sanitized>:$<$<BOOL:${SANITIZE_${upper_name}}>:-fsanitize=${name}>>
)
target_link_options (sanitizer
INTERFACE
$<$<CONFIG:Sanitized>:$<$<BOOL:${SANITIZE_${upper_name}}>:-fsanitize=${name}>>
)
endmacro ()
register_sanitizer_option (address ON)
register_sanitizer_option (leak OFF)
register_sanitizer_option (memory OFF)
register_sanitizer_option (thread OFF)
register_sanitizer_option (undefined ON)
register_sanitizer_option (float-divide-by-zero ON)
#-------------------------------------------------------------------------------
# Trap options
#-------------------------------------------------------------------------------
add_library (traps INTERFACE)
macro (register_trap_option name)
string (TOUPPER ${name} upper_name)
option (TRAP_${upper_name} "Enable the ${name} trap" OFF)
target_compile_options (traps
INTERFACE
$<$<AND:$<BOOL:${TRAP_${upper_name}}>,$<Fortran_COMPILER_ID:GNU>,$<COMPILE_LANGUAGE:Fortran>>:-ffpe-trap=${name}>
)
endmacro ()
register_trap_option (invalid)
register_trap_option (zero)
register_trap_option (overflow)
register_trap_option (inexact)
register_trap_option (denormal)
#-------------------------------------------------------------------------------
# Trap options
#-------------------------------------------------------------------------------
add_library (checks INTERFACE)
macro (register_checks_option name)
string (TOUPPER ${name} upper_name)
option (CHECK_${upper_name} "Enable the ${name} checks" OFF)
target_compile_options (checks
INTERFACE
$<$<AND:$<BOOL:${CHECK_${upper_name}}>,$<Fortran_COMPILER_ID:GNU>,$<COMPILE_LANGUAGE:Fortran>>:-fcheck=${name}>
)
endmacro ()
register_checks_option (recursion)
register_checks_option (pointer)
register_checks_option (mem)
register_checks_option (do)
register_checks_option (bounds)
#-------------------------------------------------------------------------------
# Setup access method.
#-------------------------------------------------------------------------------
option (USE_SSH "Use ssh to access git repos" OFF)
if (${USE_SSH})
set (URL_PROTO "git@")
set (URL_SEP ":")
else ()
set (URL_PROTO "https://")
set (URL_SEP "/")
endif ()
#-------------------------------------------------------------------------------
# Define a macro to register new projects.
#-------------------------------------------------------------------------------
macro (register_project name url default_tag)
string (TOUPPER ${name} dir)
option (BUILD_${dir} "Build ${name} subproject." OFF)
set (BUILD_TAG_${dir} ${default_tag} CACHE STRING "Name of the tag to checkout.")
if (BUILD_${dir})
# Set up the sub project repository.
FetchContent_Declare(
${name}
GIT_REPOSITORY ${url}
GIT_TAG origin/${BUILD_TAG_${dir}}
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${dir}
)
FetchContent_MakeAvailable(${name})
if (GIT_FOUND)
# By default cmake clones projects in a headless state. After the repo is
# cloned checkout the requested tag so repo is in a working state.
execute_process(
COMMAND ${GIT_EXECUTABLE} checkout ${BUILD_TAG_${dir}}
WORKING_DIRECTORY ${${name}_SOURCE_DIR}
)
# Add a taraget to pull the latest version before building. Note dependency is
# registered in the sub project CMakeList.txt. Not sure how this should handle
# multiple targets in a project yet. Name must match the subproject pull_
# dependency.
add_custom_target(
pull_${name}
ALL
COMMAND ${GIT_EXECUTABLE} pull
WORKING_DIRECTORY ${${name}_SOURCE_DIR}
)
endif ()
# Anything after the the tag is assumed to be a project dependency.
set (depends "${ARGN}")
foreach (project IN LISTS depends)
string (TOUPPER ${project} dep)
set (BUILD_${dep} ON CACHE BOOL "Build ${dep}" FORCE)
endforeach ()
endif ()
endmacro ()
#-------------------------------------------------------------------------------
# Build Documentation
#-------------------------------------------------------------------------------
find_package(Doxygen)
if (DOXYGEN_FOUND)
set (DOXYGEN_PROJECT_NAME "Stellarator-Tools")
set (DOXYGEN_PROJECT_LOGO ${CMAKE_CURRENT_SOURCE_DIR}/images/flux_surfaces.png)
set (DOXYGEN_EXCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/build ${CMAKE_CURRENT_SOURCE_DIR}/images)
set (DOXYGEN_ALIASES item{3}=\"<tr><td width=20%>\\fixed_width{\\1}</td><td width=50%>\\2</td><td width=30%>\\ref \\3</td></tr>\",item2{2}=\"<tr><td width=30%>\\1</td><td width=70%>\\2</td></tr>\",item3{3}=\"<tr><td width=20%>\\fixed_width{\\1}</td><td width=5%>\\2</td><td width=75%>\\3</td></tr>\",table_section{2}=\"\\subsection \\1 \\2^^<table border=1px width=80%>\",begin_table=\"<table border=1px width=80%>\",end_table=\"</table>\",table_subsection{2}=\"</table>\\subsubsection \\1 \\2^^<table border=1px width=80%>\",header{3}=\"<table border=1px width=80%><tr><td width=20%>\\fixed_width{\\1}</td><td width=50%>\\2</td><td width=30%>\\3</td></tr></table>\",header2{3}=\"<table border=1px width=80%><tr><td width=20%>\\fixed_width{\\1}</td><td width=5%>\\2</td><td width=75%>\\3</td></tr></table>\",fixed_width{1}=\"<tt>\\1</tt>\",header3{3}=\"<table border=1px width=80%><tr><td width=20%>\\fixed_width{\\1}</td><td width=20%>\\2</td><td width=60%>\\3</td></tr></table>\",item4{3}=\"<tr><td width=20%>\\fixed_width{\\1}</td><td width=20%>\\2</td><td width=60%>\\3</td></tr>\")
set (DOXYGEN_IMAGE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/images)
set (DOXYGEN_GENERATE_TREEVIEW YES)
doxygen_add_docs (doc)
endif ()
#-------------------------------------------------------------------------------
# Registers the projects. By specifying a name, directory, git url, tag and
# optional dependencies.
#
# register_project(example_project
# PROJECT_DIR
# https://url.to.project
# project_tag (Default to master)
# SUB) #Optional Sub project directories.
#-------------------------------------------------------------------------------
# Register BOOZ_XFORM
register_project(booz_xform
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/BOOZ_XFORM.git
master
libstell)
# Register V3FIT
register_project(v3fit
${URL_PROTO}github.com${URL_SEP}cianciosa/V3FIT.git
master
siesta
v3rfun
lgrid)
# Register V3RFUN
register_project(v3rfun
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/V3RFUN.git
master
libstell)
# Register SIESTA
register_project(siesta
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/SIESTA.git
master
parvmec
bmw)
# Register LGRID
register_project(lgrid
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/LGRID.git
master
libstell)
# Register SURFACE
register_project(surface
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/SURFACE.git
master
bmw)
# Register BMW
register_project(bmw
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/BMW.git
master
libstell)
# Register DESCUR
register_project(descur
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/DESCUR.git
master
libstell)
# Register PARVMEC
register_project(parvmec
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/PARVMEC.git
master
makegrid
libstell)
# Register MAKEGRID
register_project(makegrid
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/MAKEGRID.git
master
libstell)
# Register LIBSTELL
register_project(libstell
${URL_PROTO}github.com${URL_SEP}ORNL-Fusion/LIBSTELL.git
master)