-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
211 lines (173 loc) · 8.09 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
cmake_minimum_required(VERSION 3.13)
PROJECT(feellgood CXX)
# settings to add -std=c++17 option, and avoid -std=gnu++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS OFF) # ON to get a .json with compiler calls for all targets
# verbose might be done with make VERBOSE=1
find_package(OpenMP REQUIRED)
find_library(GMSH_LIB gmsh)
if(GMSH_LIB)
message(STATUS "Found GMSH")
else()
message(FATAL_ERROR "Could not find libgmsh")
endif()
find_path(GMSH_INC gmsh.h)
if(NOT GMSH_INC)
message(FATAL_ERROR "Could not find gmsh.h")
endif()
#===========================================================================
# cmake . -DENABLE_SEQ=OFF
# execution policy, by default it is parallel, sequential is for debug purpose.
# when ENABLE_SEQ is ON, executable does not link to TBB
#===========================================================================
option(ENABLE_SEQ "Enable sequential execution policy" OFF)
message( STATUS "Enable sequential execution policy: ENABLE_SEQ = " ${ENABLE_SEQ} )
if(NOT ${ENABLE_SEQ})
find_package(TBB QUIET)
if(TBB_FOUND)
message(STATUS "Found TBB, parallel mode is active")
set(TBB_LINK TBB::tbb)
else()
message(STATUS "TBB NOT FOUND")
message(WARNING "sequential mode is active")
set(ENABLE_SEQ TRUE)
endif()
endif()
# Use the Intel MKL library if we can find it.
# First, try find_package(), which should work on a oneAPI environment.
set(MKL_INTERFACE lp64)
set(MKL_THREADING intel_thread)
find_package(MKL QUIET)
if(MKL_FOUND)
message(STATUS "Found MKL with find_package(), MKL_CFLAGS= " ${MKL_CFLAGS})
set(MKL_TARGET "MKL::MKL")
else()
# As find_package() failed to find MKL, try pkg-config.
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
pkg_check_modules(MKL QUIET IMPORTED_TARGET mkl-dynamic-lp64-iomp)
if(MKL_FOUND)
message(STATUS "Found MKL with pkg-config, MKL_CFLAGS= " ${MKL_CFLAGS})
set(MKL_TARGET "PkgConfig::MKL")
endif()
else()
message(STATUS "Not found: PkgConfig, needed for MKL")
endif()
endif()
if(MKL_FOUND)
set(EIGEN_MKL_CFLAGS "-DEIGEN_USE_MKL_ALL -DMKL_DIRECT_CALL") # -DEIGEN_MKL_NO_DIRECT_CALL
else()
message(STATUS "Not found: MKL")
endif()
find_package(Eigen3 3.3 REQUIRED NO_MODULE)
#===========================================================================
# these parameters are used to build a config.h file
#===========================================================================
execute_process(
COMMAND git describe --tags --always --dirty
OUTPUT_VARIABLE FEELLGOOD_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE
)
# remove leading "v" from tag name
string(REGEX REPLACE "^v" "" FEELLGOOD_VERSION ${FEELLGOOD_VERSION})
message(STATUS "feeLLGood version = ${FEELLGOOD_VERSION}")
# Link-time optimization requires cmake version at least 3.9.
option(ENABLE_LTO "Enable link-time optimization" OFF)
message(STATUS "Link-time optimization: ENABLE_LTO = " ${ENABLE_LTO})
if(${ENABLE_LTO})
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fopenmp")
SET(HEADERS config.h node.h expression_parser.h mesh.h electrostatSolver.h
spinTransferTorque.h time_integration.h feellgoodSettings.h tetra.h
facette.h linear_algebra.h log-stats.h tags.h chronometer.h element.h)
SET(SOURCES feellgoodSettings.cpp time_integration.cpp solver.cpp
read.cpp save.cpp linear_algebra.cpp recentering.cpp tetra.cpp
energy.cpp facette.cpp expression_parser.cpp chronometer.cpp
tags.cpp mesh.cpp)
configure_file(config.h.in ./config.h)
add_custom_command(
OUTPUT default-settings.o
COMMAND ld -r -b binary -z noexecstack default-settings.yml -o default-settings.o
DEPENDS default-settings.yml)
#===========================================================================
# Compiler options
#===========================================================================
# -ffast-math -msse4.2 -mfpmath=sse (on X86 -mfpmath=sse set by default) or -mavx
# -fsanitize=address leak null undefined # both compiler and linker
#===========================================================================
include_directories (${CMAKE_SOURCE_DIR} ${GMSH_INC})
ADD_EXECUTABLE(feellgood main.cpp ${HEADERS} ${SOURCES} default-settings.o)
target_compile_options( feellgood PUBLIC -Wall -Wextra -O3 -march=native ${MKL_CFLAGS} )
target_compile_definitions(feellgood PUBLIC -DNDEBUG -DTBB_SUPPRESS_DEPRECATED_MESSAGES ${EIGEN_MKL_CFLAGS} )
if (MKL_FOUND)
#option --no-as-needed for mkl, see https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html
target_link_options(feellgood PUBLIC "-Wl,--no-as-needed" )
# not sure we really need it since --no-as-needed is default value, though there might be a --as-needed before
TARGET_LINK_LIBRARIES(feellgood yaml-cpp scalfmm duktape ANN OpenMP::OpenMP_CXX ${TBB_LINK} Eigen3::Eigen ${MKL_TARGET} ${GMSH_LIB})
else()
TARGET_LINK_LIBRARIES(feellgood yaml-cpp scalfmm duktape ANN OpenMP::OpenMP_CXX ${TBB_LINK} Eigen3::Eigen ${GMSH_LIB})
endif()
#===========================================================================
# Find where to install the Python modules.
#===========================================================================
# Find the version of the Python interpreter.
# Keep only the major and minor version numbers, e.g. "3.10".
execute_process(COMMAND python3 --version OUTPUT_VARIABLE PYTHON_VERSION)
string(
REGEX REPLACE "Python ([0-9]+\\.[0-9]+)\\..*" "\\1"
PYTHON_VERSION "${PYTHON_VERSION}"
)
# Possible install locations. The fisrt one (dist-packages) is used by the
# system Python on Debian and Debian-like systems. This is our preferred
# install location, and it will be used if it exists. The second one should
# work with any non-Debianized Python interpreter.
set(PY_DIST_DIR "lib/python${PYTHON_VERSION}/dist-packages")
set(PY_SITE_DIR "lib/python${PYTHON_VERSION}/site-packages")
# Select the best available installation directory.
if(EXISTS "${CMAKE_INSTALL_PREFIX}/${PY_DIST_DIR}")
set(PY_MODULES_DIR "${PY_DIST_DIR}/feellgood")
elseif(PYTHON_VERSION)
set(PY_MODULES_DIR "${PY_SITE_DIR}/feellgood")
endif()
# Install the python modules if we found a suitable location.
if(DEFINED PY_MODULES_DIR)
install(DIRECTORY python-modules/ DESTINATION ${PY_MODULES_DIR})
message(STATUS "Python modules will be installed in ${CMAKE_INSTALL_PREFIX}/${PY_MODULES_DIR}")
else()
message(WARNING "Python modules will not be installed.")
endif()
#===========================================================================
install(TARGETS feellgood RUNTIME DESTINATION bin)
install(PROGRAMS ./tools/convert2vtk DESTINATION bin)
install(PROGRAMS ./tools/convert2hdf5 DESTINATION bin)
install(PROGRAMS ./tools/h5extract DESTINATION bin)
install(PROGRAMS ./tools/fg-merge-sol DESTINATION bin)
#===========================================================================
# unit tests, by default it is not built.
# you have to switch it ON while cmaking to build the unit tests and to be able to call 'make test' afterward:
# cmake . -DENABLE_UTESTS=ON
# NB: ENABLE_UTESTS value is written in CMakeCache.txt
#===========================================================================
option(ENABLE_UTESTS "Enable tests" OFF)
message( STATUS "enable unit tests: ENABLE_UTESTS = " ${ENABLE_UTESTS} )
#===========================================================================
# cmake . -DENABLE_DET_UTESTS=ON
# this option forces random numbers to be deterministic
#===========================================================================
option(ENABLE_DET_UTESTS "Enable deterministic unit tests" OFF)
message( STATUS "enable deterministic unit tests: ENABLE_DET_UTESTS = " ${ENABLE_DET_UTESTS} )
if(${ENABLE_DET_UTESTS})
set(DET_UTESTS true )
else()
set(DET_UTESTS false )
endif()
if(${ENABLE_UTESTS})
configure_file(./unit-tests/ut_config.h.in ./unit-tests/ut_config.h)
include(CTest)
add_subdirectory(unit-tests)
endif()