]>
Commit | Line | Data |
---|---|---|
e969a926 | 1 | # -*- mode: cmake -*- |
2 | ||
3 | ########################################### | |
4 | # | |
5 | # Usefull macros | |
6 | # | |
7 | ########################################### | |
8 | ||
9 | ############################################################### | |
10 | # | |
11 | # Exchange file extention of LIST from | |
12 | # FILE_EXT1 to FILE_EXT2 and assign the | |
13 | # newly created list to OUTVAR. The input | |
14 | # list LIST is not changed at all | |
15 | # Ex: CHANGE_FILE_EXTENSION(*.cxx *.h TRD_HEADERS "${TRD_SRCS}") | |
16 | # | |
17 | ################################################################ | |
18 | ||
19 | MACRO (CHANGE_FILE_EXTENSION FILE_EXT1 FILE_EXT2 OUTVAR LIST) | |
20 | ||
21 | SET(BLA) | |
22 | ||
23 | IF (${FILE_EXT1} MATCHES "^[*][.]+.*$") | |
24 | STRING(REGEX REPLACE "^[*]+([.].*)$" "\\1" FILE_EXT1_NEW ${FILE_EXT1}) | |
25 | ENDIF (${FILE_EXT1} MATCHES "^[*][.]+.*$") | |
26 | ||
27 | IF (${FILE_EXT2} MATCHES "^[*][.]+.*$") | |
28 | STRING(REGEX REPLACE "^[*]+([.].*)" "\\1" FILE_EXT2_NEW ${FILE_EXT2}) | |
29 | ENDIF (${FILE_EXT2} MATCHES "^[*][.]+.*$") | |
30 | ||
31 | foreach (_current_FILE ${LIST}) | |
32 | ||
33 | # GET_FILENAME_COMPONENT(name_wo_path ${_current_FILE} | |
34 | # NAME | |
35 | # ) | |
36 | ||
37 | STRING(REGEX REPLACE "^(.*)${FILE_EXT1_NEW}$" "\\1${FILE_EXT2_NEW}" test ${_current_FILE}) | |
38 | SET (BLA ${BLA} ${test}) | |
39 | ||
40 | endforeach (_current_FILE ${LIST}) | |
41 | ||
42 | SET (${OUTVAR} ${BLA}) | |
43 | ||
44 | ||
45 | ||
46 | ENDMACRO (CHANGE_FILE_EXTENSION) | |
47 | ||
48 | ###################################################### | |
49 | # | |
50 | # Macro get string with a colon seperated string of | |
51 | # pathes or any other colon sperated list. | |
52 | # First the string is seperated and the entries are | |
53 | # filled into a list. | |
54 | # Loop over the list and searches for the occurence | |
55 | # of keywords which are provided as a list. | |
56 | # If the keyword occurs this path (entry) is | |
57 | # deleted from the list. Returns the list of pathes | |
58 | # (entries) wich survives the loop. | |
59 | # | |
60 | # PATH: colon separated string of pathes or other | |
61 | # input entries | |
62 | # LIST_OF_KEYWORDS: list of the keywords which | |
63 | # should be excluded in the output | |
64 | # OUTVAR: name of the variable which should be filled | |
65 | # with the resulting output list | |
66 | # | |
67 | ###################################################### | |
68 | ||
69 | MACRO (CLEAN_PATH_LIST PATH LIST_OF_KEYWORDS OUTVAR) | |
70 | ||
71 | SET(BLA "") | |
72 | ||
73 | STRING(REGEX MATCHALL "[^:]+" PATH1 ${PATH}) | |
74 | ||
75 | FOREACH(_current_PATH ${PATH1}) | |
76 | ||
77 | SET(KEYWORD_FOUND FALSE) | |
78 | ||
79 | FOREACH(_current_KEYWORD ${LIST_OF_KEYWORDS}) | |
80 | ||
81 | IF (${_current_PATH} MATCHES "${_current_KEYWORD}") | |
82 | SET(KEYWORD_FOUND TRUE) | |
83 | ENDIF (${_current_PATH} MATCHES "${_current_KEYWORD}") | |
84 | ||
85 | ENDFOREACH(_current_KEYWORD ${LIST_OF_KEYWORDS}) | |
86 | ||
87 | IF (NOT KEYWORD_FOUND) | |
88 | SET(BLA ${BLA} ${_current_PATH}) | |
89 | ENDIF (NOT KEYWORD_FOUND) | |
90 | ||
91 | ENDFOREACH(_current_PATH ${PATH1}) | |
92 | ||
93 | UNIQUE(${OUTVAR} "${BLA}") | |
94 | ||
95 | ENDMACRO (CLEAN_PATH_LIST) | |
96 | ||
97 | ########################################################## | |
98 | # | |
99 | # The macro checks if the user wants to build the project | |
100 | # in the source directory and if so stop the execution | |
101 | # of cmake with an error message. | |
102 | # | |
103 | ########################################################## | |
104 | ||
105 | MACRO (CHECK_OUT_OF_SOURCE_BUILD) | |
106 | ||
107 | STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource) | |
108 | IF(insource) | |
109 | FILE(REMOVE_RECURSE ${CMAKE_SOURCE_DIR}/Testing) | |
110 | FILE(REMOVE ${CMAKE_SOURCE_DIR}/DartConfiguration.tcl) | |
111 | MESSAGE(FATAL_ERROR "FAIRROOT should be installed as an out of source build, to keep the source directory clean. Please create a extra build directory and run the command 'cmake path_to_source_dir' in this newly created directory. You have also to delete the directory CMakeFiles and the file CMakeCache.txt in the source directory. Otherwise cmake will complain even if you run it from an out-of-source directory.") | |
112 | ENDIF(insource) | |
113 | ||
114 | ENDMACRO (CHECK_OUT_OF_SOURCE_BUILD) | |
115 | ||
116 | MACRO(UNIQUE var_name list) | |
117 | ||
118 | ####################################################################### | |
119 | # Make the given list have only one instance of each unique element and | |
120 | # store it in var_name. | |
121 | ####################################################################### | |
122 | ||
123 | SET(unique_tmp "") | |
124 | FOREACH(l ${list}) | |
125 | STRING(REGEX REPLACE "[+]" "\\\\+" l1 ${l}) | |
126 | IF(NOT "${unique_tmp}" MATCHES "(^|;)${l1}(;|$)") | |
127 | SET(unique_tmp ${unique_tmp} ${l}) | |
128 | ENDIF(NOT "${unique_tmp}" MATCHES "(^|;)${l1}(;|$)") | |
129 | ENDFOREACH(l) | |
130 | SET(${var_name} ${unique_tmp}) | |
131 | ENDMACRO(UNIQUE) | |
132 | ||
133 | MACRO(CHECK_CMAKE_VERSION) | |
134 | ||
135 | ################################################################# | |
136 | #Check if CMake has at least version 2.4.3 | |
137 | # This has to be done before anything else, because some commands | |
138 | # are not known in older versions. | |
139 | ################################################################# | |
140 | ||
141 | EXEC_PROGRAM( cmake ARGS "--version" OUTPUT_VARIABLE CMAKE_VERSION ) | |
142 | IF (${CMAKE_MAJOR_VERSION} LESS 2 ) | |
143 | MESSAGE("You are using CMake version ${CMAKE_VERSION} .") | |
144 | MESSAGE( FATAL_ERROR "This Cmake version is to old. At leasts version 2.4.3 is needed.") | |
145 | ENDIF (${CMAKE_MAJOR_VERSION} LESS 2 ) | |
146 | IF (${CMAKE_MINOR_VERSION} LESS 4 ) | |
147 | MESSAGE("You are using CMake version ${CMAKE_VERSION} .") | |
148 | MESSAGE( FATAL_ERROR "This Cmake version is to old. At leasts version 2.4.3 is needed.") | |
149 | ENDIF (${CMAKE_MINOR_VERSION} LESS 4 ) | |
150 | IF (${CMAKE_PATCH_VERSION} LESS 3 ) | |
151 | MESSAGE("You are using CMake version ${CMAKE_VERSION} .") | |
152 | MESSAGE( FATAL_ERROR "This Cmake version is to old. At leasts version 2.4.3 is needed.") | |
153 | ENDIF (${CMAKE_PATCH_VERSION} LESS 3 ) | |
154 | ||
155 | ENDMACRO(CHECK_CMAKE_VERSION) | |
156 | ||
157 | MACRO(CHECK_GSI) | |
158 | ||
159 | ################################################################# | |
160 | # Check if /misc/cbmsoft/config exist, because than we are at GSI | |
161 | # If we are not at GSI some of the macros may not work. | |
162 | ################################################################# | |
163 | ||
164 | SET(GSI GSI-NOTFOUND) | |
165 | FIND_PATH(GSI NAMES config PATHS | |
166 | /misc/cbmsoft | |
167 | NO_DEFAULT_PATH | |
168 | ) | |
169 | ||
170 | EXEC_PROGRAM(uname ARGS "-m" OUTPUT_VARIABLE Machine) | |
171 | # SET(Machine ${CMAKE_SYSTEM_PROCESSOR}) | |
172 | #${CMAKE_SYSTEM_PROCESSOR} is not set correctly on 64bit | |
173 | #Debian Etch, so use workaround | |
174 | ||
175 | IF(GSI) | |
176 | MESSAGE("-- You're using the GSI installation of the external packages.") | |
177 | ||
178 | SET(KEYWORDS | |
179 | cbmsoft | |
180 | debian | |
181 | globus | |
182 | gcc | |
183 | binutils | |
184 | cbm | |
185 | panda | |
186 | ) | |
187 | IF(DEFINED ENV{PATH}) | |
188 | CLEAN_PATH_LIST("$ENV{PATH}" "${KEYWORDS}" PATH) | |
189 | #MESSAGE ("PATH: ${PATH}") | |
190 | #set(ENV{PATH} ${PATH}) | |
191 | ENDIF(DEFINED ENV{PATH}) | |
192 | ||
193 | ||
194 | # Create a clean LD_LIBRARY_PATH without any pathes to libraries set | |
195 | # later on | |
196 | IF(DEFINED ENV{LD_LIBRARY_PATH}) | |
197 | SET(KEYWORDS ${KEYWORDS} ${CMAKE_BINARY_DIR}) | |
198 | CLEAN_PATH_LIST("$ENV{LD_LIBRARY_PATH}" "${KEYWORDS}" LD_LIBRARY_PATH) | |
199 | #MESSAGE("LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}") | |
200 | ENDIF(DEFINED ENV{LD_LIBRARY_PATH}) | |
201 | ||
202 | # Check if you're on an 32 or 64 bit environment | |
203 | IF(${Machine} MATCHES "i686" OR | |
204 | ${Machine} MATCHES "i386" ) | |
205 | MESSAGE("-- This is an 32 bit machine") | |
206 | SET(GSI_SIMPATH /misc/cbmsoft/Debian3.1/new/) | |
207 | ELSE(${Machine} MATCHES "i686" OR | |
208 | ${Machine} MATCHES "i386" ) | |
209 | IF(${Machine} MATCHES "x86_64") | |
210 | MESSAGE("-- This is an 64 bit machine") | |
211 | SET(GSI_SIMPATH /misc/cbmsoft/Debian64/new/) | |
212 | ELSE(${Machine} MATCHES "x86_64") | |
213 | MESSAGE(FATAL_ERROR "This is a UNIX machine wich is neither 32 nor 64 bit. Don't know what to do, so break. ") | |
214 | ENDIF(${Machine} MATCHES "x86_64") | |
215 | ENDIF(${Machine} MATCHES "i686" OR | |
216 | ${Machine} MATCHES "i386" ) | |
217 | ||
218 | ELSE(GSI) | |
219 | MESSAGE("-- You're not using the GSI installation of the external packages.") | |
220 | MESSAGE("-- If any problems occur this can be due to the fact that the macros") | |
221 | MESSAGE("-- were mostly tested at GSI. If you find any problems please contact") | |
222 | MESSAGE("-- f.uhlig@gsi.de") | |
223 | STRING(REGEX MATCHALL "[^:]+" PATH $ENV{PATH}) | |
224 | #MESSAGE("PATH: ${PATH}") | |
225 | ENDIF(GSI) | |
226 | ||
227 | ENDMACRO(CHECK_GSI) | |
228 | ||
229 | MACRO(CHECK_EXTERNAL_PACKAGES_INSTALLATION) | |
230 | ||
231 | ############################################################# | |
232 | # Check if cmake can find the root of the simulation packages | |
233 | # check if the installation is as at GSI | |
234 | # This is needed later on to check for the required packages | |
235 | # Should be done in a better way that you find the packages | |
236 | # independent of the way where they are installed | |
237 | ############################################################# | |
238 | ||
239 | SET(SIMPATH SIMPATH-NOTFOUND) | |
240 | SET(SIMPATH1 SIMPATH1-NOTFOUND) | |
241 | SET(SIMPATH2 SIMPATH2-NOTFOUND) | |
242 | SET(SIMPATH3 SIMPATH3-NOTFOUND) | |
243 | SET(SIMPATH4 SIMPATH4-NOTFOUND) | |
244 | ||
245 | FIND_PATH(SIMPATH1 NAMES transport PATHS | |
246 | $ENV{SIMPATH} | |
247 | ${GSI_SIMPATH} | |
248 | NO_DEFAULT_PATH | |
249 | ) | |
250 | FIND_PATH(SIMPATH2 NAMES tools PATHS | |
251 | $ENV{SIMPATH} | |
252 | ${GSI_SIMPATH} | |
253 | NO_DEFAULT_PATH | |
254 | ) | |
255 | FIND_PATH(SIMPATH3 NAMES cern PATHS | |
256 | $ENV{SIMPATH} | |
257 | ${GSI_SIMPATH} | |
258 | NO_DEFAULT_PATH | |
259 | ) | |
260 | FIND_PATH(SIMPATH4 NAMES generators PATHS | |
261 | $ENV{SIMPATH} | |
262 | ${GSI_SIMPATH} | |
263 | NO_DEFAULT_PATH | |
264 | ) | |
265 | ||
266 | IF(SIMPATH1 AND SIMPATH2 AND SIMPATH3 AND SIMPATH4) | |
267 | SET(SIMPATH ${SIMPATH1}) | |
268 | ENDIF(SIMPATH1 AND SIMPATH2 AND SIMPATH3 AND SIMPATH4) | |
269 | ||
270 | ||
271 | IF (${SIMPATH} MATCHES "SIMPATH-NOTFOUND") | |
272 | MESSAGE( FATAL_ERROR "Could not find the root of the simulation software. Please define SIMPATH as the path to the root of your instalation of simulation software.") | |
273 | ELSE (${SIMPATH} MATCHES "SIMPATH-NOTFOUND") | |
274 | MESSAGE( STATUS "Found root of the simulation software at ${SIMPATH}") | |
275 | SET( ENV{SIMPATH} ${SIMPATH}) | |
276 | SET(ROOTSYS ${SIMPATH}/tools/root) | |
277 | SET( ENV{ROOTSYS} ${SIMPATH}/tools/root) | |
278 | ENDIF (${SIMPATH} MATCHES "SIMPATH-NOTFOUND") | |
279 | ||
280 | ENDMACRO(CHECK_EXTERNAL_PACKAGES_INSTALLATION) | |
281 | ||
282 | ################################################### | |
283 | # Creates a variable which stores the intersection | |
284 | # between two lists | |
285 | #################################################### | |
286 | ||
287 | MACRO(INTERSECTION var_name list1 list2) | |
288 | # Store the intersection between the two given lists in var_name. | |
289 | SET(intersect_tmp "") | |
290 | FOREACH(l ${list1}) | |
291 | IF("${list2}" MATCHES "(^|;)${l}(;|$)") | |
292 | SET(intersect_tmp ${intersect_tmp} ${l}) | |
293 | ENDIF("${list2}" MATCHES "(^|;)${l}(;|$)") | |
294 | ENDFOREACH(l) | |
295 | SET(${var_name} ${intersect_tmp}) | |
296 | ENDMACRO(INTERSECTION) | |
297 | ||
298 | MACRO(REMOVE_FROM_LIST var_name list1 list2) | |
299 | # Remove elements in list2 from list1 and store the result in var_name. | |
300 | SET(filter_tmp "") | |
301 | FOREACH(l ${list1}) | |
302 | IF(NOT "${list2}" MATCHES "(^|;)${l}(;|$)") | |
303 | SET(filter_tmp ${filter_tmp} ${l}) | |
304 | ENDIF(NOT "${list2}" MATCHES "(^|;)${l}(;|$)") | |
305 | ENDFOREACH(l) | |
306 | SET(${var_name} ${filter_tmp}) | |
307 | ENDMACRO(REMOVE_FROM_LIST) | |
308 | ||
309 | ||
310 | ||
311 | ||
312 |