forked from star-bnl/star-prop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFindROOT.cmake
274 lines (235 loc) · 10.1 KB
/
FindROOT.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
# - Finds ROOT instalation
# This module sets up ROOT information
# It defines:
# ROOT_FOUND If the ROOT is found
# ROOT_INCLUDE_DIR PATH to the include directory
# ROOT_INCLUDE_DIRS PATH to the include directories (not cached)
# ROOT_LIBRARIES Most common libraries
# ROOT_<name>_LIBRARY Full path to the library <name>
# ROOT_LIBRARY_DIR PATH to the library directory
# ROOT_DEFINITIONS Compiler definitions
# ROOT_CXX_FLAGS Compiler flags to used by client packages
# ROOT_C_FLAGS Compiler flags to used by client packages
#
# Updated by K. Smith (ksmith37@nd.edu) to properly handle
# dependencies in ROOT_GENERATE_DICTIONARY
find_program(ROOT_CONFIG_EXECUTABLE root-config
HINTS $ENV{ROOTSYS}/bin)
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix
OUTPUT_VARIABLE ROOTSYS
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --version
OUTPUT_VARIABLE ROOT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir
OUTPUT_VARIABLE ROOT_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(ROOT_INCLUDE_DIRS ${ROOT_INCLUDE_DIR})
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --libdir
OUTPUT_VARIABLE ROOT_LIBRARY_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(ROOT_LIBRARY_DIRS ${ROOT_LIBRARY_DIR})
set(rootlibs Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread)
set(ROOT_LIBRARIES)
foreach(_cpt ${rootlibs} ${ROOT_FIND_COMPONENTS})
find_library(ROOT_${_cpt}_LIBRARY ${_cpt} HINTS ${ROOT_LIBRARY_DIR})
if(ROOT_${_cpt}_LIBRARY)
mark_as_advanced(ROOT_${_cpt}_LIBRARY)
list(APPEND ROOT_LIBRARIES ${ROOT_${_cpt}_LIBRARY})
list(REMOVE_ITEM ROOT_FIND_COMPONENTS ${_cpt})
endif()
endforeach()
list(REMOVE_DUPLICATES ROOT_LIBRARIES)
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --cflags
OUTPUT_VARIABLE __cflags
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCHALL "-(D|U)[^ ]*" ROOT_DEFINITIONS "${__cflags}")
string(REGEX REPLACE "(^|[ ]*)-I[^ ]*" "" ROOT_CXX_FLAGS "${__cflags}")
string(REGEX REPLACE "(^|[ ]*)-I[^ ]*" "" ROOT_C_FLAGS "${__cflags}")
set(ROOT_USE_FILE ${CMAKE_CURRENT_LIST_DIR}/RootUseFile.cmake)
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --features
OUTPUT_VARIABLE _root_options
OUTPUT_STRIP_TRAILING_WHITESPACE)
separate_arguments(_root_options)
foreach(_opt ${_root_options})
set(ROOT_${_opt}_FOUND TRUE)
endforeach()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ROOT DEFAULT_MSG ROOT_CONFIG_EXECUTABLE
ROOTSYS ROOT_VERSION ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR)
mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
include(CMakeParseArguments)
find_program(ROOTCINT_EXECUTABLE rootcint HINTS $ENV{ROOTSYS}/bin)
find_program(GENREFLEX_EXECUTABLE genreflex HINTS $ENV{ROOTSYS}/bin)
find_package(GCCXML)
#----------------------------------------------------------------------------
# function ROOT_GENERATE_DICTIONARY( dictionary
# header1 header2 ...
# LINKDEF linkdef1 ...
# OPTIONS opt1...)
function(ROOT_GENERATE_DICTIONARY dictionary)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN})
#---Get the list of include directories------------------
get_directory_property(incdirs INCLUDE_DIRECTORIES)
list(REMOVE_ITEM incdirs "/usr/include")
set(includedirs)
foreach( d ${incdirs})
set(includedirs ${includedirs} -I${d})
endforeach()
#---Get the list of header files-------------------------
set(headerfiles)
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
if(${fp} MATCHES "[*?]") # Is this header a globbing expression?
file(GLOB files ${fp})
foreach(f ${files})
if(NOT f MATCHES LinkDef) # skip LinkDefs from globbing result
set(headerfiles ${headerfiles} ${f})
endif()
endforeach()
else()
find_file(headerFile ${fp} HINTS ${incdirs})
set(headerfiles ${headerfiles} ${headerFile})
unset(headerFile CACHE)
endif()
endforeach()
#---Get LinkDef.h file------------------------------------
set(linkdefs)
foreach( f ${ARG_LINKDEF})
if(IS_ABSOLUTE ${f})
set(linkFile ${f})
else()
find_file(linkFile ${f} HINTS ${incdirs})
endif()
set(linkdefs ${linkdefs} ${linkFile})
unset(linkFile CACHE)
endforeach()
#---call rootcint------------------------------------------
add_custom_command(OUTPUT ${dictionary}.cxx
COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx
-c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
DEPENDS ${headerfiles} ${linkdefs} VERBATIM)
endfunction()
#----------------------------------------------------------------------------
# function REFLEX_GENERATE_DICTIONARY(dictionary
# header1 header2 ...
# SELECTION selectionfile ...
# OPTIONS opt1...)
function(REFLEX_GENERATE_DICTIONARY dictionary)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN})
#---Get the list of header files-------------------------
set(headerfiles)
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
file(GLOB files ${fp})
if(files)
foreach(f ${files})
set(headerfiles ${headerfiles} ${f})
endforeach()
else()
set(headerfiles ${headerfiles} ${fp})
endif()
endforeach()
#---Get Selection file------------------------------------
if(IS_ABSOLUTE ${ARG_SELECTION})
set(selectionfile ${ARG_SELECTION})
else()
set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION})
endif()
#---Get the list of include directories------------------
get_directory_property(incdirs INCLUDE_DIRECTORIES)
set(includedirs)
foreach( d ${incdirs})
set(includedirs ${includedirs} -I${d})
endforeach()
#---Get preprocessor definitions--------------------------
get_directory_property(defs COMPILE_DEFINITIONS)
foreach( d ${defs})
set(definitions ${definitions} -D${d})
endforeach()
#---Nanes and others---------------------------------------
set(gensrcdict ${dictionary}.cpp)
if(MSVC)
set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"")
else()
#set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'")
set(gccxmlopts)
endif()
#set(rootmapname ${dictionary}Dict.rootmap)
#set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict)
#---Check GCCXML and get path-----------------------------
if(GCCXML)
get_filename_component(gccxmlpath ${GCCXML} PATH)
else()
message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable")
endif()
#---Actual command----------------------------------------
add_custom_command(OUTPUT ${gensrcdict} ${rootmapname}
COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile}
--gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions}
DEPENDS ${headerfiles} ${selectionfile})
endfunction()
#
# function ROOT_GENERATE_LINKDEF( header_linkdef HEADERS header1 header2 ...)
#
# Generates a basic LinkDef header (header_linkdef) by parsing the user provided
# header files with standard linux utilities such as grep, awk, and sed.
#
function(ROOT_GENERATE_LINKDEF header_linkdef)
message(STATUS "Generating LinkDef header: ${header_linkdef}")
find_program(EXEC_GREP NAMES grep)
find_program(EXEC_AWK NAMES gawk awk)
find_program(EXEC_SED NAMES gsed sed)
if(NOT EXEC_GREP OR NOT EXEC_AWK OR NOT EXEC_SED)
message(FATAL_ERROR "FATAL: ROOT_GENERATE_LINKDEF function requires grep, awk, and sed commands")
endif()
CMAKE_PARSE_ARGUMENTS(ARG "" "" "HEADERS" ${ARGN})
# Create the list of header files with ClassDef macros
set(headers_cint)
foreach(user_header_arg ${ARG_HEADERS})
file(GLOB user_headers ${user_header_arg})
foreach(header ${user_headers})
if(header MATCHES LinkDef) # skip LinkDefs from globbing result
continue()
endif()
# Build a list of user_headers to use in dictionary generation
execute_process(COMMAND ${EXEC_GREP} -m1 -H ClassDef ${header} RESULT_VARIABLE exit_code OUTPUT_QUIET)
if (NOT ${exit_code})
list(APPEND headers_cint ${header})
else()
message(STATUS "WARNING: No ClassDef macro found in ${header}")
endif()
endforeach()
endforeach()
set(cint_dict_objects)
foreach(header ${headers_cint})
set(my_exec_cmd ${EXEC_AWK} "match($0,\"ClassDef(.*)\\\\((.*),(.*)\\\\)\",a){printf(a[2]\"\\r\")}")
execute_process(COMMAND ${my_exec_cmd} ${header} COMMAND ${EXEC_SED} -e "s/\\s\\+/;/g"
RESULT_VARIABLE exit_code OUTPUT_VARIABLE extracted_dict_objects ERROR_VARIABLE extracted_dict_objects
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND cint_dict_objects ${extracted_dict_objects})
endforeach()
# Create and write contents to LinkDef file
set_source_files_properties(${header_linkdef} PROPERTIES GENERATED TRUE)
file(WRITE ${header_linkdef}
"#ifdef __CINT__\n\n#pragma link off all globals;\n#pragma link off all classes;\n#pragma link off all functions;\n\n")
foreach(cint_dict_object ${cint_dict_objects})
file(APPEND ${header_linkdef} "#pragma link C++ class ${cint_dict_object}+;\n")
endforeach()
file(APPEND ${header_linkdef} "\n#endif\n")
endfunction()
#
# function ROOT_GENERATE_LINKDEF( user_base_file_name HEADERS header1 header2 ...)
#
# A high level wrapper around the above function to simplify user calls
#
function(ROOT_GENERATE_LINKDEF_AND_DICTIONARY user_base_file_name)
CMAKE_PARSE_ARGUMENTS(ARG "" "" "HEADERS" ${ARGN})
set(header_linkdef "${CMAKE_CURRENT_BINARY_DIR}/${user_base_file_name}_LinkDef.h")
root_generate_linkdef(${header_linkdef} HEADERS ${ARG_HEADERS})
root_generate_dictionary(${user_base_file_name}_dict ${ARG_HEADERS} LINKDEF ${header_linkdef} OPTIONS "-p")
endfunction()