forked from Exawind/nalu-wind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
291 lines (256 loc) · 10.1 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
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
############################ BASE ######################################
cmake_minimum_required (VERSION 3.1)
project(Nalu CXX C Fortran)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
########################## OPTIONS #####################################
option(ENABLE_TESTS "Enable regression testing." OFF)
option(ENABLE_DOCUMENTATION "Build documentation." OFF)
option(ENABLE_SPHINX_API_DOCS "Link Doxygen API docs to Sphinx" OFF)
option(ENABLE_OPENFAST
"Use OPENFAST tpl to get actuator line positions and forces" OFF)
option(ENABLE_PARAVIEW_CATALYST
"Enable ParaView Catalyst. Requires external installation of Trilinos Catalyst IOSS adapter."
OFF)
option(ENABLE_TIOGA "Use TIOGA TPL to perform overset connectivity" OFF)
option(ENABLE_HYPRE "Use HYPRE Solver library" OFF)
option(ENABLE_WARNINGS "Add -Wall to show compiler warnings" ON)
option(ENABLE_EXTRA_WARNINGS "Add -Wextra to show even more compiler warnings" OFF)
set(CMAKE_CXX_STANDARD 11) # Set nalu-wind C++11 standard
set(CMAKE_CXX_EXTENSIONS OFF) # Do not enable GNU extensions
set(CMAKE_CXX_STANDARD_REQUIRED) # Force error if C++11 standard is not supported
find_package(MPI REQUIRED)
include_directories(SYSTEM ${MPI_C_INCLUDE_PATH})
include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
include_directories(SYSTEM ${MPI_Fortran_INCLUDE_PATH})
find_package(OpenMP)
########################## TRILINOS ####################################
set(CMAKE_PREFIX_PATH ${Trilinos_DIR} ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${Trilinos_PATH} ${CMAKE_PREFIX_PATH})
find_package(Trilinos REQUIRED)
if(Trilinos_FOUND)
message("-- Found Trilinos = ${Trilinos_DIR}")
endif()
include_directories(SYSTEM ${Trilinos_INCLUDE_DIRS})
include_directories(SYSTEM ${Trilinos_TPL_INCLUDE_DIRS})
# Build Nalu as shared libraries if that is how Trilinos was built
if(Trilinos_BUILD_SHARED_LIBS)
set(Nalu_LIBRARY_TYPE SHARED)
set(BUILD_SHARED_LIBS ON)
else(Trilinos_BUILD_SHARED_LIBS)
set(Nalu_LIBRARY_TYPE STATIC)
endif(Trilinos_BUILD_SHARED_LIBS)
# Set Nalu's compilers, CMAKE_FIND_LIBRARY_PREFIXES
# and CMAKE_FIND_LIBRARY_SUFFIXES, etc, after inheriting settings from Trilinos
############################ YAML ######################################
set(CMAKE_PREFIX_PATH ${YAML_DIR} ${CMAKE_PREFIX_PATH})
find_package(YAML-CPP QUIET)
if(YAML-CPP_FOUND)
# YAML master branch is used
include_directories(SYSTEM ${YAML_CPP_INCLUDE_DIR})
else()
# YAML 0.5.3 is used
find_library(YAML_CPP_LIBRARIES NAMES yaml-cpp PATHS ${YAML_DIR}/lib)
find_path(YAML_CPP_INCLUDE_DIR yaml.h PATHS ${YAML_DIR}/include/yaml-cpp)
if((DEFINED YAML_CPP_LIBRARIES) AND (DEFINED YAML_CPP_INCLUDE_DIR))
include_directories(SYSTEM ${YAML_CPP_INCLUDE_DIR}/..)
set(YAML-CPP_FOUND TRUE)
endif()
endif()
if(YAML-CPP_FOUND)
message("-- Found YAML-CPP = ${YAML_DIR}")
else()
message(FATAL_ERROR "YAML-CPP NOT FOUND")
endif()
############################ HYPRE #####################################
if(ENABLE_HYPRE)
set(CMAKE_PREFIX_PATH ${HYPRE_DIR} ${CMAKE_PREFIX_PATH})
# Quiet down HYPRE's own "found" output to be consistent with others
find_package(HYPRE QUIET REQUIRED)
if(HYPRE_FOUND)
message("-- Found HYPRE = ${HYPRE_DIR}")
endif()
include_directories(SYSTEM ${HYPRE_INCLUDE_DIRS})
add_definitions("-DNALU_USES_HYPRE")
endif(ENABLE_HYPRE)
########################## OPENFAST ####################################
if(ENABLE_OPENFAST)
set(CMAKE_PREFIX_PATH ${OpenFAST_DIR} ${CMAKE_PREFIX_PATH})
find_package(OpenFAST REQUIRED)
if(OpenFAST_FOUND)
message("-- Found OpenFAST = ${OpenFAST_DIR}")
endif()
include_directories(${OpenFAST_INCLUDE_DIRS})
add_definitions("-DNALU_USES_OPENFAST")
endif(ENABLE_OPENFAST)
############################ TIOGA #####################################
if(ENABLE_TIOGA)
set(CMAKE_PREFIX_PATH ${TIOGA_DIR} ${CMAKE_PREFIX_PATH})
find_package(TIOGA REQUIRED)
if(TIOGA_FOUND)
message("-- Found TIOGA = ${TIOGA_DIR}")
endif()
include_directories(${TIOGA_INCLUDE_DIRS})
add_definitions("-DNALU_USES_TIOGA")
endif()
########################### NALU #####################################
# Add any extra flags based on compiler and/or OS
message("-- CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
message("-- CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(EXTRA_CXX_FLAGS "")
set(EXTRA_Fortran_FLAGS "")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(EXTRA_CXX_FLAGS "")
set(EXTRA_Fortran_FLAGS "")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(EXTRA_CXX_FLAGS "")
set(EXTRA_Fortran_FLAGS "")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
set(EXTRA_CXX_FLAGS "-restrict")
set(EXTRA_Fortran_FLAGS "")
endif()
if(ENABLE_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wall")
endif()
if(ENABLE_EXTRA_WARNINGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra -pedantic")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -Wextra -pedantic")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXX_FLAGS}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${EXTRA_Fortran_FLAGS}")
if (OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
endif()
message("-- CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message("-- CMAKE_Fortran_FLAGS = ${CMAKE_Fortran_FLAGS}")
if(ENABLE_HYPRE)
include(CheckSymbolExists)
set(CMAKE_REQUIRED_INCLUDES "${HYPRE_INCLUDE_DIRS}")
check_symbol_exists(
HYPRE_BIGINT "${HYPRE_INCLUDE_DIRS}/HYPRE_config.h" NALU_HYPRE_BIGINT)
if(NOT NALU_HYPRE_BIGINT)
message(WARNING
"HYPRE does not enable 64-bit integer support; will fail on large problems!")
endif()
endif()
########################### TAG VERSIONS #####################################
include(GetGitRevisionDescription)
get_git_head_revision(NALU_GITREFSPEC NALU_GIT_COMMIT_SHA)
if (NALU_GIT_COMMIT_SHA)
git_describe(NALU_VERSION_TAG "--tags")
git_local_changes(NALU_REPO_DIRTY)
option(NALU_HAVE_GIT_INFO "Git version tagging for Nalu" ON)
if (${NALU_VERSION_TAG} MATCHES ".*-NOTFOUND")
set(NALU_VERSION_TAG "v1.2.0")
endif()
endif()
find_file(TRILINOS_HAVE_GIT_INFO
"TrilinosRepoVersion.txt"
PATHS "${Trilinos_DIR}/../../../"
DOC "Check if Trilinos Git version info exists"
NO_DEFAULT_PATH)
if (NOT ${TRILINOS_HAVE_GIT_INFO} MATCHES ".*-NOTFOUND")
file(STRINGS "${Trilinos_DIR}/../../../TrilinosRepoVersion.txt"
TRILINOS_REPO_VERSION_TXT LIMIT_INPUT 1024)
list(GET TRILINOS_REPO_VERSION_TXT 1 TRILINOS_REPO_COMMIT_STR)
string(REGEX MATCH "^[a-z0-9]+" TRILINOS_GIT_COMMIT_SHA ${TRILINOS_REPO_COMMIT_STR})
set(TRILINOS_VERSION_TAG "${Trilinos_VERSION}-g${TRILINOS_GIT_COMMIT_SHA}")
else()
set(TRILINOS_VERSION_TAG "${Trilinos_VERSION}")
endif()
string(TIMESTAMP NALU_VERSION_TIMESTAMP "%Y-%m-%d %H:%M:%S (UTC)" UTC)
configure_file("${CMAKE_SOURCE_DIR}/cmake/NaluVersionInfo.h.in"
"${CMAKE_BINARY_DIR}/include/NaluVersionInfo.h" @ONLY)
#### END TAG VERSIONS
# Add all source files from source subdirectories
function(add_sources target_list)
foreach(_source IN ITEMS ${ARGN})
if (IS_ABSOLUTE "${_source}")
set(_source_abs "${_source}")
else()
get_filename_component(_source_abs "${_source}" ABSOLUTE)
endif()
set_property(GLOBAL APPEND PROPERTY "${target_list}" "${_source_abs}")
endforeach()
endfunction(add_sources)
add_subdirectory(src)
add_subdirectory(include)
add_subdirectory(unit_tests)
get_property(NALU_SOURCES GLOBAL PROPERTY GlobalSourceList)
get_property(NALU_HEADERS GLOBAL PROPERTY GlobalHeaderList)
get_property(NALU_UNIT_SOURCES GLOBAL PROPERTY GlobalUnitSourceList)
get_property(NALU_UNIT_HEADERS GLOBAL PROPERTY GlobalUnitHeaderList)
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_BINARY_DIR}/include)
add_library(nalu ${NALU_SOURCES})
target_link_libraries(nalu ${Trilinos_LIBRARIES})
target_link_libraries(nalu ${YAML_CPP_LIBRARIES})
target_link_libraries(nalu ${MPI_CXX_LIBRARIES} ${MPI_Fortran_LIBRARIES} ${MPI_C_LIBRARIES})
if(ENABLE_OPENFAST)
target_link_libraries(nalu ${OpenFAST_LIBRARIES} ${OpenFAST_CPP_LIBRARIES})
endif()
if(ENABLE_TIOGA)
target_link_libraries(nalu ${TIOGA_LIBRARIES})
endif()
if(ENABLE_HYPRE)
target_link_libraries(nalu ${HYPRE_LIBRARIES})
endif()
set(nalu_ex_name "naluX")
message("-- CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
set(nalu_ex_name "naluXd")
message("Debug Build")
endif()
add_executable(${nalu_ex_name} nalu.C)
target_link_libraries(${nalu_ex_name} nalu)
if(MPI_COMPILE_FLAGS)
set_target_properties(${nalu_ex_name} PROPERTIES
COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
endif(MPI_COMPILE_FLAGS)
if(MPI_LINK_FLAGS)
set_target_properties(${nalu_ex_name} PROPERTIES
LINK_FLAGS "${MPI_LINK_FLAGS}")
endif(MPI_LINK_FLAGS)
set(utest_ex_name "unittestX")
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG")
set(utest_ex_name "unittestXd")
endif()
add_executable(${utest_ex_name} unit_tests.C ${NALU_UNIT_SOURCES})
target_link_libraries(${utest_ex_name} nalu)
target_include_directories(${utest_ex_name} PUBLIC "${CMAKE_SOURCE_DIR}/unit_tests")
if(MPI_COMPILE_FLAGS)
set_target_properties(${utest_ex_name} PROPERTIES
COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
endif(MPI_COMPILE_FLAGS)
if(MPI_LINK_FLAGS)
set_target_properties(${utest_ex_name} PROPERTIES
LINK_FLAGS "${MPI_LINK_FLAGS}")
endif(MPI_LINK_FLAGS)
set(nalu_ex_catalyst_name "naluXCatalyst")
if(ENABLE_PARAVIEW_CATALYST)
set(PARAVIEW_CATALYST_INSTALL_PATH
""
CACHE
PATH
"Path to external installation of Trilinos Catalyst IOSS plugin.")
configure_file(cmake/naluXCatalyst.in ${nalu_ex_catalyst_name} @ONLY)
endif()
install(TARGETS ${utest_ex_name} ${nalu_ex_name} nalu
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install(DIRECTORY include/ DESTINATION include)
if(ENABLE_PARAVIEW_CATALYST)
install(PROGRAMS ${CMAKE_BINARY_DIR}/naluXCatalyst DESTINATION bin)
endif()
include(CMakePackageConfigHelpers)
if(ENABLE_DOCUMENTATION)
add_subdirectory(docs)
endif()
if(ENABLE_TESTS)
enable_testing()
include(CTest)
add_subdirectory(reg_tests)
endif()