-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
237 lines (186 loc) · 7.88 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
set(CMAKE_VERBOSE_MAKEFILE ON)
# CMake version check
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
SET(MaCh3DUNE_VERSION 1.0.0)
# Create project (todo: set configurable CUDA)
project(MaCh3DUNE VERSION ${MaCh3DUNE_VERSION} LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED True)
option(MaCh3_DUNE_USE_SRProxy "Whether to build proxy classes for Standard Record objects" OFF)
# Changes default install path to be a subdirectory of the build dir.
# Can set build dir at configure time with -DCMAKE_INSTALL_PREFIX=/install/path
if(CMAKE_INSTALL_PREFIX STREQUAL "" OR CMAKE_INSTALL_PREFIX STREQUAL
"/usr/local")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}")
elseif(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}")
endif()
# Use the compilers found in the path
find_program(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PATH)
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
message("CMAKE SOURCE_DIR IS ${CMAKE_SOURCE_DIR}")
################################################################################
# Check Dependencies
################################################################################
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
include(CPM)
CPMFindPackage(
NAME CMakeModules
GIT_TAG v0.2.3
GITHUB_REPOSITORY NuHepMC/CMakeModules
DOWNLOAD_ONLY
)
include(${CMakeModules_SOURCE_DIR}/NuHepMCModules.cmake)
include(ROOT)
if(NOT TARGET ROOT::ROOT)
cmessage(FATAL_ERROR "MaCh3 Expected dependency target: ROOT::ROOT")
endif()
if(DEFINED ROOT_CXX_STANDARD AND ROOT_CXX_STANDARD GREATER CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${ROOT_CXX_STANDARD})
endif()
############################ DUNEAnaObj ####################################
if(MaCh3_DUNE_USE_SRProxy)
find_package(duneanaobj)
if(NOT duneanaobj_FOUND)
CPMFindPackage(
NAME duneanaobj
GIT_TAG feature/Clingification_rebase2024
GITHUB_REPOSITORY luketpickering/duneanaobj
VERSION 4.0.0
)
endif()
if(NOT TARGET duneanaobj::all)
cmessage(FATAL_ERROR "MaCh3 DUNE Expected dependency target: duneanaobj::all")
endif()
else()
CPMAddPackage(
NAME duneanaobj
GIT_TAG v03_06_00
GITHUB_REPOSITORY "DUNE/duneanaobj"
DOWNLOAD_ONLY YES
)
include_directories(${duneanaobj_SOURCE_DIR})
ROOT_GENERATE_DICTIONARY(StandardRecordDict ${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/StandardRecord.h
LINKDEF ${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/classes_def.xml)
file(GLOB SR_IMPL_FILES "${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/*.cxx")
LIST(APPEND SR_IMPL_FILES ${CMAKE_CURRENT_BINARY_DIR}/StandardRecordDict.cxx)
add_library(duneanaobj_StandardRecord SHARED ${SR_IMPL_FILES})
target_link_libraries(duneanaobj_StandardRecord PUBLIC ROOT::MathCore)
target_include_directories(duneanaobj_StandardRecord PUBLIC
$<BUILD_INTERFACE:${duneanaobj_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
target_include_directories(duneanaobj_StandardRecord PRIVATE
$<BUILD_INTERFACE:${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord> #root puts this in the dictionary
)
set_target_properties(duneanaobj_StandardRecord PROPERTIES EXPORT_NAME all)
install(TARGETS duneanaobj_StandardRecord EXPORT mach3dune-targets DESTINATION lib)
file(GLOB SR_HEADER_FILES "${duneanaobj_SOURCE_DIR}/duneanaobj/StandardRecord/*.h")
install(FILES ${SR_HEADER_FILES} DESTINATION include/duneanaobj/StandardRecord)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libStandardRecordDict_rdict.pcm
${CMAKE_CURRENT_BINARY_DIR}/libStandardRecordDict.rootmap
DESTINATION lib)
add_library(duneanaobj::all ALIAS duneanaobj_StandardRecord)
endif()
################################## MaCh3 ######################################
#If MaCh3 was sourced find it, otherwise use CPM
find_package(MaCh3)
if(NOT MaCh3_FOUND)
CPMFindPackage(
NAME MaCh3
GIT_TAG "v1.2.0_alpha"
GITHUB_REPOSITORY mach3-software/MaCh3
)
else()
##KS: This ensure that all executables that are in core will be moved
FILE(GLOB MaCh3Exe $ENV{MaCh3_ROOT}/Diagnostics/*)
FILE(COPY ${MaCh3Exe} DESTINATION ${CMAKE_BINARY_DIR}/Diagnostics/)
endif()
if(NOT TARGET MaCh3::All)
cmessage(FATAL_ERROR "MaCh3 DUNE Expected dependency target: MaCh3::All, did you source setup.MaCh3.sh")
endif()
############################ C++ Compiler ####################################
if (NOT DEFINED CMAKE_CXX_STANDARD OR "${CMAKE_CXX_STANDARD} " STREQUAL " ")
SET(CMAKE_CXX_STANDARD 11)
endif()
if(DEFINED ROOT_CXX_STANDARD AND ROOT_CXX_STANDARD GREATER CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${ROOT_CXX_STANDARD})
endif()
cmessage(STATUS "CMAKE CXX Standard: ${CMAKE_CXX_STANDARD}")
################################# Features ##################################
LIST(APPEND ALL_FEATURES
)
cmessage(STATUS "MaCh3DUNE Features: ")
foreach(f ${ALL_FEATURES})
cmessage(STATUS " ${f}: ${MaCh3DUNE_${f}_ENABLED}")
endforeach()
#KS: Options to print dependency graph
if(NOT DEFINED MaCh3DUNE_DependancyGraph)
set(MaCh3DUNE_DependancyGraph FALSE)
endif()
if(MaCh3DUNE_DependancyGraph)
add_custom_target(graphviz ALL
COMMAND ${CMAKE_COMMAND} "--graphviz=foo.dot" .
COMMAND dot -Tpng foo.dot -o foo.png
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endif()
################################# Build MaCh3 ##################################
add_library(MaCh3DUNECompilerOptions INTERFACE)
set_target_properties(MaCh3DUNECompilerOptions PROPERTIES EXPORT_NAME CompilerOptions)
if(PSYCHE_FOUND)
target_compile_definitions(MaCh3DUNECompilerOptions INTERFACE PSYCHESETUP)
endif()
target_include_directories(MaCh3DUNECompilerOptions
INTERFACE
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:include>)
install(TARGETS MaCh3DUNECompilerOptions
EXPORT mach3dune-targets
LIBRARY DESTINATION lib/)
add_subdirectory(splines)
add_subdirectory(samplePDFDUNE)
add_subdirectory(src)
add_library(MaCh3DUNEAll INTERFACE)
set_target_properties(MaCh3DUNEAll PROPERTIES EXPORT_NAME All)
target_link_libraries(MaCh3DUNEAll INTERFACE splinesDUNE SamplePDFDUNE MaCh3DUNECompilerOptions)
add_library(MaCh3DUNE::All ALIAS MaCh3DUNEAll)
install(TARGETS MaCh3DUNEAll
EXPORT mach3dune-targets
LIBRARY DESTINATION lib/)
configure_file(cmake/Templates/setup.MaCh3DUNE.sh.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.MaCh3DUNE.sh" @ONLY)
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/setup.MaCh3DUNE.sh" DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/output)
############################ Install ####################################
install(DIRECTORY inputs DESTINATION ${CMAKE_BINARY_DIR})
install(DIRECTORY configs DESTINATION ${CMAKE_BINARY_DIR})
install(DIRECTORY utils DESTINATION ${CMAKE_BINARY_DIR})
set(export_destinations
${CMAKE_INSTALL_PREFIX}/lib/cmake/
${CMAKE_INSTALL_PREFIX}/
)
foreach(dest ${export_destinations})
install(EXPORT mach3dune-targets
FILE MaCh3DUNETargets.cmake
NAMESPACE MaCh3DUNE::
DESTINATION ${dest}
)
endforeach()
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/Templates/MaCh3DUNEConfig.cmake.in ${CMAKE_BINARY_DIR}/MaCh3DUNEConfig.cmake
INSTALL_DESTINATION
/this/is/ignored/for/some/reason/thanks/kitware
NO_SET_AND_CHECK_MACRO
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(${CMAKE_BINARY_DIR}/MaCh3DUNEConfigVersion.cmake
VERSION ${MaCh3DUNE_VERSION}
COMPATIBILITY AnyNewerVersion)
install(FILES
${CMAKE_BINARY_DIR}/MaCh3DUNEConfig.cmake
${CMAKE_BINARY_DIR}/MaCh3DUNEConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/MaCh3DUNE)
include(mach3dune-config)