-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
235 lines (217 loc) · 10.2 KB
/
CMakeLists.txt
File metadata and controls
235 lines (217 loc) · 10.2 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
cmake_minimum_required(VERSION 3.21.0)
project(AsFem)
set(CMAKE_CXX_STANDARD 17)
###############################################
### Set your PETSc/MPI path here or bashrc ###
### The only things to modify are the ###
### following two lines(PETSC/MPI_DIR) ###
###############################################
SET(WINDOWS "False" CACHE STRING "WINDOWS")
if(WINDOWS)
message("We are running on windows system with cygwin/mingw ...")
message(WARNING "Please use Cygwin or Mingw for the compiling !")
if(EXISTS $ENV{PETSC_DIR})
set(PETSC_DIR $ENV{PETSC_DIR})
message("PETSc dir is: ${PETSC_DIR}")
set(PETSC_INC "${PETSC_DIR}/include")
set(PETSC_LIB "${PETSC_DIR}/lib/libpetsc.dll")
include_directories("${PETSC_DIR}/include")
link_libraries("${PETSC_LIB}")
message(" PETSc include dir is: ${PETSC_INC}")
message(" PETSc library dir is: ${PETSC_LIB}")
else()
message(FATAL_ERROR "PETSC_DIR is not defined in your cygwin/mingw terminal, please set the path correctly !")
endif()
if(EXISTS $ENV{MPI_DIR})
message(FATAL_ERROR "MPI_DIR is not supported in cygwin/mingw terminal, please remove it !")
endif()
elseif(UNIX)
message ("We are running on linux system ...")
########################################
### for PETSc
########################################
if(EXISTS $ENV{MPI_DIR})
set(MPI_DIR $ENV{MPI_DIR})
message("MPI dir is: ${MPI_DIR}")
include_directories("${MPI_DIR}/include")
find_library(MPI_LIB NAMES mpi mpicxx HINTS ${MPI_DIR}/lib ${MPI_DIR}/lib64)
if(NOT MPI_LIB)
message(FATAL_ERROR " MPI lib dir can\'t be found!")
endif()
message(" MPI include dir is: ${MPI_DIR}/include")
else()
find_path(MPI_INC NAMES mpi.h
PATHS /usr/lib/x86_64-linux-gnu/openmpi/include
/lib64/mpi/gcc/openmpi4/include
/usr/lib64/petsc/*/linux-gnu-c-opt/include/petsc/mpiuni)
find_library(MPI_LIB NAMES mpi
PATHS /usr/lib
/usr/lib64
/usr/lib64/mpi/gcc/openmpi4/lib64
/opt/openmpi/lib)
message (WARNING "MPI location (MPI_DIR) is not defined in your PATH, AsFem will try to use the default one installed in your system. If your mpi path is not correct, please modifiy MPI_INC and MPI_LIB in your CMakeList.txt")
if(NOT MPI_INC)
message(FATAL_ERROR " MPI include dir can\'t be found!")
endif()
if(NOT MPI_LIB)
message(FATAL_ERROR " MPI lib dir can\'t be found!")
endif()
include_directories("${MPI_INC}")
message(" MPI include dir is: ${MPI_INC}")
endif()
link_directories("${MPI_LIB}")
message(" MPI library dir is: ${MPI_LIB}")
########################################
### for PETSc
########################################
if(EXISTS $ENV{PETSC_DIR})
set(PETSC_DIR $ENV{PETSC_DIR})
message("PETSC dir is: ${PETSC_DIR}")
include_directories("${PETSC_DIR}/include")
find_library(PETSC_LIB NAMES petsc HINTS ${PETSC_DIR}/lib ${PETSC_DIR}/lib64)
if(NOT PETSC_LIB)
message(FATAL_ERROR " PETSc lib dir can\'t be found!")
endif()
find_library(METIS_LIB NAMES metis HINTS ${PETSC_DIR}/lib ${PETSC_DIR}/lib64)
# ###
# if(NOT METIS_LIB)
# message(FATAL_ERROR " METIS lib dir can\'t be found!")
# endif()
# message(" METIS library is: ${METIS_LIB}")
# link_libraries("${METIS_LIB}")
else()
message (WARNING "PETSc location (PETSC_DIR) is not defined in your PATH, AsFem will try to use the default one installed in your system. If your PETSC_DIR path is not correct, please modifiy PETSC_INC and PETSC_LIB in your CMakeList.txt")
find_path(PETSC_INC NAMES petsc.h
PATHS /usr/lib/petsc
/usr/lib/petscdir/*
/opt/petsc/linux-c-opt
/opt/local/lib/petsc
/usr/lib64/petsc/*/linux-gnu-c-opt
/usr/lib64/mpi/gcc/openmpi4/lib64/
/usr/lib64/mpi/gcc/openmpi4/lib64/petsc/*/linux-gnu-c-opt/lib)
find_library(PETSC_LIB NAMES petsc PATHS /usr)
if(NOT PETSC_INC)
message(FATAL_ERROR " PETSc include dir can\'t be found!")
endif()
if(NOT PETSC_LIB)
message(FATAL_ERROR " PETSc lib dir can\'t be found!")
endif()
message(" PETSc include dir is: ${PETSC_INC}")
include_directories("${PETSC_INC}")
endif()
message(" PETSC include dir is: ${PETSC_DIR}/include")
message(" PETSc library dir is: ${PETSC_LIB}")
link_directories("${PETSC_LIB}")
endif()
#############################################################
### ENV setup for the METIS package ###
### You should install the GKlib and METIS package ###
#############################################################
# ### for GKlib
# if(EXISTS $ENV{GKLIB_DIR})
# set(GKLIB_DIR $ENV{GKLIB_DIR})
# message("GKLib dir is: ${GKLIB_DIR}")
# find_library(GKLIB NAMES GKlib HINTS ${GKLIB_DIR}/lib ${GKLIB_DIR}/lib64)
# if(NOT GKLIB)
# message(FATAL_ERROR "GKLib dir can\'t be found!")
# endif()
# message(" GKLib include dir is: ${GKLIB_DIR}/include")
# message(" GKLib library dir is: ${GKLIB}")
# include_directories("${GKLIB_DIR}/include")
# link_libraries("${GKLIB}")
# else()
# message (WARNING "GKLib location (GKLIB_DIR) is not defined in your PATH, AsFem will try to use the default one installed in your system. If your GKLib path is not correct, please modifiy GKLIB_DIR in your CMakeList.txt")
# set(GKLIB_DIR "/home/by/Programs/toolkits/gcc13/GKlib")
# message(" GKLib include dir is: ${GKLIB_DIR}/include")
# message(" GKLib library dir is: ${GKLIB_DIR}/lib/libGKlib.a")
# include_directories("${GKLIB_DIR}/include")
# link_libraries("${GKLIB_DIR}/lib/libGKlib.a")
# endif ()
# ## for METIS
# if(EXISTS $ENV{METIS_DIR})
# set(METIS_DIR $ENV{METIS_DIR})
# message("METIS dir is: ${METIS_DIR}")
# find_library(METIS_LIB NAMES metis HINTS ${METIS_DIR}/lib ${METIS_DIR}/lib64)
# if(NOT METIS_LIB)
# message(FATAL_ERROR " METIS lib can\'t be found!")
# endif()
# message(" METIS include dir is: ${METIS_DIR}/include")
# message(" METIS library dir is: ${METIS_LIB}")
# include_directories("${METIS_DIR}/include")
# link_libraries("${METIS_LIB}")
# else()
# message (WARNING "METIS location (METIS_DIR) is not defined in your PATH, AsFem will try to use the default one installed in your system. If your METIS_DIR path is not correct, please modifiy METIS_DIR_DIR in your CMakeList.txt")
# set(METIS_DIR "/home/by/Programs/toolkits/gcc13/METIS")
# set(METIS_LIB "/home/by/Programs/toolkits/gcc13/METIS/lib/libmetis.so")
# include_directories("${METIS_DIR}/include")
# link_libraries("${METIS_LIB}")
# endif ()
###############################################
# For external packages ###
###############################################
### for eigen
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/external/eigen")
### for json
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/external")
###############################################
### set debug or release mode ###
###############################################
if (CMAKE_BUILD_TYPE STREQUAL "")
# user should use -DCMAKE_BUILD_TYPE=Release[Debug] option
set (CMAKE_BUILD_TYPE "Debug")
endif ()
###############################################
### set LTO for asfem ###
###############################################
# LTO is Link-Time Optimization.
# This block check current compiler supports whether the IPO/LTO technology.
# added by wwj(bbsy789@126.com) on 2022.12.10.
if (CMAKE_BUILD_TYPE STREQUAL "Release")
include(CheckIPOSupported)
check_ipo_supported(RESULT currentCompilerLTOsupported OUTPUT error)
endif ()
###############################################
### For linux platform ###
###############################################
if(UNIX)
if (CMAKE_BUILD_TYPE STREQUAL "Depdebug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -O0 -fsanitize=address -g -fno-omit-frame-pointer -std=c++17")
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -O2 -std=c++17")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native -mtune=native -DNDEBUG -std=c++17")
else()
message (FATAL_ERROR "Unknown cmake build type (CMAKE_BUILD_TYPE)")
endif()
elseif(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /W1 /arch:AVX")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GL /openmp")
endif()
message("AsFem will be compiled in ${CMAKE_BUILD_TYPE} mode !")
message("CXX compiler options are: ${CMAKE_CXX_FLAGS}")
message("The executable file 'asfem' will be generated in ${CMAKE_CURRENT_SOURCE_DIR}/bin folder")
###############################################
### Do not edit the following two lines !!! ###
###############################################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include(SourceCode.cmake)
##################################################
add_executable(asfem ${inc} ${src})
# target_link_libraries(asfem ${MPI_LIB} ${PETSC_LIB} ${METIS_LIB} ${GKLIB})
target_link_libraries(asfem ${MPI_LIB} ${PETSC_LIB})
###############################################
### set LTO for asfem ###
###############################################
# LTO is Link-Time Optimization.
# This block check current compiler supports whether the IPO/LTO technology.
# added by wwj(bbsy789@126.com) on 2022.12.10
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(currentCompilerLTOsupported)
message(STATUS "IPO/LTO enabled")
set_property(TARGET asfem PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO/LTO not supported: <${error}>")
endif()
endif()
include(Test.cmake)