forked from OpenGATE/Gate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindCLHEP.cmake
355 lines (319 loc) · 13.1 KB
/
FindCLHEP.cmake
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
351
352
353
354
355
# - Try to find the CLHEP High Energy Physics library and headers
# Usage of this module is as follows
#
# == Using any header-only components of CLHEP: ==
#
# find_package( CLHEP 2.3.1.0 )
# if(CLHEP_FOUND)
# include_directories(${CLHEP_INCLUDE_DIRS})
# add_executable(foo foo.cc)
# endif()
#
# == Using the binary CLHEP library ==
#
# find_package( CLHEP 2.3.1.0 )
# if(CLHEP_FOUND)
# include_directories(${CLHEP_INCLUDE_DIRS})
# add_executable(foo foo.cc)
# target_link_libraries(foo ${CLHEP_LIBRARIES})
# endif()
#
# You can provide a minimum version number that should be used.
# If you provide this version number and specify the REQUIRED attribute,
# this module will fail if it can't find a CLHEP of the specified version
# or higher. If you further specify the EXACT attribute, then this module
# will fail if it can't find a CLHEP with a version eaxctly as specified.
#
# ===========================================================================
# Variables used by this module which can be used to change the default
# behaviour, and hence need to be set before calling find_package:
#
# CLHEP_ROOT_DIR The preferred installation prefix for searching for
# CLHEP. Set this if the module has problems finding
# the proper CLHEP installation.
#
# If you don't supply CLHEP_ROOT_DIR, the module will search on the standard
# system paths. On UNIX, the module will also try to find the clhep-config
# program in the PATH, and if found will use the prefix supplied by this
# program as a HINT on where to find the CLHEP headers and libraries.
#
# You can re-run CMake with a different version of CLHEP_ROOT_DIR to
# force a new search for CLHEP using the new version of CLHEP_ROOT_DIR.
# CLHEP_ROOT_DIR is cached and so can be editted in the CMake curses
# and GUI interfaces
#
# ============================================================================
# Variables set by this module:
#
# CLHEP_FOUND System has CLHEP.
#
# CLHEP_INCLUDE_DIRS CLHEP include directories: not cached.
#
# CLHEP_LIBRARIES Link to these to use the CLHEP library: not cached.
#
# ===========================================================================
# If CLHEP is installed in a non-standard way, e.g. a non GNU-style install
# of <prefix>/{lib,include}, then this module may fail to locate the headers
# and libraries as needed. In this case, the following cached variables can
# be editted to point to the correct locations.
#
# CLHEP_INCLUDE_DIR The path to the CLHEP include directory: cached
#
# CLHEP_LIBRARY The path to the CLHEP library: cached
#
# You should not need to set these in the vast majority of cases
#
#============================================================================
# Copyright (C) 2010,2011 Ben Morgan <Ben.Morgan@warwick.ac.uk>
# Copyright (C) 2010,2011 University of Warwick
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the University of Warwick nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#============================================================================
#-----------------------------------------------------------------------
# Define library components for use if requested
#
set(CLHEP_COMPONENTS
Cast
Evaluator
Exceptions
GenericFunctions
Geometry
Matrix
Random
RandomObjects
RefCount
Vector
)
# - and their interdependencies (taken from CLHEP webpage, may not
# be totally up to date, but assumed to be complete
set(CLHEP_Geometry_REQUIRES Vector)
set(CLHEP_Matrix_REQUIRES Random Vector)
set(CLHEP_RandomObjects_REQUIRES Matrix Random Vector)
set(CLHEP_RefCount_REQUIRES Cast)
set(CLHEP_Exceptions_REQUIRES RefCount Cast)
set(CLHEP_ROOT_DIR "${CLHEP_ROOT_DIR}" CACHE PATH "prefix of system CLHEP installation")
#----------------------------------------------------------------------------
# Enable re-search if known CLHEP_ROOT_DIR changes?
#
if(NOT "${CLHEP_ROOT_DIR}" STREQUAL "${CLHEP_INTERNAL_ROOT_DIR}")
if(CLHEP_INTERNAL_ROOT_DIR AND NOT CLHEP_FIND_QUIETLY)
message(STATUS "CLHEP_ROOT_DIR Changed, Rechecking for CLHEP")
endif()
set(CLHEP_INTERNAL_ROOT_DIR ${CLHEP_ROOT_DIR}
CACHE INTERNAL "Last value supplied for where to locate CLHEP")
#set(CLHEP_INCLUDE_DIR CLHEP_INCLUDE_DIR-NOTFOUND)
#set(CLHEP_LIBRARY CLHEP_LIBRARY-NOTFOUND)
#foreach(__clhep_comp ${CLHEP_COMPONENTS})
#set(CLHEP_${__clhep_comp}_LIBRARY CLHEP_${__clhep_comp}_LIBRARY-NOTFOUND)
#endforeach()
#set(CLHEP_CONFIG_EXECUTABLE CLHEP_CONFIG_EXECUTABLE-NOTFOUND)
unset(CLHEP_INCLUDE_DIR CACHE)
unset(CLHEP_LIBRARY CACHE)
foreach(__clhep_comp ${CLHEP_COMPONENTS})
unset(CLHEP_${__clhep_comp}_LIBRARY CACHE)
endforeach()
unset(CLHEP_CONFIG_EXECUTABLE CACHE)
set(CLHEP_LIBRARIES )
set(CLHEP_INCLUDE_DIRS )
set(CLHEP_FOUND FALSE)
endif()
#----------------------------------------------------------------------------
# - If we already found CLHEP, be quiet
#
if(CLHEP_INCLUDE_DIR AND CLHEP_LIBRARY)
set(CLHEP_FIND_QUIETLY TRUE)
endif()
#----------------------------------------------------------------------------
# Set up HINTS on where to look for CLHEP
# If we're on UNIX, see if we can find clhep-config and use its --prefix
# as an extra hint.
#
set(_clhep_root_hints ${CLHEP_ROOT_DIR})
if(UNIX)
# Try and find clhep-config in the user's path, but hint at the bin
# directory under CLHEP_ROOT_DIR because we'd ideally like to pick up
# the config program that matches the libraries/headers.
# We only use it as a fallback though.
find_program(CLHEP_CONFIG_EXECUTABLE clhep-config
HINTS ${_clhep_root_hints}/bin
DOC "Path to CLHEP's clhep-config program")
mark_as_advanced(CLHEP_CONFIG_EXECUTABLE)
if(CLHEP_CONFIG_EXECUTABLE)
execute_process(COMMAND ${CLHEP_CONFIG_EXECUTABLE} --prefix
OUTPUT_VARIABLE _clhep_config_prefix
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND _clhep_root_hints ${_clhep_config_prefix})
endif()
elseif(WIN32 AND NOT UNIX)
# Do we need to set suitable defaults?
endif()
#----------------------------------------------------------------------------
# Find the CLHEP headers
# Use Units/defs.h as locator as this is pretty consistent through versions
find_path(CLHEP_INCLUDE_DIR CLHEP/Units/defs.h
HINTS ${_clhep_root_hints}
PATH_SUFFIXES include
DOC "Path to the CLHEP headers"
)
#----------------------------------------------------------------------------
# Extract the CLHEP version from defs.h
# Versions COMPATIBLE if RequestedVersion > FoundVersion
# Also check if versions exact
if(CLHEP_INCLUDE_DIR)
set(CLHEP_VERSION 0)
file(READ "${CLHEP_INCLUDE_DIR}/CLHEP/Units/defs.h" _CLHEP_DEFS_CONTENTS)
string(REGEX REPLACE ".*#define (PACKAGE|CLHEP_UNITS)+_VERSION \"([0-9.]+).*" "\\2"
CLHEP_VERSION "${_CLHEP_DEFS_CONTENTS}")
if(NOT CLHEP_FIND_QUIETLY)
message(STATUS "Found CLHEP Version ${CLHEP_VERSION}")
endif()
if(CLHEP_FIND_VERSION)
set(CLHEP_VERSIONING_TESTS CLHEP_VERSION_COMPATIBLE)
if("${CLHEP_VERSION}" VERSION_LESS "${CLHEP_FIND_VERSION}")
set(CLHEP_VERSION_COMPATIBLE FALSE)
else()
set(CLHEP_VERSION_COMPATIBLE TRUE)
if(CLHEP_FIND_VERSION_EXACT)
if("${CLHEP_VERSION}" VERSION_EQUAL "${CLHEP_FIND_VERSION}")
set(CLHEP_VERSION_EXACT TRUE)
endif()
list(APPEND CLHEP_VERSIONING_TESTS CLHEP_VERSION_EXACT)
endif()
endif()
endif()
endif()
#----------------------------------------------------------------------------
# Find the CLHEP library - AFTER version checking because CLHEP component
# libs are named including the version number
# Prefer lib64 if available.
set(__CLHEP_LIBRARY_SET)
if(CLHEP_FIND_COMPONENTS)
# Resolve dependencies of requested components
set(CLHEP_RESOLVED_FIND_COMPONENTS)
foreach(__clhep_comp ${CLHEP_FIND_COMPONENTS})
list(APPEND CLHEP_RESOLVED_FIND_COMPONENTS ${__clhep_comp} ${CLHEP_${__clhep_comp}_REQUIRES})
endforeach()
list(REMOVE_DUPLICATES CLHEP_RESOLVED_FIND_COMPONENTS)
foreach(__clhep_comp ${CLHEP_RESOLVED_FIND_COMPONENTS})
find_library(CLHEP_${__clhep_comp}_LIBRARY CLHEP-${__clhep_comp}-${CLHEP_VERSION}
HINTS ${_clhep_root_hints}
PATH_SUFFIXES lib64 lib
DOC "Path to the CLHEP ${__clhep_comp} library"
)
list(APPEND __CLHEP_LIBRARY_SET "CLHEP_${__clhep_comp}_LIBRARY")
endforeach()
else()
find_library(CLHEP_LIBRARY CLHEP
HINTS ${_clhep_root_hints}
PATH_SUFFIXES lib64 lib
DOC "Path to the CLHEP library"
)
set(__CLHEP_LIBRARY_SET "CLHEP_LIBRARY")
endif()
#----------------------------------------------------------------------------
# Construct an error message for FPHSA
#
set(CLHEP_DEFAULT_MSG "Could NOT find CLHEP:\n")
if(NOT CLHEP_INCLUDE_DIR)
set(CLHEP_DEFAULT_MSG "${CLHEP_DEFAULT_MSG}CLHEP Header Path Not Found\n")
endif()
if(NOT CLHEP_FIND_COMPONENTS AND NOT CLHEP_LIBRARY)
set(CLHEP_DEFAULT_MSG "${CLHEP_DEFAULT_MSG}CLHEP Library Not Found\n")
endif()
if(CLHEP_FIND_VERSION)
if(NOT CLHEP_VERSION_COMPATIBLE)
set(CLHEP_DEFAULT_MSG "${CLHEP_DEFAULT_MSG}Incompatible versions, ${CLHEP_VERSION}(found) < ${CLHEP_FIND_VERSION}(required)\n")
endif()
if(CLHEP_FIND_VERSION_EXACT)
if(NOT CLHEP_VERSION_EXACT)
set(CLHEP_DEFAULT_MSG "${CLHEP_DEFAULT_MSG}Non-exact versions, ${CLHEP_VERSION}(found) != ${CLHEP_FIND_VERSION}(required)\n")
endif()
endif()
endif()
#----------------------------------------------------------------------------
# Handle the QUIETLY and REQUIRED arguments, setting CLHEP_FOUND to TRUE if
# all listed variables are TRUE
#
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CLHEP
"${CLHEP_DEFAULT_MSG}"
${__CLHEP_LIBRARY_SET}
CLHEP_INCLUDE_DIR
${CLHEP_VERSIONING_TESTS}
)
#----------------------------------------------------------------------------
# If we found CLHEP, set the needed non-cache variables
#
if(CLHEP_FOUND)
set(CLHEP_LIBRARIES)
foreach(__clhep_lib ${__CLHEP_LIBRARY_SET})
list(APPEND CLHEP_LIBRARIES ${${__clhep_lib}})
endforeach()
set(CLHEP_INCLUDE_DIRS ${CLHEP_INCLUDE_DIR})
# Create imported targets
foreach(__clhep_lib ${__CLHEP_LIBRARY_SET})
# Construct imported target name
string(REPLACE "_LIBRARY" "" __clhep_imp_lib "${__clhep_lib}")
string(REPLACE "_" "::" __clhep_imp_lib "${__clhep_imp_lib}")
if(__clhep_imp_lib STREQUAL "CLHEP")
# Create both CLHEP and CLHEP::CLHEP targets
if(NOT TARGET CLHEP::CLHEP)
add_library(CLHEP::CLHEP UNKNOWN IMPORTED)
set_target_properties(CLHEP::CLHEP PROPERTIES
IMPORTED_LOCATION "${CLHEP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${CLHEP_INCLUDE_DIRS}"
)
endif()
if(NOT TARGET CLHEP)
add_library(CLHEP UNKNOWN IMPORTED)
set_target_properties(CLHEP PROPERTIES
IMPORTED_LOCATION "${CLHEP_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${CLHEP_INCLUDE_DIRS}"
)
endif()
else()
# Have a component target - these are always namespaced
# Note that at present, link interfaces aren't created...
if(NOT TARGET ${__clhep_imp_lib})
add_library(${__clhep_imp_lib} UNKNOWN IMPORTED)
set_target_properties(${__clhep_imp_lib} PROPERTIES
IMPORTED_LOCATION "${${__clhep_lib}}"
INTERFACE_INCLUDE_DIRECTORIES "${CLHEP_INCLUDE_DIRS}"
)
endif()
endif()
endforeach()
endif()
#----------------------------------------------------------------------------
# Mark cache variables that can be adjusted as advanced
#
mark_as_advanced(CLHEP_INCLUDE_DIR CLHEP_LIBRARY)
foreach(__clhep_comp ${CLHEP_COMPONENTS})
mark_as_advanced(CLHEP_${__clhep_comp}_LIBRARY)
endforeach()