-
Notifications
You must be signed in to change notification settings - Fork 21
/
CMakeLists.txt
294 lines (256 loc) · 11 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
## Do NOT edit this file unless you really know what you are doing
cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0076 NEW)
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_COLOR_MAKEFILE ON)
## Set project name
project(ga-aem VERSION 2.0 DESCRIPTION "Airborne electromagnetics forward modelling and inversion" LANGUAGES CXX C)
message(STATUS "Configuring ga-aem")
include(cmake/Message-Functions.cmake)
include(cmake/Check-Functions.cmake)
# Set options
option(WITH_FFTW "Build with FFTW support" ON)
option(WITH_MPI "Build with MPI support" ON)
option(WITH_NETCDF "Build with NetCDF support" ON)
option(WITH_GDAL "Build with GDAL support" ON)
option(WITH_PETSC "Build with PETSC support" ON)
reportvar(WITH_FFTW)
reportvar(WITH_MPI)
reportvar(WITH_NETCDF)
reportvar(WITH_GDAL)
reportvar(WITH_PETSC)
reportvar(CMAKE_VERSION)
reportvar(CMAKE_SYSTEM_NAME)
reportvar(CMAKE_BUILD_TYPE)
set(CMAKE_EXECUTABLE_SUFFIX_C ".exe")
set(CMAKE_EXECUTABLE_SUFFIX_CXX ".exe")
# Include the project level options and flags
include(cmake/Typical-Compiler-Options.cmake)
# Find Configure the external packages
#This is where the NetCDF C++ src code is located if it is not installed and has to be built from source
set(NETCDFCXX_SRC_DIR submodules/netcdf-cxx4/cxx4)
include(cmake/Configure-External-Packages.cmake)
#######################################
### Add the build targets
# Add the project include directories, which don't have their own CMakelists.txt
include_directories(src/)
include_directories(submodules/eigen)
# Add the cpp-utils submodule
add_subdirectory(submodules/cpp-utils EXCLUDE_FROM_ALL)
# Add the geophysics-netcdf submodule
if(${WITH_NETCDF})
add_subdirectory(submodules/geophysics-netcdf EXCLUDE_FROM_ALL)
endif()
# Add the TICPP library submodule
add_subdirectory(submodules/ticpp EXCLUDE_FROM_ALL)
# Add the gatdaem1d static library
set(target gatdaem1d-static)
add_library(${target} STATIC EXCLUDE_FROM_ALL src/gatdaem1d.cpp)
set_target_properties(${target} PROPERTIES OUTPUT_NAME gatdaem1d-static)
set_target_properties(${target} PROPERTIES PREFIX "")
set_target_properties(${target} PROPERTIES PUBLIC_HEADER src/gatdaem1d.h)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
install(TARGETS ${target} OPTIONAL PUBLIC_HEADER DESTINATION include OPTIONAL)
# Platform differences for Matlab and Python targets
if(WIN32)
set(matlab_suffix ".mexw64")
set(artefact_type "RUNTIME")
else()
set(matlab_suffix ".so")
set(artefact_type "LIBRARY")
endif()
# Add the gatdaem1d shared library
set(target gatdaem1d-shared)
add_library(${target} SHARED EXCLUDE_FROM_ALL src/gatdaem1d.cpp)
set_target_properties(${target} PROPERTIES OUTPUT_NAME gatdaem1d)
set_target_properties(${target} PROPERTIES PREFIX "")
set_target_properties(${target} PROPERTIES PUBLIC_HEADER src/gatdaem1d.h)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
install(TARGETS ${target} ${artefact_type} OPTIONAL PUBLIC_HEADER DESTINATION include OPTIONAL)
# Python bindings target - same as gatdaem1d-shared but different location
set(target python-bindings)
add_library(${target} SHARED src/gatdaem1d.cpp)
set_target_properties(${target} PROPERTIES OUTPUT_NAME gatdaem1d)
set_target_properties(${target} PROPERTIES PREFIX "")
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
install(TARGETS ${target} ${artefact_type} DESTINATION python/gatdaem1d OPTIONAL)
# Matlab bindings target - same as gatdaem1d-shared but different suffix and location
set(target matlab-bindings)
add_library(${target} SHARED src/gatdaem1d.cpp)
set_target_properties(${target} PROPERTIES OUTPUT_NAME gatdaem1d)
set_target_properties(${target} PROPERTIES PREFIX "")
set_target_properties(${target} PROPERTIES SUFFIX ${matlab_suffix})
set_target_properties(${target} PROPERTIES PUBLIC_HEADER src/gatdaem1d.h)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
install(TARGETS ${target} ${artefact_type} DESTINATION matlab/bin OPTIONAL PUBLIC_HEADER DESTINATION matlab/gatdaem1d_functions OPTIONAL)
# Add gaforwardmodeltdem executable
set(target gaforwardmodeltdem)
add_executable(${target} src/gaforwardmodeltdem.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Add example_forward_model executable
set(target example_forward_model)
add_executable(${target} src/example_forward_model.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
# There is no need to install this example as its just for developers
#install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Add the pure C example executable
set(target example_forward_model_c)
add_executable(${target} src/example_forward_model_c.c)
target_link_libraries(${target} PRIVATE gatdaem1d-static)
target_link_libraries(${target} PRIVATE cpp-utils)
# There is no need to install this example as its just for developers
#install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Add galeisbstdem executable
set(target galeisbstdem)
add_executable(${target} src/galeisbstdem.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
if(${WITH_MPI})
target_compile_definitions(${target} PRIVATE ENABLE_MPI OMPI_SKIP_MPICXX)
endif()
if(${WITH_NETCDF})
target_compile_definitions(${target} PRIVATE HAVE_NETCDF)
target_link_libraries(${target} PUBLIC geophysics-netcdf)
endif()
if(OpenMP_CXX_FOUND)
target_link_libraries(${target} PRIVATE OpenMP::OpenMP_CXX)
endif()
install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Add galeisbstdem-nompi executable
# This is simply an executable without any MPI functionality or dependency designed for use by people who are not allowed to have MPI installed on their systems
set(target galeisbstdem-nompi)
add_executable(${target} src/galeisbstdem.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
if(${WITH_NETCDF})
target_compile_definitions(${target} PRIVATE HAVE_NETCDF)
target_link_libraries(${target} PUBLIC geophysics-netcdf)
endif()
if(OpenMP_CXX_FOUND)
target_link_libraries(${target} PRIVATE OpenMP::OpenMP_CXX)
endif()
install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Add garjmcmctdem executable
set(target garjmcmctdem)
if(${WITH_NETCDF})
add_executable(${target} src/garjmcmctdem.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
target_compile_definitions(${target} PRIVATE HAVE_NETCDF)
target_link_libraries(${target} PUBLIC geophysics-netcdf)
if(${WITH_MPI})
target_compile_definitions(${target} PRIVATE ENABLE_MPI OMPI_SKIP_MPICXX)
endif()
install(TARGETS ${target} DESTINATION bin OPTIONAL)
else()
message(WARNING "${target} requires NETCDF - will not be built")
endif()
# Add galeiallatonce executable
set(target galeiallatonce)
if(MPI_C_FOUND AND PETSC_FOUND)
add_executable(${target} src/galeiallatonce.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE FFTW::FFTW)
target_compile_definitions(${target} PRIVATE ENABLE_MPI OMPI_SKIP_MPICXX)
target_link_libraries(${target} PRIVATE PETSC::PETSC)
install(TARGETS ${target} DESTINATION bin OPTIONAL)
else()
message(WARNING "${target} requires PETSc and MPI -- will not be built")
endif()
# Add galeisbsfdem executable
### This frequency-domain inversion code is currently out of action
### set(target galeisbsfdem)
### add_executable(${target} src/galeisbsfdem.cpp)
### target_link_libraries(${target} PRIVATE cpp-utils)
### if(${WITH_MPI})
### target_compile_definitions(${target} PRIVATE ENABLE_MPI OMPI_SKIP_MPICXX)
### endif()
### if(OpenMP_CXX_FOUND)
### target_link_libraries(${target} PRIVATE OpenMP::OpenMP_CXX)
### endif()
### install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Add ctlinedata2sgrid executable
set(target ctlinedata2sgrid)
add_executable(${target} src/ctlinedata2sgrid.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE ticpp::ticpp)
install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Add ctlinedata2slicegrids executable
set(target ctlinedata2slicegrids)
if(${WITH_GDAL} AND GDAL_FOUND)
add_executable(${target} src/ctlinedata2slicegrids.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
install(TARGETS ${target} DESTINATION bin OPTIONAL)
else()
message(WARNING "${target} requires GDAL - will not be built")
endif()
# Add ctlinedata2georefimage executable
set(target ctlinedata2georefimage)
if (MSVC)
# Only on Windows with MSVC
add_executable(${target} src/ctlinedata2georefimage.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
install(TARGETS ${target} DESTINATION bin OPTIONAL)
endif()
# Add ctlinedata2curtainimage executable
set(target ctlinedata2curtainimage)
if (MSVC)
# Only on Windows with MSVC
if(${WITH_GDAL} AND GDAL_FOUND)
add_executable(${target} src/ctlinedata2curtainimage.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
target_link_libraries(${target} PRIVATE ticpp::ticpp)
install(TARGETS ${target} DESTINATION bin OPTIONAL)
else()
message(WARNING "${target} requires GDAL - will not be built")
endif()
endif()
# Add removelog10conductivityfromsgrid executable
set(target removelog10conductivityfromsgrid)
add_executable(${target} src/removelog10conductivityfromsgrid.cpp)
target_link_libraries(${target} PRIVATE cpp-utils)
install(TARGETS ${target} DESTINATION bin OPTIONAL)
# Install the documentation
install(DIRECTORY docs/ DESTINATION docs MESSAGE_NEVER)
# Install the examples
install(DIRECTORY examples/ DESTINATION examples
MESSAGE_NEVER
PATTERN "*.sh" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
# Install the python library and examples and code, excluding rubbish from the development environment
install(DIRECTORY python/ DESTINATION python
MESSAGE_NEVER
PATTERN "*.ilk" EXCLUDE
PATTERN "*.pdb" EXCLUDE
PATTERN "*.ipdb" EXCLUDE
PATTERN "*.iobj" EXCLUDE
PATTERN "*.dll" EXCLUDE
PATTERN "__pycache__" EXCLUDE
PATTERN "*.sh" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
# Install the matlab library and examples and functions, excluding rubbish from the development environment
install(DIRECTORY matlab/ DESTINATION matlab
MESSAGE_NEVER
PATTERN "bin" EXCLUDE)
# Install any Unix shell scripts or Windows batch files
if(UNIX)
install(DIRECTORY scripts/ DESTINATION scripts
MESSAGE_NEVER
FILES_MATCHING PATTERN "*.sh"
PATTERN "*.sh" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
else()
install(DIRECTORY scripts/ DESTINATION scripts
MESSAGE_NEVER
FILES_MATCHING PATTERN "*.bat"
PATTERN "*.bat" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ)
endif()
# Install certain root directory files
install(FILES README.md DESTINATION .)
install(FILES README-Dependencies.md DESTINATION .)
install(FILES COPYRIGHT.txt DESTINATION .)
install(FILES LICENCE.txt DESTINATION .)