-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
206 lines (183 loc) · 6.52 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
### Basic settings
cmake_minimum_required(VERSION 3.13.4)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
### Define the project
project(MEPHIT LANGUAGES C CXX Fortran)
### Specify paths
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_Fortran_MODULE_DIRECTORY ${LIBRARY_OUTPUT_PATH})
### Set compiler flags
if ("$ENV{FC}" MATCHES "ifort")
# ifort configuration
set(CMAKE_Fortran_FLAGS "-fpp -g -assume norealloc_lhs -traceback -check all -fpe-all=0")
set(WARNING_FLAGS "-warn all")
set(LEGACY_FLAGS "-check noarg_temp_created")
else ()
# gfortran configuration
set(CMAKE_Fortran_FLAGS "-O2 -march=native -cpp -g -fno-realloc-lhs -fbacktrace -fcheck=all -ffpe-trap=invalid,zero,overflow")
set(WARNING_FLAGS "-Wall -Wextra -pedantic -fmax-errors=1 -Wno-unused-label")
set(LEGACY_FLAGS "-fcheck=no-array-temps")
set(CMAKE_C_FLAGS "-O2 -g -march=native -Wconversion -Wfloat-equal -Wshadow -Wredundant-decls -Winline ${WARNING_FLAGS}")
endif ()
# Prevent linker error with hdf5tools on Ubuntu
if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--copy-dt-needed-entries")
endif()
### Define external paths
if ("${CMAKE_SYSTEM}" MATCHES "Darwin")
set(tmpdir $TMPDIR)
else ()
if ("$ENV{XDG_RUNTIME_DIR}" STREQUAL "")
set(tmpdir /tmp/runtime-$USER)
else ()
set(tmpdir $XDG_RUNTIME_DIR)
endif ()
endif ()
### Find dependencies in standard directories
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
find_package(SuiteSparse)
if(SUITESPARSE_FOUND)
set(LEGACY_SUITESPARSE ON)
message(STATUS "SuiteSparse found.")
else()
message(STATUS "SuiteSparse not found. Trying new cmake search.")
find_package(UMFPACK REQUIRED)
endif()
cmake_policy(SET CMP0074 NEW)
find_package(HDF5 COMPONENTS C Fortran HL REQUIRED)
find_package(Boost 1.74 REQUIRED)
find_package(FFTW REQUIRED)
find_package(GSL REQUIRED)
### NetCDF
find_program(NF_CONFIG "nf-config")
if (NF_CONFIG)
execute_process(COMMAND nf-config --includedir
OUTPUT_VARIABLE NETCDFINCLUDE_DIR)
execute_process(COMMAND nc-config --libdir
OUTPUT_VARIABLE NETCDFLIB_DIR)
execute_process(COMMAND nf-config --flibs
OUTPUT_VARIABLE NETCDF_FLIBS)
else()
message(SEND_ERROR "nf-config not found. Please install libnetcdff-dev")
endif()
string(STRIP ${NETCDFINCLUDE_DIR} NETCDFINCLUDE_DIR)
string(STRIP ${NETCDFLIB_DIR} NETCDFLIB_DIR)
string(STRIP ${NETCDF_FLIBS} NETCDF_FLIBS)
message(STATUS "NetCDF include path: " ${NETCDFINCLUDE_DIR})
message(STATUS "NetCDF lib path: " ${NETCDFLIB_DIR})
message(STATUS "NetCDF Fortran libs: " ${NETCDF_FLIBS})
# Replace space by semicolon in the Fortran libs
string(REPLACE " " ";" NETCDF_FLIBS ${NETCDF_FLIBS})
include_directories(${NETCDFINCLUDE_DIR})
link_directories(${NETCDFLIB_DIR})
add_link_options(${NETCDF_FLIBS})
include(ExternalProject)
include(SetupCODE)
include(SetupLIBNEO)
include(SetupTriangle)
include(SetupMFEM)
### Project source files
# SuiteSparse
set(SUITESPARSE_SRC_FILES
src/external/umf4_f77wrapper.c
src/external/umf4_f77zwrapper.c
)
if(LEGACY_SUITESPARSE)
set(SUITESPARSE_FLAGS "-I${SUITESPARSE_INCLUDE_DIRS}")
else()
set(SUITESPARSE_FLAGS "")
endif()
set_source_files_properties(src/external/umf4_f77wrapper.c PROPERTIES COMPILE_FLAGS "${SUITESPARSE_FLAGS} -DDLONG")
set_source_files_properties(src/external/umf4_f77zwrapper.c PROPERTIES COMPILE_FLAGS "${SUITESPARSE_FLAGS} -DZLONG")
set(COMMON_FORTRAN_SRC_FILES
src/external/netlib_mod.f90
src/external/d1mach.f
src/fftw3.f90
src/field_line_integration_for_SYNCH.f90
src/magdata_in_symfluxcoord.f90
src/odeint_allroutines.f
src/points_2d.f90
src/sparse_mod.f90
src/getIfunc.f90
src/progonka.f90
src/response_current.f90
src/W2_arr.f90
)
set_source_files_properties(${COMMON_FORTRAN_SRC_FILES}
PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS} ${LEGACY_FLAGS}")
set(MEPHIT_FORTRAN_SRC_FILES
src/mephit_conf.f90
src/mephit_util.f90
src/mephit_mesh.f90
src/mephit_pert.f90
src/mephit_iter.f90
)
set_source_files_properties(src/mephit_test.f90 ${MEPHIT_FORTRAN_SRC_FILES}
PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS} ${WARNING_FLAGS}")
set(MEPHIT_C_SRC_FILES
src/mephit_util.c
src/mephit_fem.c
src/hyper1F1.c
)
set(MEPHIT_CPP_SRC_FILES
src/mephit_fem.cpp
src/magnetic_differential_equation.cpp
src/miscellaneous.cpp
)
set_source_files_properties(src/mephit_run.c ${MEPHIT_C_SRC_FILES} ${MEPHIT_CPP_SRC_FILES}
PROPERTIES COMPILE_FLAGS "${CMAKE_C_FLAGS} -DREAL=double -I${TRIANGLE_INCLUDE_DIR} -I${SUITESPARSE_INCLUDE_DIRS} -L${TRIANGLE_LIB_DIR}")
### Define library
add_library(mephit SHARED
${SUITESPARSE_SRC_FILES}
${COMMON_FORTRAN_SRC_FILES}
${MEPHIT_FORTRAN_SRC_FILES}
${MEPHIT_C_SRC_FILES}
${MEPHIT_CPP_SRC_FILES}
)
add_dependencies(mephit LIBNEO MFEM TRIANGLE)
target_include_directories(mephit PUBLIC
${magfie_include_dir}
${NETCDF_INCLUDES}
${MFEM_INCLUDE_DIRS}
${NETCDF_INCLUDES}
${TRIANGLE_INCLUDE_DIR}
)
set(MEPHIT_LIBS
hdf5::hdf5
hdf5::hdf5_hl
hdf5::hdf5_fortran
hdf5::hdf5_hl_fortran
GSL::gsl
${MFEM_LIBRARIES}
BLAS::BLAS
LAPACK::LAPACK
${FFTW_LIBRARIES}
${triangle_lib}
${magfie_lib}
${neo_lib}
${hdf5_tools_lib}
)
target_link_libraries(mephit ${MEPHIT_LIBS})
if(LEGACY_SUITESPARSE)
target_link_libraries(mephit ${SUITESPARSE_LIBRARIES})
else()
target_link_libraries(mephit SuiteSparse::umfpack)
endif()
### Define executables
add_executable(mephit_run.x src/mephit_run.c)
add_executable(mephit_test.x src/mephit_test.f90)
target_link_libraries(mephit_run.x mephit)
target_link_libraries(mephit_test.x mephit)
### Add helper script to binaries
configure_file(scripts/mephit.bash ${PROJECT_BINARY_DIR}/scripts/mephit.bash @ONLY)
configure_file(scripts/ff-mephit.bash ${PROJECT_BINARY_DIR}/scripts/ff-mephit.bash COPYONLY)
configure_file(scripts/maxwell_daemon.edp ${PROJECT_BINARY_DIR}/scripts/maxwell_daemon.edp COPYONLY)
configure_file(scripts/extmesh.edp ${PROJECT_BINARY_DIR}/scripts/extmesh.edp COPYONLY)
configure_file(scripts/mephit.gdb ${PROJECT_BINARY_DIR}/scripts/mephit.gdb COPYONLY)
configure_file(data/convexwall_asdex.dat ${PROJECT_BINARY_DIR}/data/convexwall_asdex.dat COPYONLY)
configure_file(data/convexwall_kilca.dat ${PROJECT_BINARY_DIR}/data/convexwall_kilca.dat COPYONLY)
configure_file(data/convexwall_mastu.dat ${PROJECT_BINARY_DIR}/data/convexwall_mastu.dat COPYONLY)
configure_file(data/field_divB0.inp ${PROJECT_BINARY_DIR}/data/field_divB0.inp COPYONLY)
configure_file(data/preload_for_SYNCH.inp ${PROJECT_BINARY_DIR}/data/preload_for_SYNCH.inp COPYONLY)