-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
350 lines (317 loc) · 12.5 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Build Garfield++ library and examples
# Authors: Klaus Zenker, Pere Mato, Stefano Caiazza
# Version 3.9 is required by the ROOT Use file
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
# although this builds all binary dependent on it, this will not
# work with root cling interpreter, and not prefered.
# set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Setting a default build type to be release with debug information.
# Otherwise the default mode is debug.
set(default_build_type "Release")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE
"${default_build_type}"
CACHE STRING "Choose the type of build.")
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel"
"RelWithDebInfo")
endif()
# do not require a fortran at top-level project, so this can build with visual studio + gfortran
project(
Garfield
LANGUAGES CXX #Fortran
VERSION 0.3.0)
include(CheckLanguage)
message(CHECK_START "Checking for fortran compiler")
check_language(Fortran)
# this branching logic references CMakeAddFortranSubdirectory.cmake, logic stayed the same since first release with it
# (2.8.8) up to current latest 3.24
if(NOT CMAKE_Fortran_COMPILER)
if(MSVC)
set(GARFIELD_USE_SUBPROJ_MINGW ON)
message(STATUS "Msvc without fotran compiler in build system, will try with mingw-gfortran later.")
message(STATUS "Use MINGW_GFORTRAN variable to specify the compiler")
message(STATUS "Generated project will be used as external project, and will not by default regenerated when Garfield Regenerates.")
else()
# CHECK_FAIL requires cmake 3.17
#message(CHECK_FAIL "missing fortran compiler")
message(STATUS "missing fortran compiler")
message(FATAL_ERROR "Cannot compile magboltz without fortran compiler")
endif()
else()
set(GARFIELD_USE_SUBPROJ_MINGW OFF)
enable_language(Fortran)
# CHECK_FAIL requires cmake 3.17
#message(CHECK_PASS "Found fortran compiler: ${CMAKE_Fortran_COMPILER}")
message(STATUS "Found fortran compiler: ${CMAKE_Fortran_COMPILER}")
endif()
#--- Set default installation prefix ------------------------------------------
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(DEFINED ENV{GARFIELD_INSTALL} )
set(CMAKE_INSTALL_PREFIX
$ENV{GARFIELD_INSTALL}
CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
elseif(DEFINED ENV{GARFIELD_HOME} )
set(CMAKE_INSTALL_PREFIX
$ENV{GARFIELD_HOME}/install
CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
else()
set(CMAKE_INSTALL_PREFIX
${PROJECT_SOURCE_DIR}/install
CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
endif()
else()
message(
STATUS "The installation folder is set to its default value ${CMAKE_INSTALL_PREFIX}")
endif()
message(STATUS "Install path: ${CMAKE_INSTALL_PREFIX}")
message(
STATUS
"If you want to change this path call cmake -DCMAKE_INSTALL_PREFIX=my_install_path ..."
)
# Adding the CMake folder to the search path for modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake)
#--- Use GNU-style hierarchy for installing build products --------------------
include(GNUInstallDirs)
include(BuildUtils)
# force_color_output()
#--- Dependencies -------------------------------------------------------------
if(DEFINED ENV{ROOTSYS})
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
elseif(DEFINED ROOTSYS)
list(APPEND CMAKE_PREFIX_PATH ${ROOTSYS})
elseif(DEFINED ROOT_CMAKE_DIR)
list(APPEND CMAKE_PREFIX_PATH ${ROOT_CMAKE_DIR})
# else()
# message(
# STATUS
# "Please consider to set ROOTSYS or use -DROOTSYS=..."
# "If still there is a problem, point to the directory which includes FindROOT.cmake using -DROOT_CMAKE_DIR=..."
# )
endif(DEFINED ENV{ROOTSYS})
find_package(ROOT 6.0 REQUIRED COMPONENTS Geom Gdml)
#--- Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY) --
if(${ROOT_VERSION} VERSION_LESS "6.20.0")
# It only makes sense for ROOT < 6.20.
# Afterwards it is loaded automatically by the find_package
get_filename_component(Root_Use_File_Dir ${ROOT_USE_FILE} DIRECTORY)
include("${Root_Use_File_Dir}/modules/RootNewMacros.cmake")
endif()
find_package(GSL REQUIRED)
find_package(OpenMP)
#--- Add Magboltz -------------------------------------------------------------
include(CMakeAddFortranSubdirectory)
cmake_add_fortran_subdirectory(
Magboltz
# cmake will fallback and create a new mingw project
# using these parameters on msvc instead of normal subdir behavior
PROJECT "Magboltz_mingw"
# need to propagate this variable to subproj, so the "if(x) proj" could work
CMAKE_COMMAND_LINE = -DGARFIELD_USE_SUBPROJ_MINGW=${GARFIELD_USE_SUBPROJ_MINGW}
ARCHIVE_DIR "Magboltz"
RUNTIME_DIR "Magboltz"
LIBRARIES "magboltz"
LINK_LIBRARIES "magboltz"
NO_EXTERNAL_INSTALL
)
add_library(Garfield::magboltz ALIAS magboltz)
# Creating the main Garfield library
add_library(Garfield SHARED "")
add_library(Garfield::Garfield ALIAS Garfield)
target_sources(
Garfield
PRIVATE Source/AvalancheGrid.cc
Source/AvalancheMC.cc
Source/AvalancheMicroscopic.cc
Source/Component.cc
Source/ComponentAnalyticField.cc
Source/ComponentAnsys121.cc
Source/ComponentAnsys123.cc
Source/ComponentCST.cc
Source/ComponentComsol.cc
Source/ComponentConstant.cc
Source/ComponentElmer.cc
Source/ComponentElmer2d.cc
Source/ComponentFieldMap.cc
Source/ComponentGrid.cc
Source/ComponentNeBem2d.cc
Source/ComponentNeBem3d.cc
Source/ComponentNeBem3dMap.cc
Source/ComponentParallelPlate.cc
Source/ComponentTcad2d.cc
Source/ComponentTcad3d.cc
Source/ComponentTcadBase.cc
Source/ComponentUser.cc
Source/ComponentVoxel.cc
Source/DriftLineRKF.cc
Source/GeometryRoot.cc
Source/GeometrySimple.cc
Source/KDTree.cc
Source/Medium.cc
Source/MediumCdTe.cc
Source/MediumDiamond.cc
Source/MediumGaAs.cc
Source/MediumGaN.cc
Source/MediumGas.cc
Source/MediumMagboltz.cc
Source/MediumSilicon.cc
Source/NeBemInterface.cpp
Source/Numerics.cc
Source/OpticalData.cc
Source/PlottingEngine.cc
Source/Polygon.cc
Source/QuadTree.cc
Source/Random.cc
Source/RandomEngineRoot.cc
Source/Sensor.cc
Source/Shaper.cc
Source/Solid.cc
Source/SolidBox.cc
Source/SolidExtrusion.cc
Source/SolidHole.cc
Source/SolidRidge.cc
Source/SolidSphere.cc
Source/SolidTube.cc
Source/SolidWire.cc
Source/TetrahedralTree.cc
Source/TGeoTet.cc
Source/Track.cc
Source/TrackBichsel.cc
Source/TrackElectron.cc
Source/TrackHeed.cc
Source/TrackPAI.cc
Source/TrackSimple.cc
Source/TrackSrim.cc
Source/TrackTrim.cc
Source/ViewBase.cc
Source/ViewCell.cc
Source/ViewDrift.cc
Source/ViewFEMesh.cc
Source/ViewField.cc
Source/ViewGeometry.cc
Source/ViewIsochrons.cc
Source/ViewMedium.cc
Source/ViewSignal.cc)
#--- Create ROOT dictionary ---------------------------------------------------
if(ROOT_VERSION VERSION_LESS 6.17)
file(
GLOB garfield_header
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/Include
Include/Garfield/*.hh)
root_generate_dictionary(
GarfieldDict
${garfield_header}
LINKDEF
Include/Garfield/LinkDef.h
OPTIONS
-I${CMAKE_CURRENT_SOURCE_DIR}/Include
-I${PROJECT_SOURCE_DIR}/Heed)
else()
file(
GLOB garfield_header
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/Include
Include/Garfield/*.hh)
include_directories(Include Heed)
root_generate_dictionary(GarfieldDict ${garfield_header} LINKDEF
Include/Garfield/LinkDef.h)
endif()
target_sources(Garfield PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/GarfieldDict.cxx)
#--- Install pcm file in case of ROOT 6 ---------------------------------------
if(ROOT_VERSION VERSION_GREATER 6.06)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/libGarfieldDict_rdict.pcm
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT dict)
endif()
garfield_set_all_default_properties(Garfield)
#--- Set the C++ standard (depending on the ROOT version) ---------------------
if(NOT DEFINED CMAKE_CXX_STANDARD)
if(${ROOT_CXX_FLAGS} MATCHES ".*-std=c\\+\\+([0-9][0-9])")
set_property(TARGET Garfield PROPERTY CXX_STANDARD ${CMAKE_MATCH_1})
elseif(${ROOT_CXX_FLAGS} MATCHES ".*-std=c\\+\\+1z")
set_property(TARGET Garfield PROPERTY CXX_STANDARD 17)
endif()
endif()
set_property(TARGET Garfield PROPERTY CMAKE_CXX_STANDARD_REQUIRED ON)
set_property(TARGET Garfield PROPERTY CXX_EXTENSIONS OFF)
#--- If you cannot create symbolic links turn FALSE the library version -------
option(BUILD_WITH_VERSION_NUMBER
"If you cannot create symbolic links turn FALSE the library version" TRUE)
if(BUILD_WITH_VERSION_NUMBER)
set_target_properties(Garfield PROPERTIES SOVERSION ${Garfield_VERSION})
endif()
mark_as_advanced(BUILD_WITH_VERSION_NUMBER)
#--- Add neBEM ----------------------------------------------------------------
# TODO Decouple Nebem interface from the Garfield components
# The Nebem interface is somewhat coupled with Garfield itself.
# We should decouple them to keep them independent, but until then
# they have to be compiled in the same library to make it work
# Creating the target as a shared library
message(STATUS "Creating a new library named ${libname} with API version ${lib_apiver}")
set(nebem_sources
NeBem/ComputeProperties.c
NeBem/Isles.c
NeBem/luc.c
NeBem/neBEM.c
NeBem/neBEMInterface.c
NeBem/nrutil.c
NeBem/ReTriM.c
NeBem/svdcmp.c
NeBem/Vector.c)
# Until CMake 3.18 the source file properties are only visible to targets
# added in the same directory therefore we cannot add Nebem through the
# add_subdirectory mechanism unless we change the cpp file extension so that
# CMake can recognize them automatically as CXX and not C
set_source_files_properties(${nebem_sources} PROPERTIES LANGUAGE CXX)
target_sources( Garfield PRIVATE ${nebem_sources})
target_compile_definitions(Garfield PRIVATE BUILDING_GARFIELD=1)
if(MSVC)
# disable warning 4251, and manually export medium and component classes.
# this warning is for stl members not being exported, and will require exact
# same cxx standard and runtime (and possibly template headers) as root already requires.
target_compile_options(Garfield PRIVATE /wd4251)
target_compile_definitions(Garfield PRIVATE _USE_MATH_DEFINES=1 _CRT_SECURE_NO_DEPRECATE=1)
endif()
#--- Add Heed sources ---------------------------------------------------------
add_subdirectory(Heed)
target_link_libraries(Garfield PUBLIC ROOT::Geom ROOT::Gdml ROOT::Graf3d GSL::gsl
Garfield::magboltz)
if(OpenMP_CXX_FOUND)
target_link_libraries(Garfield PRIVATE OpenMP::OpenMP_CXX)
endif()
target_include_directories(
Garfield
PUBLIC $<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Heed>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/NeBem>)
#--- Install the header files -------------------------------------------------
install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
REGEX LinkDef EXCLUDE)
install(
TARGETS Garfield
EXPORT "${PROJECT_NAME}Targets"
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Data
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/Garfield/)
#--- Target for Doxygen documentation -----------------------------------------
option(WITH_DOC "Whether or not to create doxygen doc target." OFF)
if(WITH_DOC)
add_subdirectory(Doc)
endif()
#--- Build the examples -------------------------------------------------------
option(WITH_EXAMPLES "Build Garfield++ examples" ON)
if(WITH_EXAMPLES)
message(
STATUS
"Garfield++ examples will be built. In order disable this option use -DWITH_EXAMPLES=OFF"
)
add_subdirectory(Examples)
else()
message(STATUS "Building of examples is switched off.")
endif()
add_subdirectory(CMake)