forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindFastJet.cmake
More file actions
121 lines (104 loc) · 4.43 KB
/
FindFastJet.cmake
File metadata and controls
121 lines (104 loc) · 4.43 KB
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
# Copyright 2019-2020 CERN and copyright holders of ALICE O2.
# See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
# All rights not expressly granted are reserved.
#
# This software is distributed under the terms of the GNU General Public
# License v3 (GPL Version 3), copied verbatim in the file "COPYING".
#
# In applying this license CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.
# Author: Jochen Klein
#
# add FastJet::FastJet as library to targets depending on FastJet,
# place code depending on FastJet in blocks:
# if(FastJet_FOUND) ... endif() (in cmake)
# #ifdef HAVE_FASTJET ... #endif (in C++)
set(PKGNAME ${CMAKE_FIND_PACKAGE_NAME})
string(TOUPPER ${PKGNAME} PKGENVNAME)
string(TOLOWER "${PKGNAME}-config" PKGCONFIG)
find_program(${PKGNAME}_CONFIG
NAMES ${PKGCONFIG}
PATHS $ENV{${PKGENVNAME}})
mark_as_advanced(${PKGNAME}_CONFIG)
if(${PKGNAME}_CONFIG)
execute_process(COMMAND ${${PKGNAME}_CONFIG} --cxxflags
OUTPUT_VARIABLE ${PKGNAME}_CXXFLAGS
ERROR_VARIABLE error
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(${PKGNAME}_INCLUDE_DIRS)
mark_as_advanced(${PKGNAME}_INCLUDE_DIRS)
if(${PKGNAME}_CXXFLAGS)
string(REGEX MATCHALL "(^| )-I[^ ]+" incdirs ${${PKGNAME}_CXXFLAGS})
foreach(incdir ${incdirs})
string(STRIP ${incdir} incdir)
string(SUBSTRING ${incdir} 2 -1 incdir)
list(APPEND ${PKGNAME}_INCLUDE_DIRS ${incdir})
endforeach()
endif(${PKGNAME}_CXXFLAGS)
execute_process(COMMAND ${${PKGNAME}_CONFIG} --libs
OUTPUT_VARIABLE ${PKGNAME}_CONFIGLIBS
ERROR_VARIABLE error
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(${PKGNAME}_LIBS)
set(${PKGNAME}_LIB_DIRS)
mark_as_advanced(${PKGNAME}_LIBS ${PKGNAME}_LIB_DIRS)
if(${PKGNAME}_CONFIGLIBS)
string(REGEX MATCHALL "(^| )-l[^ ]+" libs ${${PKGNAME}_CONFIGLIBS})
foreach(lib ${libs})
string(STRIP ${lib} lib)
string(SUBSTRING ${lib} 2 -1 lib)
list(APPEND ${PKGNAME}_LIBS ${lib})
endforeach()
string(REGEX MATCHALL "(^| )-L[^ ]+" libdirs ${${PKGNAME}_CONFIGLIBS})
foreach(libdir ${libdirs})
string(STRIP ${libdir} libdir)
string(SUBSTRING ${libdir} 2 -1 libdir)
list(APPEND ${PKGNAME}_LIB_DIRS ${libdir})
endforeach()
# append directories of exposed libraries
if ("CGAL" IN_LIST ${PKGNAME}_LIBS)
find_library(lib_cgal NAMES "CGAL" PATHS $ENV{CGAL_ROOT}/lib NO_DEFAULT_PATH)
if (NOT lib_cgal)
message(FATAL_ERROR "CGAL not found in $ENV{CGAL_ROOT}/lib")
endif()
get_filename_component(dir_cgal ${lib_cgal} DIRECTORY)
list(APPEND ${PKGNAME}_LIB_DIRS ${dir_cgal})
endif()
if ("gmp" IN_LIST ${PKGNAME}_LIBS)
find_library(lib_gmp NAMES "gmp" PATHS $ENV{GMP_ROOT}/lib NO_DEFAULT_PATH)
if (NOT lib_gmp)
message(FATAL_ERROR "GMP not found in $ENV{GMP_ROOT}/lib")
endif()
get_filename_component(dir_gmp ${lib_gmp} DIRECTORY)
list(APPEND ${PKGNAME}_LIB_DIRS ${dir_gmp})
endif()
endif(${PKGNAME}_CONFIGLIBS)
endif(${PKGNAME}_CONFIG)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(${PKGNAME}
REQUIRED_VARS ${PKGNAME}_INCLUDE_DIRS
${PKGNAME}_LIB_DIRS
${PKGNAME}_LIBS)
# if everything was found, assemble target with dependencies
if(${${PKGNAME}_FOUND})
add_library(${PKGNAME}::${PKGNAME} IMPORTED INTERFACE GLOBAL)
target_compile_definitions(${PKGNAME}::${PKGNAME} INTERFACE "HAVE_${PKGENVNAME}")
foreach(lib ${${PKGNAME}_LIBS})
target_link_libraries(${PKGNAME}::${PKGNAME} INTERFACE ${lib})
endforeach()
foreach(libdir ${${PKGNAME}_LIB_DIRS})
target_link_directories(${PKGNAME}::${PKGNAME} INTERFACE ${libdir})
endforeach()
foreach(incdir ${${PKGNAME}_INCLUDE_DIRS})
target_include_directories(${PKGNAME}::${PKGNAME} INTERFACE ${incdir})
endforeach()
find_library(lib_contrib NAMES "fastjetcontribfragile" PATHS ${${PKGNAME}_LIB_DIRS} NO_DEFAULT_PATH)
if(lib_contrib)
message(STATUS "adding FastJet contrib")
add_library(${PKGNAME}::Contrib IMPORTED INTERFACE GLOBAL)
target_link_libraries(${PKGNAME}::Contrib INTERFACE ${lib_contrib})
endif()
endif()
unset(PKGNAME)
unset(PKGENVNAME)