-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
321 lines (259 loc) · 9.15 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# This program is a part of EASIFEM library Copyright (C) 2020-2021 Vikas
# Sharma, Ph.D
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <https: //www.gnu.org/licenses/>
#
cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR)
set(PROJECT_NAME "easifemClasses")
project(${PROJECT_NAME})
enable_language(Fortran C CXX)
set(VERSION_MAJOR "24")
set(VERSION_MINOR "4")
set(VERSION_BugFix "1")
set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BugFix})
set(CMAKE_PROJECT_DESCRIPTION
"${PROJECT_NAME} is part of EASIFEM platform.
EASIFEM: Expandable and Scalable Infrastructure for Finite Element Methods.
")
set(CMAKE_PROJECT_HOMEPAGE_URL "https://www.easifem.com")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}")
include(CMakePrintHelpers)
include(FortranCInterface)
FortranCInterface_VERIFY()
list(APPEND TARGET_COMPILE_DEF "-DUSE_CMAKE")
# find my cmake modules here...
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules)
# check error
if(" ${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL " ${CMAKE_CURRENT_BINARY_DIR}")
message(
FATAL_ERROR
"[ERROR] :: Build directory and Source directory cannot be same.")
endif()
# make directories include(${PROJECT_SOURCE_DIR}/cmake/makeDirs.cmake)
include(GNUInstallDirs)
set(CMAKE_Fortran_MODULE_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
set(INSTALL_LIBDIR
${CMAKE_INSTALL_LIBDIR}
CACHE PATH "Installation location of lib")
set(INSTALL_INCLUDEDIR
${CMAKE_INSTALL_INCLUDEDIR}
CACHE PATH "Installation location of module files")
set(INSTALL_BINDIR
${CMAKE_INSTALL_BINDIR}
CACHE PATH "Installation location of binary files")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKEDIR CMake)
else()
set(DEF_INSTALL_CMAKEDIR share/cmake/${PROJECT_NAME})
endif()
set(INSTALL_CMAKEDIR
${DEF_INSTALL_CMAKEDIR}
CACHE PATH "Installation directory for CMake files")
foreach(p LIB BIN INCLUDE CMAKE)
file(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/${INSTALL_${p}DIR} _path)
message(STATUS "Installing ${p} componenets to ${_path}")
endforeach()
option(BUILD_SHARED_LIBS "Build shared library" ON)
if(BUILD_SHARED_LIBS)
message(STATUS "${PROJECT_NAME} will be built as a shared library.")
add_library(${PROJECT_NAME} SHARED "")
set_property(TARGET ${PROJECT_NAME} PROPERTY POSITION_INDEPENDENT_CODE TRUE)
else()
message(STATUS "${PROJECT_NAME} will be built as a static library.")
add_library(${PROJECT_NAME} STATIC "")
endif()
# include(${PROJECT_SOURCE_DIR}/cmake/Compiler.cmake)
message(
STATUS
"[INFO] :: Is the Fortran compiler loaded? ${CMAKE_Fortran_COMPILER_LOADED}"
)
if(CMAKE_Fortran_COMPILER_LOADED)
message(STATUS "[INFO] :: Fortran compiler: ${CMAKE_Fortran_COMPILER_ID}")
message(
STATUS
"[INFO] :: Fortran compiler version is: ${CMAKE_Fortran_COMPILER_VERSION}"
)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Build type" FORCE)
endif()
if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU" OR Fortran_COMPILER_NAME MATCHES
"gfortran*")
list(
APPEND
FORTRAN_FLAGS
"-ffree-form"
"-ffree-line-length-none"
"-std=f2018"
"-fimplicit-none"
"-fno-range-check")
list(APPEND FORTRAN_FLAGS_RELEASE "-O3")
if(APPLE)
list(
APPEND
FORTRAN_FLAGS_DEBUG
"-fbounds-check"
"-g"
"-fbacktrace"
"-Wextra"
"-Wall"
# "-fprofile-arcs"
"-ftest-coverage"
"-Wimplicit-interface")
else()
list(
APPEND
FORTRAN_FLAGS_DEBUG
"-fbounds-check"
"-g"
"-fbacktrace"
"-Wextra"
"-Wall"
# "-fprofile-arcs"
"-ftest-coverage"
"-Wimplicit-interface")
endif()
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel" OR Fortran_COMPILER_NAME
MATCHES "ifort*")
list(APPEND FORTRAN_FLAGS "-r8" "-W1")
list(APPEND FORTRAN_FLAGS_RELEASE "-O3")
list(
APPEND
FORTRAN_FLAGS_DEBUG
"-O0"
"-traceback"
"-g"
"-debug all"
"-check all"
"-ftrapuv"
"-warn"
"nointerfaces")
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "XL" OR Fortran_COMPILER_NAME
MATCHES "xlf*")
list(APPEND FORTRAN_FLAGS "-q64" "-qrealsize=8" "-qsuffix=f=f90:cpp=f90")
list(APPEND FORTRAN_FLAGS_RELEASE "-O3" "-qstrict")
list(APPEND FORTRAN_FLAGS_DEBUG "-O0" "-g" "-qfullpath" "-qkeepparm")
else()
message(ERROR "[ERROR] :: No optimized Fortran compiler flags are known")
endif()
cmake_print_variables(FORTRAN_FLAGS)
cmake_print_variables(FORTRAN_FLAGS_RELEASE)
cmake_print_variables(FORTRAN_FLAGS_DEBUG)
# include(${PROJECT_SOURCE_DIR}/cmake/targetCompileOpts.cmake)
target_compile_options(
${PROJECT_NAME}
PRIVATE ${TARGET_COMPILE_OPT} ${FORTRAN_FLAGS}
"$<$<CONFIG:Debug>:${FORTRAN_FLAGS_DEBUG}>"
"$<$<CONFIG:Release>:${FORTRAN_FLAGS_RELEASE}>")
# include(${PROJECT_SOURCE_DIR}/cmake/targetIncludeDirs.cmake)
target_include_directories(
${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_Fortran_MODULE_DIRECTORY}>
$<INSTALL_INTERFACE:${INSTALL_INCLUDEDIR}>)
# include(${PROJECT_SOURCE_DIR}/cmake/targetProperties.cmake) target properties
set_target_properties(
${PROJECT_NAME}
PROPERTIES POSITION_INDEPENDENT_CODE 1
SOVERSION ${VERSION_MAJOR}
OUTPUT_NAME ${PROJECT_NAME}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
MACOSX_RPATH ON
WINDOWS_EXPORT_ALL_SYMBOLS ON)
# include(${PROJECT_SOURCE_DIR}/cmake/targetCompileDefs.cmake)
option(USE_REAL32 OFF)
option(USE_REAL64 ON)
if(USE_REAL32)
list(APPEND TARGET_COMPILE_DEF "-DUSE_Real32")
endif()
if(USE_REAL64)
list(APPEND TARGET_COMPILE_DEF "-DUSE_Real64")
endif()
option(USE_INT32 ON)
if(USE_INT32)
list(APPEND TARGET_COMPILE_DEF "-DUSE_Int32")
endif()
option(USE_INT64 OFF)
if(USE_INT64)
list(APPEND TARGET_COMPILE_DEF "-DUSE_Int64")
endif()
list(APPEND TARGET_COMPILE_DEF "-D${CMAKE_HOST_SYSTEM_NAME}_SYSTEM")
# DEFINE DEBUG
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
list(APPEND TARGET_COMPILE_DEF "-DDEBUG_VER")
endif()
# include(${PROJECT_SOURCE_DIR}/cmake/install.cmake) Installation
install(
DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY}
DESTINATION "./"
COMPONENT "${PROJECT_NAME}")
install(
EXPORT ${TARGETS_EXPORT_NAME}
FILE "${TARGETS_EXPORT_NAME}.cmake"
NAMESPACE ${namespace}::
DESTINATION ${INSTALL_CMAKEDIR}
COMPONENT "${PROJECT_NAME}")
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion)
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION ${INSTALL_CMAKEDIR}
PATH_VARS INSTALL_INCLUDEDIR)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${INSTALL_CMAKEDIR}
COMPONENT "${PROJECT_NAME}-dev")
# Find external dependency of the project FIXME:
if(NOT CMAKE_PREFIX_PATH)
list(APPEND CMAKE_PREFIX_PATH "$ENV{EASIFEM_EXTPKGS}" "$ENV{EASIFEM_BASE}")
endif()
# linking include(${PROJECT_SOURCE_DIR}/cmake/targetLinkLibs.cmake)
find_package(easifemBase REQUIRED)
if(easifemBase_FOUND)
message(STATUS "FOUND easifemBase")
else()
message(ERROR "NOT FOUND easifemBase")
endif()
target_link_libraries(${PROJECT_NAME} PUBLIC easifemBase::easifemBase)
include(${PROJECT_SOURCE_DIR}/cmake/addHDF5.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/addGmsh.cmake)
# Add source files
include(src/modules/CMakeLists.txt)
include(src/submodules/CMakeLists.txt)
# this should be in the end.
target_compile_definitions(${PROJECT_NAME} PUBLIC ${TARGET_COMPILE_DEF})
message(STATUS "[INFO] :: Compiler definition : ${TARGET_COMPILE_DEF}")
install(
TARGETS ${PROJECT_NAME} ${C_PROJECTS}
EXPORT ${TARGETS_EXPORT_NAME}
COMPONENT "${PROJECT_NAME}"
ARCHIVE DESTINATION ${INSTALL_LIBDIR}
RUNTIME DESTINATION ${INSTALL_BINDIR}
LIBRARY DESTINATION ${INSTALL_LIBDIR})
include(${PROJECT_SOURCE_DIR}/cmake/packaging.cmake)