-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindROOT.cmake
184 lines (168 loc) · 6.76 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
# - 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_LIBRARIES Most common libraries
# ROOT_LIBRARY_DIR PATH to the library directory
find_program(ROOT_CONFIG_EXECUTABLE root-config
PATHS $ENV{ROOTSYS}/bin)
if(NOT ROOT_CONFIG_EXECUTABLE)
set(ROOT_FOUND FALSE)
else()
set(ROOT_FOUND TRUE)
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)
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --libs
OUTPUT_VARIABLE ROOT_LIBRARIES
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(
COMMAND ${ROOT_CONFIG_EXECUTABLE} --cflags --ldflags
OUTPUT_VARIABLE ROOT_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${ROOT_FLAGS} MATCHES "(^|.+ )-m64($| .+)")
if (CMAKE_SIZEOF_VOID_P EQUAL 4)
message(FATAL_ERROR "You are building 32 bit version of cnipol, but your ROOT is 64 bit.")
endif()
elseif(${ROOT_FLAGS} MATCHES "(^|.+ )-m32($| .+)")
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(FATAL_ERROR "You are building 64 bit version of cnipol, but your ROOT is 32 bit.")
endif()
else()
message(FATAL_ERROR "Can't detect ROOT distribution bitness")
endif()
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lThread -lMinuit -lHtml -lVMC -lEG -lGeom -lTreePlayer -lXMLIO -lProof)
#set(ROOT_LIBRARIES ${ROOT_LIBRARIES} -lProofPlayer -lMLP -lSpectrum -lEve -lRGL -lGed -lXMLParser -lPhysics)
set(ROOT_LIBRARY_DIR ${ROOTSYS}/lib)
# Make variables changeble to the advanced user
mark_as_advanced(ROOT_CONFIG_EXECUTABLE)
if(NOT ROOT_FIND_QUIETLY)
message(STATUS "Found ROOT ${ROOT_VERSION} in ${ROOTSYS}")
endif()
endif()
include(CMakeParseArguments)
find_program(ROOTCINT_EXECUTABLE rootcint PATHS $ENV{ROOTSYS}/bin)
find_program(GENREFLEX_EXECUTABLE genreflex PATHS $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 header files-------------------------
set(headerfiles)
foreach(fp ${ARG_UNPARSED_ARGUMENTS})
file(GLOB files ${fp})
if(files)
foreach(f ${files})
if(NOT f MATCHES LinkDef)
set(headerfiles ${headerfiles} ${f})
endif()
endforeach()
else()
set(headerfiles ${headerfiles} ${fp})
endif()
endforeach()
#---Get the list of include directories------------------
get_directory_property(incdirs INCLUDE_DIRECTORIES)
set(includedirs)
foreach( d ${incdirs})
set(includedirs ${includedirs} -I${d})
endforeach()
#---Get LinkDef.h file------------------------------------
set(linkdefs)
foreach( f ${ARG_LINKDEF})
if( IS_ABSOLUTE ${f})
set(linkdefs ${linkdefs} ${f})
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/inc/${f})
set(linkdefs ${linkdefs} ${CMAKE_CURRENT_SOURCE_DIR}/inc/${f})
else()
set(linkdefs ${linkdefs} ${CMAKE_CURRENT_SOURCE_DIR}/${f})
endif()
endif()
endforeach()
#---call rootcint------------------------------------------
if (${ROOT_VERSION} VERSION_LESS "6.0")
add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h
COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx
-c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
DEPENDS ${headerfiles} ${linkdefs})
else()
add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}_rdict.pcm
COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx
-c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs}
DEPENDS ${headerfiles} ${linkdefs})
endif()
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()