-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
269 lines (225 loc) · 9.75 KB
/
CMakeLists.txt
File metadata and controls
269 lines (225 loc) · 9.75 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
# Copyright (c) 2023-2024, The Neko-TOP Authors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# * Neither the name of the authors nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# ============================================================================ #
# Neko-TOP: Neko Topology Optimization Package
# ============================================================================ #
cmake_minimum_required(VERSION 3.21)
project(Neko-TOP VERSION 0.0.1 LANGUAGES Fortran)
# Set language standards
set(CMAKE_Fortran_STANDARD 2008)
# ............................................................................ #
# Define cmake variables
# Define the list of available build types
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build")
set(CMAKE_BUILD_TYPE_LIST
Debug
Release
Testing
)
set(CMAKE_Fortran_PREPROCESS ON)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# ............................................................................ #
# Options
# Assign default values to options
option(BUILD_EXAMPLES "Build the examples" OFF)
option(BUILD_DOCS "Build documentation" OFF)
option(BUILD_TESTING "Build the tests" OFF)
option(ONLY_DOCS "Only build the documentation" OFF)
# ============================================================================ #
# Documentation
# ============================================================================ #
# Add the documentation target to ALL if we have "BUILD_DOCS" enabled
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/documentation)
if (ONLY_DOCS)
return()
endif()
# ============================================================================ #
# Setup External Libraries
# ============================================================================ #
# Check for the required libraries.
find_package(BLAS QUIET)
find_package(LAPACK QUIET)
# Check for the optional libraries.
find_package(MPI REQUIRED)
find_package(OpenMP REQUIRED COMPONENTS Fortran)
# We need PKG Config to find the JSON-Fortran and Neko libraries
find_package(PkgConfig REQUIRED)
# Check that the MPI Fortran 2008 module is available
if (NOT MPI_Fortran_HAVE_F08_MODULE)
message(FATAL_ERROR "MPI Fortran 2008 module is required for Neko-TOP.")
endif()
include_directories(${MPI_Fortran_INCLUDE_DIRS})
include_directories(${MPI_Fortran_MODULE_DIR})
# Set the default external directory
if (DEFINED ENV{EXTERNAL_DIR})
set(EXTERNAL_DIR $ENV{EXTERNAL_DIR})
else()
set(EXTERNAL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external)
endif()
# ............................................................................ #
# Setup of JSON-Fortran
# Set the proper paths for the JSON_FORTRAN_DIR directory
if (DEFINED ENV{JSON_FORTRAN_DIR} AND IS_ABSOLUTE $ENV{JSON_FORTRAN_DIR})
set(JSON_FORTRAN_DIR $ENV{JSON_FORTRAN_DIR} CACHE STRING
"Path to the JSON-Fortran installation")
elseif(DEFINED ENV{JSON_FORTRAN_DIR})
set(JSON_FORTRAN_DIR ${EXTERNAL_DIR}/$ENV{JSON_FORTRAN_DIR}
CACHE STRING "Path to the JSON-Fortran installation")
else()
set(JSON_FORTRAN_DIR ${EXTERNAL_DIR}/json-fortran
CACHE STRING "Path to the JSON-Fortran installation")
endif()
set(CMAKE_PREFIX_PATH ${JSON_FORTRAN_DIR} ${CMAKE_PREFIX_PATH})
# Find the JSON-Fortran library
pkg_check_modules(json-fortran REQUIRED IMPORTED_TARGET json-fortran)
# ............................................................................ #
# Setup of the Neko library
# Set the proper paths for the NEKO_DIR
if (DEFINED ENV{NEKO_DIR} AND IS_ABSOLUTE $ENV{NEKO_DIR})
set(NEKO_DIR $ENV{NEKO_DIR} CACHE STRING
"Path to the Neko installation")
elseif(DEFINED ENV{NEKO_DIR})
set(NEKO_DIR ${EXTERNAL_DIR}/$ENV{NEKO_DIR}
CACHE STRING "Path to the Neko installation")
else()
set(NEKO_DIR ${EXTERNAL_DIR}/neko
CACHE STRING "Path to the Neko installation")
endif()
set(CMAKE_PREFIX_PATH ${NEKO_DIR} ${CMAKE_PREFIX_PATH})
# Find the Neko library
pkg_check_modules(neko REQUIRED IMPORTED_TARGET neko)
pkg_get_variable(DEVICE_TYPE neko backend)
# ............................................................................ #
# HDF5 Support
if (DEFINED ENV{HDF5_DIR} AND IS_ABSOLUTE $ENV{HDF5_DIR})
set(HDF5_DIR $ENV{HDF5_DIR} CACHE STRING
"Path to the HDF5 installation")
elseif(DEFINED ENV{HDF5_DIR})
set(HDF5_DIR ${EXTERNAL_DIR}/$ENV{HDF5_DIR}
CACHE STRING "Path to the HDF5 installation")
endif()
if (DEFINED HDF5_DIR)
set(CMAKE_PREFIX_PATH ${HDF5_DIR} ${CMAKE_PREFIX_PATH})
endif()
find_package(HDF5 QUIET COMPONENTS Fortran)
if (NOT HDF5_FOUND)
pkg_check_modules(HDF5 QUIET IMPORTED_TARGET hdf5)
if (NOT HDF5_FOUND)
pkg_check_modules(HDF5 QUIET IMPORTED_TARGET hdf5_parallel)
endif()
if (HDF5_FOUND)
set(HDF5_PKG_FOUND TRUE)
set(HDF5_FOUND FALSE)
endif()
endif()
if (HDF5_FOUND OR HDF5_PKG_FOUND)
set(HAVE_HDF5 TRUE)
add_compile_definitions(HAVE_HDF5=1)
endif()
# ............................................................................ #
# Setup PFUnit
if (DEFINED ENV{PFUNIT_DIR} AND IS_ABSOLUTE $ENV{PFUNIT_DIR})
set(PFUNIT_DIR $ENV{PFUNIT_DIR} CACHE STRING
"Path to the pFUnit installation")
elseif(DEFINED ENV{PFUNIT_DIR})
set(PFUNIT_DIR ${EXTERNAL_DIR}/$ENV{PFUNIT_DIR}
CACHE STRING "Path to the pFUnit installation")
else()
set(PFUNIT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/pfunit
CACHE STRING "Path to the pFUnit installation")
endif()
# ============================================================================ #
# Setup compiler specific options
# ============================================================================ #
# Set the compiler flags
include(${CMAKE_Fortran_COMPILER_ID} OPTIONAL RESULT_VARIABLE compiler_flags_found)
if (NOT compiler_flags_found)
message(WARNING "No specific compiler flags found for "
"${CMAKE_Fortran_COMPILER_ID}.")
endif()
# ============================================================================ #
# Setup the Neko-TOP library
# ============================================================================ #
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sources)
# Add a static library target for use in examples and tests
# This ensures the complete Neko-TOP library is built and linked before any
# examples or tests are built.
add_library(neko-top-a STATIC IMPORTED)
set_target_properties(neko-top-a PROPERTIES
IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/libneko-top.a"
)
add_custom_target(neko-top_ready
DEPENDS neko-top
COMMENT "Neko-TOP library is ready.")
add_dependencies(neko-top-a neko-top_ready)
# ============================================================================ #
# Build the examples
# ============================================================================ #
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples)
# ============================================================================ #
# Build the tests
# ============================================================================ #
# Setup testing
include(CTest)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests)
# ============================================================================ #
# Write messages to the user about the options and paths if we are at the top
# level of the build.
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
string(REPEAT "=" 80 BARRIER)
message(STATUS ${BARRIER})
message(STATUS "Neko-TOP: Neko Topology Optimization Package")
message(STATUS "")
message(STATUS "Current configuration:")
message(STATUS "- CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "- DEVICE_TYPE: ${DEVICE_TYPE}")
message(STATUS "- BUILD_DOCS: ${BUILD_DOCS}")
message(STATUS "- BUILD_TESTING: ${BUILD_TESTING}")
message(STATUS "- BUILD_EXAMPLES: ${BUILD_EXAMPLES}")
message(STATUS "")
message(STATUS "External dependencies:")
message(STATUS "- JSON_FORTRAN_DIR: ${JSON_FORTRAN_DIR}")
message(STATUS "- NEKO_DIR: ${NEKO_DIR}")
message(STATUS "- PFUNIT_DIR: ${PFUNIT_DIR}")
if (DEFINED HDF5_DIR AND IS_DIRECTORY "${HDF5_DIR}")
message(STATUS "- HDF5: ${HDF5_DIR}")
elseif (HDF5_FOUND)
message(STATUS "- HDF5: Found (HDF5 support enabled)")
else()
message(STATUS "- HDF5: Not found (HDF5 support disabled)")
endif()
message(STATUS ${BARRIER})
message(STATUS "")
endif()
# ============================================================================ #
# End of file