1 |
# - Finds ROOT instalation |
2 |
# This module sets up ROOT information |
3 |
# It defines: |
4 |
# ROOT_FOUND If the ROOT is found |
5 |
# ROOT_INCLUDE_DIR PATH to the include directory |
6 |
# ROOT_LIBRARIES Most common libraries |
7 |
# ROOT_LIBRARY_DIR PATH to the library directory |
8 |
# |
9 |
# Updated by K. Smith (ksmith37@nd.edu) to properly handle |
10 |
# dependncies in ROOT_GENERATE_DICTIONARY |
11 |
|
12 |
if("$ENV{ROOTSYS}" STREQUAL "") |
13 |
message(WARNING "The ROOTSYS environment variable is not defined") |
14 |
endif() |
15 |
|
16 |
find_program(ROOT_CONFIG_EXECUTABLE root-config |
17 |
PATHS $ENV{ROOTSYS}/bin) |
18 |
|
19 |
if(NOT ROOT_CONFIG_EXECUTABLE) |
20 |
set(ROOT_FOUND FALSE) |
21 |
else() |
22 |
set(ROOT_FOUND TRUE) |
23 |
|
24 |
execute_process( |
25 |
COMMAND ${ROOT_CONFIG_EXECUTABLE} --prefix |
26 |
OUTPUT_VARIABLE ROOTSYS |
27 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
28 |
|
29 |
execute_process( |
30 |
COMMAND ${ROOT_CONFIG_EXECUTABLE} --version |
31 |
OUTPUT_VARIABLE ROOT_VERSION |
32 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
33 |
string(REGEX REPLACE "/" "." ROOT_VERSION "${ROOT_VERSION}") |
34 |
|
35 |
execute_process( |
36 |
COMMAND ${ROOT_CONFIG_EXECUTABLE} --incdir |
37 |
OUTPUT_VARIABLE ROOT_INCLUDE_DIR |
38 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
39 |
|
40 |
execute_process( |
41 |
COMMAND ${ROOT_CONFIG_EXECUTABLE} --libs |
42 |
OUTPUT_VARIABLE ROOT_LIBRARIES |
43 |
OUTPUT_STRIP_TRAILING_WHITESPACE) |
44 |
|
45 |
# Extract library dir from ROOT_LIBRARIES |
46 |
string(REGEX REPLACE " " ";" ROOT_LIBRARY_LIST ${ROOT_LIBRARIES}) |
47 |
list(GET ROOT_LIBRARY_LIST 0 ROOT_LIBRARY_DIR) |
48 |
string(REGEX REPLACE "-L" "" ROOT_LIBRARY_DIR ${ROOT_LIBRARY_DIR}) |
49 |
|
50 |
endif() |
51 |
|
52 |
include(FindPackageHandleStandardArgs) |
53 |
find_package_handle_standard_args(ROOT REQUIRED_VARS ROOT_CONFIG_EXECUTABLE |
54 |
ROOTSYS ROOT_VERSION ROOT_INCLUDE_DIR ROOT_LIBRARIES ROOT_LIBRARY_DIR |
55 |
VERSION_VAR ROOT_VERSION) |
56 |
|
57 |
mark_as_advanced(ROOT_CONFIG_EXECUTABLE) |
58 |
|
59 |
include(CMakeParseArguments) |
60 |
find_program(ROOTCINT_EXECUTABLE rootcint PATHS $ENV{ROOTSYS}/bin) |
61 |
find_program(GENREFLEX_EXECUTABLE genreflex PATHS $ENV{ROOTSYS}/bin) |
62 |
find_package(GCCXML) |
63 |
|
64 |
#---------------------------------------------------------------------------- |
65 |
# function ROOT_GENERATE_DICTIONARY( dictionary |
66 |
# header1 header2 ... |
67 |
# LINKDEF linkdef1 ... |
68 |
# OPTIONS opt1...) |
69 |
function(ROOT_GENERATE_DICTIONARY dictionary) |
70 |
CMAKE_PARSE_ARGUMENTS(ARG "" "" "LINKDEF;OPTIONS" "" ${ARGN}) |
71 |
#---Get the list of include directories------------------ |
72 |
get_directory_property(incdirs INCLUDE_DIRECTORIES) |
73 |
set(includedirs) |
74 |
foreach( d ${incdirs}) |
75 |
set(includedirs ${includedirs} -I${d}) |
76 |
endforeach() |
77 |
#---Get the list of header files------------------------- |
78 |
set(headerfiles) |
79 |
foreach(fp ${ARG_UNPARSED_ARGUMENTS}) |
80 |
if(${fp} MATCHES "[*?]") # Is this header a globbing expression? |
81 |
file(GLOB files ${fp}) |
82 |
foreach(f ${files}) |
83 |
if(NOT f MATCHES LinkDef) # skip LinkDefs from globbing result |
84 |
set(headerfiles ${headerfiles} ${f}) |
85 |
endif() |
86 |
endforeach() |
87 |
else() |
88 |
find_file(headerFile ${fp} PATHS ${incdirs}) |
89 |
set(headerfiles ${headerfiles} ${headerFile}) |
90 |
unset(headerFile CACHE) |
91 |
endif() |
92 |
endforeach() |
93 |
#---Get LinkDef.h file------------------------------------ |
94 |
set(linkdefs) |
95 |
foreach( f ${ARG_LINKDEF}) |
96 |
find_file(linkFile ${f} PATHS ${incdirs}) |
97 |
set(linkdefs ${linkdefs} ${linkFile}) |
98 |
unset(linkFile CACHE) |
99 |
endforeach() |
100 |
#---call rootcint------------------------------------------ |
101 |
add_custom_command(OUTPUT ${dictionary}.cxx ${dictionary}.h |
102 |
COMMAND ${ROOTCINT_EXECUTABLE} -cint -f ${dictionary}.cxx |
103 |
-c ${ARG_OPTIONS} ${includedirs} ${headerfiles} ${linkdefs} |
104 |
DEPENDS ${headerfiles} ${linkdefs} VERBATIM) |
105 |
endfunction() |
106 |
|
107 |
#---------------------------------------------------------------------------- |
108 |
# function REFLEX_GENERATE_DICTIONARY(dictionary |
109 |
# header1 header2 ... |
110 |
# SELECTION selectionfile ... |
111 |
# OPTIONS opt1...) |
112 |
function(REFLEX_GENERATE_DICTIONARY dictionary) |
113 |
CMAKE_PARSE_ARGUMENTS(ARG "" "" "SELECTION;OPTIONS" "" ${ARGN}) |
114 |
#---Get the list of header files------------------------- |
115 |
set(headerfiles) |
116 |
foreach(fp ${ARG_UNPARSED_ARGUMENTS}) |
117 |
file(GLOB files ${fp}) |
118 |
if(files) |
119 |
foreach(f ${files}) |
120 |
set(headerfiles ${headerfiles} ${f}) |
121 |
endforeach() |
122 |
else() |
123 |
set(headerfiles ${headerfiles} ${fp}) |
124 |
endif() |
125 |
endforeach() |
126 |
#---Get Selection file------------------------------------ |
127 |
if(IS_ABSOLUTE ${ARG_SELECTION}) |
128 |
set(selectionfile ${ARG_SELECTION}) |
129 |
else() |
130 |
set(selectionfile ${CMAKE_CURRENT_SOURCE_DIR}/${ARG_SELECTION}) |
131 |
endif() |
132 |
#---Get the list of include directories------------------ |
133 |
get_directory_property(incdirs INCLUDE_DIRECTORIES) |
134 |
set(includedirs) |
135 |
foreach( d ${incdirs}) |
136 |
set(includedirs ${includedirs} -I${d}) |
137 |
endforeach() |
138 |
#---Get preprocessor definitions-------------------------- |
139 |
get_directory_property(defs COMPILE_DEFINITIONS) |
140 |
foreach( d ${defs}) |
141 |
set(definitions ${definitions} -D${d}) |
142 |
endforeach() |
143 |
#---Nanes and others--------------------------------------- |
144 |
set(gensrcdict ${dictionary}.cpp) |
145 |
if(MSVC) |
146 |
set(gccxmlopts "--gccxmlopt=\"--gccxml-compiler cl\"") |
147 |
else() |
148 |
#set(gccxmlopts "--gccxmlopt=\'--gccxml-cxxflags -m64 \'") |
149 |
set(gccxmlopts) |
150 |
endif() |
151 |
#set(rootmapname ${dictionary}Dict.rootmap) |
152 |
#set(rootmapopts --rootmap=${rootmapname} --rootmap-lib=${libprefix}${dictionary}Dict) |
153 |
#---Check GCCXML and get path----------------------------- |
154 |
if(GCCXML) |
155 |
get_filename_component(gccxmlpath ${GCCXML} PATH) |
156 |
else() |
157 |
message(WARNING "GCCXML not found. Install and setup your environment to find 'gccxml' executable") |
158 |
endif() |
159 |
#---Actual command---------------------------------------- |
160 |
add_custom_command(OUTPUT ${gensrcdict} ${rootmapname} |
161 |
COMMAND ${GENREFLEX_EXECUTABLE} ${headerfiles} -o ${gensrcdict} ${gccxmlopts} ${rootmapopts} --select=${selectionfile} |
162 |
--gccxmlpath=${gccxmlpath} ${ARG_OPTIONS} ${includedirs} ${definitions} |
163 |
DEPENDS ${headerfiles} ${selectionfile}) |
164 |
endfunction() |
165 |
|