forked from key4hep/k4geo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
186 lines (146 loc) · 6.43 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
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
#---------------------------
set( PackageName k4geo )
#---------------------------
project(${PackageName})
# project version
SET( ${PackageName}_VERSION_MAJOR 0 )
SET( ${PackageName}_VERSION_MINOR 20 )
SET( ${PackageName}_VERSION_PATCH 0 )
SET( ${PackageName}_VERSION "${${PackageName}_VERSION_MAJOR}.${${PackageName}_VERSION_MINOR}" )
SET( ${PackageName}_SOVERSION "${${PackageName}_VERSION_MAJOR}.${${PackageName}_VERSION_MINOR}" )
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake )
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
include(GNUInstallDirs)
set(CMAKE_INSTALL_LIBDIR lib)
set(CMAKE_INSTALL_CMAKEDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
#------------- set the default installation directory to be the source directory
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET( CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR} CACHE PATH
"install prefix path - overwrite with -D CMAKE_INSTALL_PREFIX = ..."
FORCE )
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX is ${CMAKE_INSTALL_PREFIX} - overwrite with -D CMAKE_INSTALL_PREFIX" )
ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
#---Options-------------------------------------------------------------------------
option(BUILD_TESTING "Enable and build tests" ON)
option(INSTALL_COMPACT_FILES "Copy compact files to install area" OFF)
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
find_package(DD4hep REQUIRED COMPONENTS DDRec DDG4 DDParsers)
# dd4hep_set_compiler_flags() expects DD4hep_SET_RPATH to be set to ON
# otherwise it will not set the rpath when installing
set(DD4HEP_SET_RPATH ON)
dd4hep_set_compiler_flags()
find_package ( ROOT REQUIRED COMPONENTS Geom GenVector)
message ( STATUS "ROOT_VERSION: ${ROOT_VERSION}" )
find_package( Geant4 REQUIRED )
OPTION(K4GEO_USE_LCIO "Enable or disable the use of LCIO, which is needed for some detector constructors and plugins" ON)
if(K4GEO_USE_LCIO)
find_package(LCIO REQUIRED)
# Shim for older LCIO versions
if(NOT TARGET LCIO::lcio)
add_library(LCIO::lcio INTERFACE IMPORTED GLOBAL)
set_target_properties(LCIO::lcio
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LCIO_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${LCIO_LIBRARIES}"
)
endif()
endif()
file(GLOB sources
./detector/tracker/*.cpp
./detector/calorimeter/*.cpp
./detector/fcal/*.cpp
./detector/muonSystem/*.cpp
./detector/other/*.cpp
./detector/CaloTB/*.cpp
./FCalTB/setup/*.cpp
./plugins/LinearSortingPolicy.cpp
./detector/PID/ARC_geo_o1_v01.cpp
)
if(NOT K4GEO_USE_LCIO)
set(lcio_sources # in ./detector/tracker
TrackerEndcap_o2_v05_geo.cpp
SiTrackerEndcap_o2_v02ext_geo.cpp
TrackerBarrel_o1_v03_geo.cpp
TrackerBarrel_o1_v04_geo.cpp
TrackerBarrel_o1_v05_geo.cpp
TrackerEndcap_o1_v05_geo.cpp
TrackerEndcap_o2_v06_geo.cpp
VertexBarrel_detailed_o1_v01_geo.cpp
VertexEndcap_o1_v05_geo.cpp
ZPlanarTracker_geo.cpp
)
foreach(lcio_source ${lcio_sources})
list(FILTER sources EXCLUDE REGEX "${lcio_source}")
endforeach()
message(STATUS "Use of LCIO is DISABLED, some detectors that depend on LCIO will not be built: ${lcio_sources}")
endif()
include(CheckIncludeFileCXX)
set(CMAKE_REQUIRED_LIBRARIES DD4hep::DDRec)
CHECK_INCLUDE_FILE_CXX(DDRec/DCH_info.h DCH_INFO_H_EXIST)
set(CMAKE_REQUIRED_LIBRARIES)
set(FILES_DEPENDINGON_DCH_INFO_H "DriftChamber_o1_v02.cpp" )
if(NOT DCH_INFO_H_EXIST)
list(FILTER sources EXCLUDE REGEX "${FILES_DEPENDINGON_DCH_INFO_H}")
message(WARNING "Subdetector ${FILES_DEPENDINGON_DCH_INFO_H} will not be built because header file DDRec/DCH_info.h was not found")
endif()
file(GLOB G4sources
./plugins/TPCSDAction.cpp
./plugins/CaloPreShowerSDAction.cpp
)
if(DD4HEP_USE_PYROOT)
ROOT_GENERATE_DICTIONARY(G__ILDEx ${headers} LINKDEF include/ROOT/LinkDef.h)
list(APPEND sources G__ILDEx.cxx)
endif()
add_dd4hep_plugin(${PackageName} SHARED ${sources})
add_dd4hep_plugin(${PackageName}G4 SHARED ${G4sources})
add_library(lcgeo ALIAS k4geo)
target_include_directories(${PackageName} PRIVATE ${PROJECT_SOURCE_DIR}/detector/include )
target_include_directories(${PackageName}G4 PRIVATE ${PROJECT_SOURCE_DIR}/detector/include )
target_link_libraries(${PackageName} DD4hep::DDCore DD4hep::DDRec DD4hep::DDParsers ROOT::Core detectorSegmentations)
target_link_libraries(${PackageName}G4 DD4hep::DDCore DD4hep::DDRec DD4hep::DDParsers DD4hep::DDG4 ROOT::Core ${Geant4_LIBRARIES})
if(K4GEO_USE_LCIO)
target_link_libraries(${PackageName} LCIO::lcio)
target_link_libraries(${PackageName}G4 LCIO::lcio)
endif()
#Create this_package.sh file, and install
dd4hep_instantiate_package(${PackageName})
add_subdirectory(detectorSegmentations)
add_subdirectory(detectorCommon)
# Destination directories are hardcoded because GNUdirectories are not included
install(TARGETS ${PackageName} ${PackageName}G4
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT shlib
)
#---Testing-------------------------------------------------------------------------
if(BUILD_TESTING)
include(CTest)
add_subdirectory(lcgeoTests)
set(BUILDNAME "${CMAKE_SYSTEM}-${CMAKE_CXX_COMPILER}-${CMAKE_BUILD_TYPE}" CACHE STRING "set build string for cdash")
endif(BUILD_TESTING)
#--- install remaining targets--------------------------
FILE(GLOB hfiles "ILD/include/*.h")
INSTALL(FILES ${hfiles}
DESTINATION include/${PackageName}
)
#--- install compact files------------------------------
if(INSTALL_COMPACT_FILES)
INSTALL(DIRECTORY CaloTB CLIC FCalTB FCCee ILD fieldmaps SiD DESTINATION share/k4geo )
endif()
# create k4geoConfig and friends
INSTALL(EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
FILE k4geoConfig-targets.cmake)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/k4geoConfig.cmake.in ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/k4geoConfig.cmake
PATH_VARS CMAKE_INSTALL_CMAKEDIR
INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKEDIR} )
write_basic_package_version_file(
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/k4geoConfigVersion.cmake
VERSION ${${PackageName}_VERSION}
COMPATIBILITY SameMajorVersion )
install(FILES ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/k4geoConfig.cmake
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/k4geoConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_CMAKEDIR} )