-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
263 lines (211 loc) · 7.07 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
cmake_minimum_required(VERSION 3.15...3.25)
include(CMakePrintHelpers)
project(
EmpiricalPseudopotential
VERSION "1.0.0"
DESCRIPTION "Empirical Pseudo Potential Code"
LANGUAGES C CXX)
add_compile_definitions(CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}")
# -----------------------------------------------------------------------------
# Set the project options.
option(ENABLE_OPEN_MP "Build programs with suppot of OpenMP." ON)
option(ENABLE_MPI_BUILD "Build some programs with MPI parralelization." ON)
option(ENABLE_CLANG_TIDY "Enable clang tidy at compilation" OFF)
option(ENABLE_BUILD_DOC "Enable the documentation build (doxygen)" OFF)
option(ENABLE_BUILD_TEST "Enable the documentation build (doxygen)" ON)
option(ENABLE_MARCH_NATIVE "Enable optimization for the local machine." ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Handling build type nicely Set a default build type if none was specified
set(default_build_type "Release")
if(EXISTS "${CMAKE_SOURCE_DIR}/.git")
set(default_build_type "RelWithDebInfo")
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(
STATUS
"Setting build type to '${default_build_type}' as none was specified.")
set(CMAKE_BUILD_TYPE
"${default_build_type}"
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
if(ENABLE_CLANG_TIDY)
message("Clang tidy at compilation is enabled")
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*)
endif()
if (ENABLE_MARCH_NATIVE)
message("Optimization for the local machine is enabled")
add_compile_options(-march=native)
endif()
# Flags for the compiler
if(MSVC)
add_compile_options("/W4" "$<$<CONFIG:RELEASE>:/O2>")
else()
# add_compile_options("-Wall" "-Wextra" "-Werror" "-pedantic")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options("-stdlib=libc++")
else()
# nothing special for gcc at the moment
endif()
endif()
# exclude Anaconda directories from search
if(DEFINED ENV{CONDA_PREFIX})
set(h5_ignore_path
$ENV{CONDA_PREFIX}/bin $ENV{CONDA_PREFIX}/lib $ENV{CONDA_PREFIX}/include
$ENV{CONDA_PREFIX}/Library/bin $ENV{CONDA_PREFIX}/Library/lib $ENV{CONDA_PREFIX}/Library/include
)
list(APPEND CMAKE_IGNORE_PATH ${h5_ignore_path})
endif()
# -----------------------------------------------------------------------------
# FIND / GET RELEVANT LIBRARIES
include(FetchContent)
# Find Eigen library Find Eigen library
FetchContent_Declare(
Eigen
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen.git"
GIT_TAG "3.4.0"
GIT_SHALLOW TRUE
GIT_PROGRESS TRUE)
# find_package(Eigen3)
# if(NOT Eigen3_FOUND)
set(EIGEN_BUILD_DOC OFF)
set(BUILD_TESTING OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)
message("Fetching Eigen3 lib ...")
# add_compile_definitions(EIGEN_USE_LAPACK=0)
FetchContent_MakeAvailable(Eigen)
find_package(Eigen3 REQUIRED)
# endif()
# Find OpenMP
if(ENABLE_OPEN_MP)
message("OpenMP optimization activated.")
find_package(OpenMP)
if(OpenMP_FOUND)
set(USE_OPENMP_ACCELERATION 1)
add_compile_definitions(USE_OPEN_MP=1)
endif()
else()
set(USE_OPENMP_ACCELERATION 0)
add_compile_definitions(USE_OPEN_MP=0)
endif(ENABLE_OPEN_MP)
# FIND GMSH Adds GMSH
find_library(GMSH_LIB gmsh HINTS $ENV{GMSH_LIB})
if(NOT GMSH_LIB)
message(FATAL_ERROR "Could not find libgmsh")
endif()
find_path(GMSH_INC gmsh.h HINTS $ENV{GMSH_INC})
if(NOT GMSH_INC)
message(FATAL_ERROR "Could not find gmsh.h")
endif()
message("---------------- GMSH.a FOUND" ${GMSH_LIB})
message("---------------- GMSH.H FOUND" ${GMSH_INC})
cmake_print_variables(GMSH_LIB)
cmake_print_variables(GMSH_INC)
if(GMSH_LIB MATCHES ".a") # FIXME - generalize this
find_library(BLAS_LIB blas)
if(BLAS_LIB)
list(APPEND EXTRA_LIBS ${BLAS_LIB})
message("BLAS FOUND : " ${BLAS_LIB})
endif()
find_library(LAPACK_LIB lapack)
if(LAPACK_LIB)
list(APPEND EXTRA_LIBS ${LAPACK_LIB})
message("LAPACK FOUND : " ${BLAS_LIB})
endif()
endif()
FetchContent_Declare(
DocTest
GIT_REPOSITORY "https://github.com/onqtam/doctest"
GIT_TAG "4d8716f1efc1d14aa736ef52ee727bd4204f4c40")
FetchContent_Declare(
yaml-cpp
GIT_REPOSITORY "https://github.com/jbeder/yaml-cpp"
GIT_TAG "master")
FetchContent_Declare(
rapidcsv
GIT_REPOSITORY "https://github.com/d99kris/rapidcsv.git"
GIT_TAG "master"
CONFIGURE_COMMAND "" BUILD_COMMAND "")
# Get fast-parse-csv lib
find_package(rapidcsv NO_MODULE)
if(NOT rapidcsv_FOUND)
message("Fetching rapidcsv lib ...")
FetchContent_MakeAvailable(rapidcsv)
include_directories(${rapidcsv_SOURCE_DIR})
endif()
# Get yaml_cpp lib
find_package(yaml-cpp NO_MODULE)
if(NOT yaml-cpp_FOUND)
message("Fetching yaml-cpp lib ...")
set(YAML_CPP_BUILD_TESTS OFF)
set(YAML_CPP_BUILD_TOOLS OFF)
set(YAML_CPP_BUILD_CONTRIB OFF)
FetchContent_MakeAvailable(yaml-cpp)
endif()
# check if Doxygen is installed
find_package(Doxygen)
if(DOXYGEN_FOUND AND ENABLE_BUILD_DOC)
# set input and output files
set(DOXYGEN_IN ${PROJECT_SOURCE_DIR}/doc/Doxyfile)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
set(MAINPAGE_IN ${PROJECT_SOURCE_DIR}/doc/mainpage.md)
set(MAINPAGE_OUT ${CMAKE_CURRENT_BINARY_DIR}/mainpage.md)
# request to configure the file
configure_file(${MAINPAGE_IN} ${MAINPAGE_OUT} @ONLY)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
message("Doxygen build started")
# note the option ALL which allows to build the docs together with the
# application
add_custom_target(
doc_doxygen ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
else(DOXYGEN_FOUND)
message("Doxygen need to be installed to generate the doxygen documentation")
endif()
# Get yaml_cpp lib
find_package(yaml-cpp NO_MODULE)
if(NOT yaml-cpp_FOUND)
message("Fetching yaml-cpp lib ...")
FetchContent_MakeAvailable(yaml-cpp)
endif()
FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
GIT_TAG master)
FetchContent_MakeAvailable(fmt)
# MPI SUPPORT
if(ENABLE_MPI_BUILD)
message("MPI support activated.")
find_package(MPI)
if(MPI_FOUND)
set(USE_MPI_ACCELERATION 1)
add_compile_definitions(USE_MPI=1)
add_definitions(-DOMPI_SKIP_MPICXX)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
message("MPI ACCELERATION ENABLED.")
endif()
else()
set(USE_MPI_ACCELERATION 0)
add_compile_definitions(USE_MPI=0)
message("MPI support deactivated. Not found.")
endif(ENABLE_MPI_BUILD)
# The tests are here
if(ENABLE_BUILD_TEST)
message("Fetching DocTest lib ...")
FetchContent_MakeAvailable(DocTest)
add_subdirectory(tests/)
endif(ENABLE_BUILD_TEST)
# tclap library for argument parsing
include_directories(${PROJECT_SOURCE_DIR}/external/tclap-1.4.0/include)
# -----------------------------------------------------------------------------
# The compiled library code is here
add_subdirectory(src/EPP)
add_subdirectory(src/BZ_MESH)
add_subdirectory(apps/)