Fixed errors in cmake build system
[u/mrichter/AliRoot.git] / cmake / modules / CreateSubCMakeFiles.cmake
CommitLineData
96c0c856 1Macro(CreateSubCMakeFiles)
2
3 # Extract list of subdirectories for which the script has to
4 # create CMakeLists.txt out of the information of the main
5 # CMakeLists.txt
6
7 MESSAGE(STATUS "Generating CMakeLists.txt in subdirectories from the package files.")
8
9 file(STRINGS ${CMAKE_SOURCE_DIR}/CMakeLists.txt bla
10 REGEX "^Add_subdirectory(.*)"
11 )
12
13 Foreach(_dir ${bla})
14 STRING(REGEX REPLACE "^Add_subdirectory\((.*)\)$" "\\1" _OutDir "${_dir}")
15 STRING(STRIP ${_OutDir} _OutDir1)
16 string(LENGTH ${_OutDir1} _Length)
17 math(EXPR _Length1 ${_Length}-2)
18 string(SUBSTRING ${_OutDir1} 1 ${_Length1} _OutDir)
19 List(APPEND Directories ${_OutDir})
20 EndForeach(_dir ${bla})
21
22 # Check if ROOT was compile with xml and alien support
23 # This is needed later to set properly the definitions during
24 # compilation
25 Execute_process(
26 COMMAND root-config --has-xml
27 OUTPUT_VARIABLE ROOT_HAS_XML
28 OUTPUT_STRIP_TRAILING_WHITESPACE)
29
30 Execute_process(
31 COMMAND root-config --has-alien
32 OUTPUT_VARIABLE ROOT_HAS_ALIEN
33 OUTPUT_STRIP_TRAILING_WHITESPACE)
34
35 # Loop over the subdirectories, extract the package files and
36 # call for each of the package files a macro which creates the
37 # corresponding CMake input files in the subdirectory
38
39 Foreach(_dir ${Directories})
40 if(NOT ${_dir} STREQUAL HLT)
41 file(GLOB Package RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/${_dir}/*.pkg)
42 get_filename_component(__path ${_dir} NAME)
43 set(EINCLUDE_SUBDIR ${__path} STEER)
44 set(PACKCXXFLAGS_SUBDIR)
45 set(PACKAGES)
46 Foreach(_pack ${Package})
47 GenerateInputFiles(${_pack})
48 set(EINCLUDE_SUBDIR ${EINCLUDE_SUBDIR} ${EINCLUDE_PACKAGE})
49 set(PACKCXXFLAGS_SUBDIR ${PACKCXXFLAGS_SUBDIR} ${PACKCXXFLAGS_PACKAGE})
50 EndForeach(_pack ${Package})
51 list(REMOVE_DUPLICATES EINCLUDE_SUBDIR)
52 CreateMainCMakeFile(${__path})
53 else(NOT ${_dir} STREQUAL HLT)
54# MESSAGE(STATUS "Don't generate files for HLT do to complete different syntax of package files")
55 Include(CreateHLTSubCMakeFiles)
56 CreateHLTSubCMakeFiles()
57 endif(NOT ${_dir} STREQUAL HLT)
58 EndForeach(_dir ${Directories})
59
60
61EndMacro(CreateSubCMakeFiles)
62
63Macro(GenerateInputFiles Package)
64
65 get_filename_component(_path ${Package} PATH)
66 get_filename_component(_name ${Package} NAME)
67
68 STRING(REGEX REPLACE "^(lib.*).pkg$" "\\1" _lib "${_name}")
69 STRING(REGEX REPLACE "^(bin.*).pkg$" "\\1" _bin "${_name}")
70
71 ParsePackageFile(${Package})
72
73 If(_name MATCHES "^lib.*$")
74 Set(PACKAGES ${PACKAGES} ${_lib})
75 SpecialSettingsMadeByHand(${_lib}) # Correct the Parser
76 CreateLibPackageFile(${_path} ${_lib})
77 Else(_name MATCHES "^lib.*$")
78 Set(PACKAGES ${PACKAGES} ${_bin})
79 CreateBinPackageFile(${_path} ${_bin})
80 EndIf(_name MATCHES "^lib.*$")
81
82EndMacro(GenerateInputFiles Package)
83
84Macro(ParsePackageFile Package)
85
86 Set(CXXSRCS_PACKAGE)
87 Set(CSRCS_PACKAGE)
88 Set(FSRCS_PACKAGE)
89 Set(EINCLUDE_PACKAGE)
90 Set(DHDR_PACKAGE)
91 Set(ELIBS_PACKAGE)
92 Set(HDRS_PACKAGE)
93 Set(PACKCXXFLAGS_PACKAGE)
94 Set(PACKFFLAGS_PACKAGE)
95 Set(ADD_HEADERS)
96 Set(EXCLUDE_PART FALSE)
97 Set(MATCHED FALSE)
98 Set(_file_glob FALSE)
99 Set(_file_glob_dir)
100 Set(DIMDIR $ENV{DIMDIR})
101
102 # Read the complete text file into variable contents
103
104 FILE(READ "${Package}" contents)
105
106 # Convert file contents into a CMake list (where each element in the list
107 # is one line of the file)
108 # Replace as first step ";" to "\". One "\" in a regex must be "\\\\"
109 # After that replace line breaks by a semicolon, which is in cmake the
110 # separator between list elements. The nice feature is that if there is a
111 # follow up line this is indicated with an "\" at the end of the line
112 # directly before the line break. In the generated string this two letters
113 # together becomes "\;" which is not the separator between two list elements
114 # but a single ";" in a liste element. With this trick one gets all
115 # follow up lines in one list element which can be parsed
116
117 STRING(REGEX REPLACE ";" "\\\\;" contents "${contents}")
118 STRING(REGEX REPLACE "\n" ";" contents "${contents}")
119
120 # Iterate over the lines of the input file
121 Foreach(line ${contents})
122
123
124 # Simple technique to handle if statements in the package files
125 # If you hit an endif or an else at the begining of a line read
126 # again lines below this point. In case of else check if it is a
127 # nested "if else if else endif endif" structure. If the correct
128 # case is already found don't read the following lines
129
130 # If(line MATCHES "^[#].*$")
131 # Set(EXCLUDE_PART TRUE)
132 # EndIf(line MATCHES "^[#].*$")
133
134 If(line MATCHES "^endif.*$")
135 Set(EXCLUDE_PART FALSE)
136 EndIf(line MATCHES "^endif.*$")
137
138 If(line MATCHES "^else.*$")
139 If(NOT MATCHED)
140 Set(EXCLUDE_PART FALSE)
141 Else(NOT MATCHED)
142 Set(EXCLUDE_PART TRUE)
143 EndIf(NOT MATCHED)
144 EndIf(line MATCHES "^else.*$")
145
146 # Special handling in case ther is a if statement
147
148 If(line MATCHES "^if.*$")
149
150 # Special handling in case ther is a ifeq statement
151
152 If(line MATCHES "^ifeq.*$")
153
154 # Remove ifeq from text. The rest is the interesting part of
155 # the statement
156
157 STRING(REGEX REPLACE "ifeq" "" statement "${line}")
158
159 # check if "ifeq" compares for ALICE_TARGET. If required target is
160 # equal to ALICE_TARGET, then read the following lines until endif
161 # or else is found
162 # Since only one target is possible mark that a target was already
163 # found. A short summary of regular expressions can be found at the
164 # end of this file.
165
166 If(line MATCHES "^.*ALICE_TARGET.*$")
167 STRING(REGEX REPLACE "^.*[(](.*),[$][(]ALICE_TARGET[)][)].*$" "\\1" _result "${line}")
168 If(_result STREQUAL ${ALICE_TARGET})
169 Set(MATCHED TRUE)
170 Set(EXCLUDE_PART FALSE)
171 Else(_result STREQUAL ${ALICE_TARGET})
172 Set(EXCLUDE_PART TRUE)
173 EndIf(_result STREQUAL ${ALICE_TARGET})
174 EndIf(line MATCHES "^.*ALICE_TARGET.*$")
175
176
177 # check if "if" statement checks for Alien or XML installation.
178 # If ROOT is installed with Alien or XML switch on the compile
179 # flags
180
181 If(line MATCHES "^.*CHECK.*$")
182 STRING(REGEX REPLACE "^.*[(](.*),[$][(]CHECKXML[)][)].*$" "\\1" _result_xml "${line}")
183 STRING(REGEX REPLACE "^.*[(](.*),[$][(]CHECKALIEN[)][)].*$" "\\1" _result_alien "${line}")
184 If(${_result_xml} STREQUAL ${ROOT_HAS_XML} OR ${_result_alien} STREQUAL ${ROOT_HAS_ALIEN})
185 Set(EXCLUDE_PART FALSE)
186 Else(${_result_xml} STREQUAL ${ROOT_HAS_XML} OR ${_result_alien} STREQUAL ${ROOT_HAS_ALIEN})
187 Set(EXCLUDE_PART TRUE)
188 EndIf(${_result_xml} STREQUAL ${ROOT_HAS_XML} OR ${_result_alien} STREQUAL ${ROOT_HAS_ALIEN})
189# MESSAGE("HIER")
190 EndIf(line MATCHES "^.*CHECK.*$")
191
192# MESSAGE("EXCLUDE: ${EXCLUDE_PART}")
193
194 If(line MATCHES "^.*CCM.*$")
195 STRING(REGEX REPLACE "^.*[(][$][(]CCMAJORV[)],(.*)[)].*$" "\\1" _result_maj "${line}")
196 STRING(REGEX REPLACE "^.*[(][$][(]CCMINORV[)],(.*)[)].*$" "\\1" _result_min "${line}")
197 If(${_result_maj} EQUAL 4 OR ${_result_min} EQUAL 3)
198 Set(EXCLUDE_PART FALSE)
199 Else(${_result_maj} EQUAL 4 OR ${_result_min} EQUAL 3)
200 Set(EXCLUDE_PART TRUE)
201 EndIf(${_result_maj} EQUAL 4 OR ${_result_min} EQUAL 3)
202 EndIf(line MATCHES "^.*CCM.*$")
203
204# MESSAGE("EXCLUDE: ${EXCLUDE_PART}")
205
206 If(line MATCHES "^.*F77.*$")
207 STRING(REGEX REPLACE "^.*[(](.*),[$][(]F77[)][)].*$" "\\1" _result_f77 "${line}")
208 If(${_result_f77} STREQUAL g95)
209 Set(EXCLUDE_PART FALSE)
210 Else(${_result_f77} STREQUAL g95)
211 Set(EXCLUDE_PART TRUE)
212 EndIf(${_result_f77} STREQUAL g95)
213 EndIf(line MATCHES "^.*F77.*$")
214
215
216# MESSAGE("EXCLUDE: ${EXCLUDE_PART}")
217
218 If(line MATCHES "^.*MACOSX_MINOR.*$")
219 STRING(REGEX REPLACE "^.*[(](.*),[$][(]MACOSX_MINOR[)][)].*$" "\\1" _result_mac "${line}")
220 If(${_result_mac} EQUAL 5)
221 Set(EXCLUDE_PART FALSE)
222 Else(${_result_mac} EQUAL 5)
223 Set(EXCLUDE_PART TRUE)
224 EndIf(${_result_mac} EQUAL 5)
225 EndIf(line MATCHES "^.*MACOSX_MINOR.*$")
226
227# MESSAGE("EXCLUDE: ${EXCLUDE_PART}")
228
229 Else(line MATCHES "^ifeq.*$")
230
231 If(line MATCHES "^ifdef.*$")
232 #MESSAGE("LINE: ${line}")
233
234 # line starts with if but not ifeq
235
236 # Parse DATE dependent part of if statements
237 STRING(REGEX REPLACE "^.*(DATE_ROOT).*$" "\\1" _result_date "${line}")
238 If(${_result_date} STREQUAL DATE_ROOT)
239 If(DATE_FOUND)
240 Set(EXCLUDE_PART FALSE)
241 Else(DATE_FOUND)
242 Set(EXCLUDE_PART TRUE)
243 EndIf(DATE_FOUND)
244 EndIf(${_result_date} STREQUAL DATE_ROOT)
245
246 STRING(REGEX REPLACE "^.*(DIMDIR).*$" "\\1" _result_date "${line}")
247 If(${_result_date} STREQUAL DIMDIR)
248 If(DIMDIR)
249 Set(EXCLUDE_PART FALSE)
250 Else(DIMDIR)
251 Set(EXCLUDE_PART TRUE)
252 EndIf(DIMDIR)
253 EndIf(${_result_date} STREQUAL DIMDIR)
254
255 Else(line MATCHES "^ifdef.*$")
256 If(line MATCHES "^ifneq.*$")
257
258 If(line MATCHES "^.*FASTJET_ROOT.*$")
259 STRING(REGEX REPLACE "^.*[(][$][(]FASTJET_ROOT[)],(.*)[)].*$" "\\1" _result_fastjet "${line}")
260 If(NOT ${_length_fastjet})
261 Set(EXCLUDE_PART FALSE)
262 Else(NOT ${_length_fastjet})
263 Set(EXCLUDE_PART TRUE)
264 EndIf(NOT ${_length_fastjet})
265
266 Else(line MATCHES "^.*FASTJET_ROOT.*$")
267 If(line MATCHES "^.*findstring macosx,[$][(]ALICE_TARGET[)].*$")
268 STRING(REGEX REPLACE "^.*findstring[ ](,*),[$][(]ALICE_TARGET[)].*$" "\\1" _result_macox "${line}")
269 If(${_result_macox} MATCHES ".*macosx.*")
270 Set(EXCLUDE_PART FALSE)
271 Else(${_result_macox} MATCHES ".*macosx.*")
272 Set(EXCLUDE_PART FALSE)
273 EndIf(${_result_macox} MATCHES ".*macosx.*")
274
275 Else(line MATCHES "^.*findstring macosx,[$][(]ALICE_TARGET[)].*$")
276
277 MESSAGE(FATAL_ERROR "There is no rule how to handle ifneq statement in ${line}")
278
279 EndIf(line MATCHES "^.*findstring macosx,[$][(]ALICE_TARGET[)].*$")
280 EndIf(line MATCHES "^.*FASTJET_ROOT.*$")
281
282
283
284 Else(line MATCHES "^ifneq.*$")
285 Set(EXCLUDE_PART TRUE)
286 MESSAGE(FATAL_ERROR "There is no rule how to handle if statement in ${line}")
287 EndIf(line MATCHES "^ifneq.*$")
288
289 EndIf(line MATCHES "^ifdef.*$")
290 EndIf(line MATCHES "^ifeq.*$")
291 EndIf(line MATCHES "^if.*$")
292
293 # If the lines are inside an if statement which is not true exclude this
294 # part. In other words read only interesting part of of the file
295
296# MESSAGE("EXCLUDE*: ${EXCLUDE_PART}")
297
298 if(NOT EXCLUDE_PART)
299
300 If(line MATCHES "^ORGSRCS.*$")
301 STRING(REGEX REPLACE "^.*[$][(]wildcard[ ](.*)[*].*$" "\\1" orgsrc "${line}")
302 Set(_file_glob_dir ${_file_glob_dir} ${orgsrc})
303 EndIf(line MATCHES "^ORGSRCS.*$")
304
305 If(line MATCHES "^SRCS.*$")
306 STRING(REGEX REPLACE "SRCS" "" CXXSRCS "${line}")
307 STRING(REGEX REPLACE ":=" "" CXXSRCS "${CXXSRCS}")
308 STRING(REGEX REPLACE "[+]=" "" CXXSRCS "${CXXSRCS}")
309 STRING(REGEX REPLACE "=" "" CXXSRCS "${CXXSRCS}")
310 STRING(REGEX REPLACE "[ ]+" ";" CXXSRCS "${CXXSRCS}")
311 STRING(REGEX REPLACE "^;" "" CXXSRCS "${CXXSRCS}")
312 If(CXXSRCS MATCHES "^.*patsubst.*$")
313 set(_file_glob TRUE)
314 Else(CXXSRCS MATCHES "^.*patsubst.*$")
315 SET(CXXSRCS_PACKAGE ${CXXSRCS_PACKAGE} ${CXXSRCS})
316 EndIf(CXXSRCS MATCHES "^.*patsubst.*$")
317 EndIf(line MATCHES "^SRCS.*$")
318
319 If(line MATCHES "^CSRCS.*$")
320 STRING(REGEX REPLACE "CSRCS" "" CSRCS "${line}")
321 STRING(REGEX REPLACE ":=" "" CSRCS "${CSRCS}")
322 STRING(REGEX REPLACE "[+]=" "" CSRCS "${CSRCS}")
323 STRING(REGEX REPLACE "=" "" CSRCS "${CSRCS}")
324 STRING(REGEX REPLACE "[ ]+" ";" CSRCS "${CSRCS}")
325 STRING(REGEX REPLACE "^;" "" CSRCS "${CSRCS}")
326 SET(CSRCS_PACKAGE ${CSRCS_PACKAGE} ${CSRCS})
327 EndIf(line MATCHES "^CSRCS.*$")
328
329 If(line MATCHES "^FSRCS.*$")
330 STRING(REGEX REPLACE "FSRCS" "" FSRCS "${line}")
331 STRING(REGEX REPLACE ":=" "" FSRCS "${FSRCS}")
332 STRING(REGEX REPLACE "[+]=" "" FSRCS "${FSRCS}")
333 STRING(REGEX REPLACE "=" "" FSRCS "${FSRCS}")
334 STRING(REGEX REPLACE "[ ]+" ";" FSRCS "${FSRCS}")
335 STRING(REGEX REPLACE "^;" "" FSRCS "${FSRCS}")
336 SET(FSRCS_PACKAGE ${FSRCS_PACKAGE} ${FSRCS})
337 EndIf(line MATCHES "^FSRCS.*$")
338
339 If(line MATCHES "^EINCLUDE.*$")
340# MESSAGE("BLA: ${line}")
341 STRING(REGEX REPLACE "EINCLUDE" "" EINCLUDE "${line}")
342 STRING(REGEX REPLACE ":=" "" EINCLUDE "${EINCLUDE}")
343 STRING(REGEX REPLACE "[+]=" "" EINCLUDE "${EINCLUDE}")
344 STRING(REGEX REPLACE "=" "" EINCLUDE "${EINCLUDE}")
345 STRING(REGEX REPLACE "[ ]+" ";" EINCLUDE "${EINCLUDE}")
346 STRING(REGEX REPLACE "^;" "" EINCLUDE "${EINCLUDE}")
347 SET(EINCLUDE_PACKAGE ${EINCLUDE_PACKAGE} ${EINCLUDE})
348# MESSAGE("EINCLUDE_PACKAGE: ${EINCLUDE_PACKAGE}")
349 EndIf(line MATCHES "^EINCLUDE.*$")
350
351 If(line MATCHES "^DHDR.*$")
352 STRING(REGEX REPLACE "DHDR" "" DHDR "${line}")
353 STRING(REGEX REPLACE ":=" "" DHDR "${DHDR}")
354 STRING(REGEX REPLACE "[+]=" "" DHDR "${DHDR}")
355 STRING(REGEX REPLACE "=" "" DHDR "${DHDR}")
356 STRING(REGEX REPLACE "[ ]+" ";" DHDR "${DHDR}")
357 STRING(REGEX REPLACE "^;" "" DHDR "${DHDR}")
358 SET(DHDR_PACKAGE ${DHDR_PACKAGE} ${DHDR})
359 EndIf(line MATCHES "^DHDR.*$")
360
361 If(line MATCHES "^PACKCXXFLAGS.*$")
362 STRING(REGEX REPLACE "PACKCXXFLAGS" "" PACKCXXFLAGS "${line}")
363 STRING(REGEX REPLACE ":=" "" PACKCXXFLAGS "${PACKCXXFLAGS}")
364 STRING(REGEX REPLACE "[+]=" "" PACKCXXFLAGS "${PACKCXXFLAGS}")
365 STRING(REGEX REPLACE "^[ ]+[=]" "" PACKCXXFLAGS "${PACKCXXFLAGS}")
366 STRING(REGEX REPLACE "[ ]+" ";" PACKCXXFLAGS "${PACKCXXFLAGS}")
367 STRING(REGEX REPLACE "^;" "" PACKCXXFLAGS "${PACKCXXFLAGS}")
368 foreach(elem ${PACKCXXFLAGS})
369 STRING(REGEX MATCH "^[-]D.*$" _match_result ${elem})
370 if(${elem} STREQUAL "${_match_result}")
371 SET(PACKCXXFLAGS_PACKAGE ${PACKCXXFLAGS_PACKAGE} ${elem})
372 endif(${elem} STREQUAL "${_match_result}")
373 endforeach(elem ${PACKCXXFLAGS})
374 # MESSAGE("DEFINITIONS: ${PACKCXXFLAGS_PACKAGE}")
375 EndIf(line MATCHES "^PACKCXXFLAGS.*$")
376
377 If(line MATCHES "^PACKFFLAGS.*$")
378 STRING(REGEX REPLACE "PACKFFLAGS" "" PACKFFLAGS "${line}")
379 STRING(REGEX REPLACE ":=" "" PACKFFLAGS "${PACKFFLAGS}")
380 STRING(REGEX REPLACE "[+]=" "" PACKFFLAGS "${PACKFFLAGS}")
381 STRING(REGEX REPLACE "^[ ]+[=]" "" PACKFFLAGS "${PACKFFLAGS}")
382 STRING(REGEX REPLACE "[ ]+" ";" PACKFFLAGS "${PACKFFLAGS}")
383 STRING(REGEX REPLACE "^;" "" PACKFFLAGS "${PACKFFLAGS}")
384 foreach(elem ${PACKFFLAGS})
385 STRING(REGEX MATCH "[-]O[%]" _match_result ${elem})
386 if("${_match_result}" STREQUAL "-O%")
387 set(elem "bla bla")
388 endif("${_match_result}" STREQUAL "-O%")
389 STRING(REGEX MATCH "^[-].*$" _match_result ${elem})
390 if(${elem} STREQUAL "${_match_result}")
391 SET(PACKFFLAGS_PACKAGE ${PACKFFLAGS_PACKAGE} ${elem})
392 endif(${elem} STREQUAL "${_match_result}")
393 endforeach(elem ${PACKFFLAGS})
394 # MESSAGE("FDEFINITIONS: ${PACKFFLAGS_PACKAGE}")
395 EndIf(line MATCHES "^PACKFFLAGS.*$")
396
397 If(line MATCHES "^ELIBS.*$")
398 If(NOT line MATCHES "^ELIBSCPP.*$")
399 If(NOT line MATCHES "^ELIBSDIR.*$")
400 STRING(REGEX REPLACE "ELIBS" "" ELIBS "${line}")
401 STRING(REGEX REPLACE ":=" "" ELIBS "${ELIBS}")
402 STRING(REGEX REPLACE "[+]=" "" ELIBS "${ELIBS}")
403 STRING(REGEX REPLACE "=" "" ELIBS "${ELIBS}")
404 STRING(REGEX REPLACE "[ ]+" ";" ELIBS "${ELIBS}")
405 STRING(REGEX REPLACE "^;" "" ELIBS "${ELIBS}")
406 SET(ELIBS_PACKAGE ${ELIBS_PACKAGE} ${ELIBS})
407 EndIf(NOT line MATCHES "^ELIBSDIR.*$")
408 EndIf(NOT line MATCHES "^ELIBSCPP.*$")
409 EndIf(line MATCHES "^ELIBS.*$")
410
411 If(line MATCHES "^HDRS.*$")
412 STRING(REGEX REPLACE "HDRS" "" HDRS "${line}")
413
414 # Check if list of header files should be build from
415 # list of source files. Add additional header files to
416 # the list if they are defined. The parser does not
417 IF("${HDRS}" MATCHES "[$][(]SRCS:[.]cxx=[.]h[)]")
418 set(ADD_HEADERS TRUE)
419 ELSE("${HDRS}" MATCHES "[$][(]SRCS:[.]cxx=[.]h[)]")
420 if(ADD_HEADERS)
421 set(ADD_HEADERS TRUE)
422 else(ADD_HEADERS)
423 set(ADD_HEADERS FALSE)
424 endif(ADD_HEADERS)
425 ENDIF("${HDRS}" MATCHES "[$][(]SRCS:[.]cxx=[.]h[)]")
426 STRING(REGEX REPLACE "[$][(]SRCS:[.]cxx=[.]h[)]" "" HDRS "${HDRS}")
427
428# STRING(REGEX REPLACE "[$][(]filter-out(.*),.*[)]" "//1" _exclude_h "${HDRS}")
429# STRING(LENGTH ${_exclude_h} _exclude_h_length)
430# If(${_exclude_h_length} GREATER 0)
431# String(STRIP ${_exclude_h} _exclude_h)
432# list(REMOVE_ITEM HDRS ${_exclude_h})
433# EndIf(${_exclude_h_length} GREATER 0)
434
435 STRING(REGEX REPLACE "[$][(]filter-out.*[)]" "" HDRS "${HDRS}")
436 STRING(REGEX REPLACE ":=" "" HDRS "${HDRS}")
437 STRING(REGEX REPLACE "[+]=" "" HDRS "${HDRS}")
438 STRING(REGEX REPLACE "=" "" HDRS "${HDRS}")
439 STRING(REGEX REPLACE "[ ]+" ";" HDRS "${HDRS}")
440 STRING(REGEX REPLACE "^;" "" HDRS "${HDRS}")
441 SET(HDRS_PACKAGE ${HDRS_PACKAGE} ${HDRS})
442 EndIf(line MATCHES "^HDRS.*$")
443
444# MESSAGE("Parsed: ${line}")
445 Else(NOT EXCLUDE_PART)
446# MESSAGE("Not parsed: ${line}")
447 EndIf(NOT EXCLUDE_PART)
448
449 EndForeach(line ${contents})
450EndMacro(ParsePackageFile Package)
451
452Macro(CreateMainCMakeFile path)
453 set(FileName ${path}/CMakeLists.txt)
454 file(WRITE ${FileName} "# -*- mode: cmake -*-\n")
455 file(APPEND ${FileName} "# Create a library called \"lib<name>\" which includes the source files given in\n")
456 file(APPEND ${FileName} "# the array .\n")
457 file(APPEND ${FileName} "# The extension is already found. Any number of sources could be listed here.\n\n")
458 file(APPEND ${FileName} "set(INCLUDE_DIRECTORIES\n")
459 foreach(file ${EINCLUDE_SUBDIR})
460 If(file MATCHES "^.*[$].*$")
461 STRING(REGEX REPLACE "[(]" "ENV{" file "${file}")
462 STRING(REGEX REPLACE "[)]" "}" file "${file}")
463 file(APPEND ${FileName} "${file}\n")
464 Else(file MATCHES "^.*[$].*$")
465 file(APPEND ${FileName} "\${CMAKE_SOURCE_DIR}/${file}\n")
466 EndIf(file MATCHES "^.*[$].*$")
467 endforeach(file ${EINCLUDE_SUBDIR})
468 file(APPEND ${FileName} "\${ROOT_INCLUDE_DIR}\n")
469
470 if(${_dir} STREQUAL STEER OR ${_dir} STREQUAL TPC OR ${_dir} STREQUAL ALIROOT)
471 file(APPEND ${FileName} "\${CMAKE_BINARY_DIR}/STEER\n")
472 endif(${_dir} STREQUAL STEER OR ${_dir} STREQUAL TPC OR ${_dir} STREQUAL ALIROOT)
473 if(${_dir} STREQUAL RAW)
474 file(APPEND ${FileName} "\${CMAKE_SOURCE_DIR}\n")
475 endif(${_dir} STREQUAL RAW)
476
477
478 file(APPEND ${FileName} ")\n\n")
479 file(APPEND ${FileName} "include_directories(\${INCLUDE_DIRECTORIES})\n\n")
480 file(APPEND ${FileName} "set(LINK_DIRECTORIES\n")
481 file(APPEND ${FileName} "\${ROOT_LIBRARY_DIR}\n")
482 file(APPEND ${FileName} ")\n\n")
483 file(APPEND ${FileName} "link_directories(\${LINK_DIRECTORIES})\n\n")
484
485 list(LENGTH PACKCXXFLAGS_SUBDIR definition_length)
486 if(${definition_length} GREATER 0)
487 list(REMOVE_DUPLICATES PACKCXXFLAGS_SUBDIR)
488 file(APPEND ${FileName} "Add_Definitions(\n")
489 foreach(file ${PACKCXXFLAGS_SUBDIR})
490 file(APPEND ${FileName} "${file}\n")
491 endforeach(file ${CXXSRCS_SUBDIR})
492 file(APPEND ${FileName} ")\n\n")
493 endif(${definition_length} GREATER 0)
494
495 file(APPEND ${FileName} "SetModule()\n\n")
496 foreach(file ${PACKAGES})
497 file(APPEND ${FileName} "include (CMake_${file}.txt)\n\n")
498 endforeach(file ${PACKAGES})
499EndMacro(CreateMainCMakeFile path)
500
501Macro(CreateLibPackageFile path lib)
502
503 set(FileName ${path}/CMake_${lib}.txt)
504 set(AddCSource FALSE)
505 set(AddFortranSource FALSE)
506
507 STRING(REGEX REPLACE "^lib(.*)" "\\1" _lib "${lib}")
508
509 file(WRITE ${FileName} "# -*- mode: cmake -*-\n\n")
510
511 file(APPEND ${FileName} "set(SRCS)\n\n")
512
513 If(_file_glob)
514 set(_counter 0)
515 ForEach(_file ${_file_glob_dir})
516 file(APPEND ${FileName} "File(GLOB SRCS${_counter} RELATIVE \${CMAKE_CURRENT_SOURCE_DIR} \${CMAKE_SOURCE_DIR}/${_file}*.cxx)\n\n")
517 Math(EXPR _counter ${_counter}+1)
518 EndForEach(_file ${_file_glob_dir})
519 Math(EXPR _counter ${_counter}-1)
520 file(APPEND ${FileName} "set(SRCS)\n")
521 ForEach(_loop RANGE ${_counter})
522 file(APPEND ${FileName} "set(SRCS \${SRCS} \${SRCS${_loop}})\n")
523 EndForEach(_loop RANGE ${_counter})
524 Else(_file_glob)
525 list(LENGTH CXXSRCS_PACKAGE cxx_length)
526 if(${cxx_length} GREATER 0)
527 file(APPEND ${FileName} "set(SRCS\n")
528 foreach(file ${CXXSRCS_PACKAGE})
529 file(APPEND ${FileName} "${file}\n")
530 endforeach(file ${CXXSRCS_PACKAGE})
531 file(APPEND ${FileName} ")\n\n")
532 endif(${cxx_length} GREATER 0)
533 EndIf(_file_glob)
534
535 list(LENGTH CSRCS_PACKAGE c_length)
536 if(${c_length} GREATER 0)
537 set(AddCSource TRUE)
538 file(APPEND ${FileName} "set(CSRCS\n")
539 foreach(file ${CSRCS_PACKAGE})
540 file(APPEND ${FileName} "${file}\n")
541 endforeach(file ${CSRCS_PACKAGE})
542 file(APPEND ${FileName} ")\n\n")
543 endif(${c_length} GREATER 0)
544
545 list(LENGTH FSRCS_PACKAGE f_length)
546 if(${f_length} GREATER 0)
547 set(AddFortranSource TRUE)
548 file(APPEND ${FileName} "set(FSRCS\n")
549 foreach(file ${FSRCS_PACKAGE})
550 file(APPEND ${FileName} "${file}\n")
551 endforeach(file ${FSRCS_PACKAGE})
552 file(APPEND ${FileName} ")\n\n")
553 endif(${f_length} GREATER 0)
554
555
556 if(ADD_HEADERS)
557 file(APPEND ${FileName} "# fill list of header files from list of source files\n")
558 file(APPEND ${FileName} "# by exchanging the file extension\n")
559
560 file(APPEND ${FileName} "String(REPLACE \".cxx\" \".h\" HDRS \"\${SRCS}\")\n\n")
561 list(LENGTH HDRS_PACKAGE _length)
562 if(${_length} GREATER 0)
563 file(APPEND ${FileName} "set(HDRS \${HDRS}\n")
564 foreach(file ${HDRS_PACKAGE})
565 file(APPEND ${FileName} "${file}\n")
566 endforeach(file ${HDRS_PACKAGE})
567 file(APPEND ${FileName} ")\n\n")
568 endif(${_length} GREATER 0)
569 else(ADD_HEADERS)
570 list(LENGTH HDRS_PACKAGE _length)
571 if(${_length} GREATER 0)
572 file(APPEND ${FileName} "set(HDRS\n")
573 foreach(file ${HDRS_PACKAGE})
574 file(APPEND ${FileName} "${file}\n")
575 endforeach(file ${HDRS_PACKAGE})
576 file(APPEND ${FileName} ")\n\n")
577 endif(${_length} GREATER 0)
578 endif(ADD_HEADERS)
579
580 If(AddCSource)
581 file(APPEND ${FileName} "Set(SRCS \${SRCS} \${CSRCS})\n\n")
582 EndIf(AddCSource)
583 If(AddFortranSource)
584 file(APPEND ${FileName} "Set(SRCS \${SRCS} \${FSRCS})\n\n")
585 EndIf(AddFortranSource)
586
587 list(LENGTH PACKFFLAGS_PACKAGE packf_length)
588 if(${packf_length} GREATER 0)
589 file(APPEND ${FileName} "SET_SOURCE_FILES_PROPERTIES(\n")
590 file(APPEND ${FileName} "${FSRCS} PROPERTIES COMPILE_FLAGS\n")
591 file(APPEND ${FileName} "${PACKFFLAGS_PACKAGE}\n")
592 file(APPEND ${FileName} ")\n\n")
593 endif(${packf_length} GREATER 0)
594
595
596 file(APPEND ${FileName} "AddLibrary(${_lib} \"\${SRCS}\" \"\${HDRS}\")\n")
597
598
599 # If package file is empty remove the CMake input file for that packge and
600 # remove the package from the list.
601# If( ${cxx_length} EQUAL 0 AND ${c_length} EQUAL 0 AND ${f_length} EQUAL 0)
602# file(REMOVE ${FileName})
603# list(REMOVE_ITEM PACKAGES lib${_lib})
604# EndIf( ${cxx_length} EQUAL 0 AND ${c_length} EQUAL 0 AND ${f_length} EQUAL 0)
605
606EndMacro(CreateLibPackageFile path lib)
607
608Macro(CreateBinPackageFile path bin)
609
610 set(FileName ${path}/CMake_${bin}.txt)
611 STRING(REGEX REPLACE "^bin(.*)" "\\1" _bin "${bin}")
612
613 file(WRITE ${FileName} "# -*- mode: cmake -*-\n\n")
614
615 file(APPEND ${FileName} "set(SRCS)\n\n")
616
617 list(LENGTH CXXSRCS_PACKAGE _length)
618 if(${_length} GREATER 0)
619 file(APPEND ${FileName} "set(SRCS\n")
620 foreach(file ${CXXSRCS_PACKAGE})
621 file(APPEND ${FileName} "${file}\n")
622 endforeach(file ${CXXSRCS_PACKAGE})
623 file(APPEND ${FileName} ")\n\n")
624 endif(${_length} GREATER 0)
625
626 list(LENGTH CSRCS_PACKAGE _length)
627 if(${_length} GREATER 0)
628 file(APPEND ${FileName} "set(CSRCS\n")
629 foreach(file ${CSRCS_PACKAGE})
630 file(APPEND ${FileName} "${file}\n")
631 endforeach(file ${CXXSRCS_PACKAGE})
632 file(APPEND ${FileName} ")\n\n")
633 endif(${_length} GREATER 0)
634
635 list(LENGTH ELIBS_PACKAGE _length)
636 if(${_length} GREATER 0)
637 file(APPEND ${FileName} "set(LIBS\n")
638 foreach(file ${ELIBS_PACKAGE})
639 file(APPEND ${FileName} "${file}\n")
640 endforeach(file ${ELIBS_PACKAGE})
641 file(APPEND ${FileName} ")\n\n")
642 endif(${_length} GREATER 0)
643
644 file(APPEND ${FileName} "AddExecutable(${_bin}exe \"\${SRCS}\" \"\${LIBS}\")\n")
645EndMacro(CreateBinPackageFile path bin)
646
647Macro(SpecialSettingsMadeByHand lib)
648 If(${lib} STREQUAL libAliengui)
649 list(REMOVE_ITEM CXXSRCS_PACKAGE Aliengui/AliAnalysisGUIdummy.cxx)
650 EndIf(${lib} STREQUAL libAliengui)
651# If(${lib} STREQUAL libTPCmon)
652# list(REMOVE_ITEM CXXSRCS_PACKAGE AliTPCMonitorDateMonitor.cxx)
653# list(REMOVE_ITEM HDRS_PACKAGE AliTPCMonitorDateMonitor.h)
654# EndIf(${lib} STREQUAL libTPCmon)
655 If(${lib} STREQUAL libRAWDatabase)
656 list(APPEND HDRS_PACKAGE \${ROOT_INCLUDE_DIR}/TH1F.h)
657 list(APPEND H_PACKAGE \${ROOT_INCLUDE_DIR}/TH1F.h)
658 EndIf(${lib} STREQUAL libRAWDatabase)
659 If(${lib} STREQUAL liblhapdf)
660# STRING(REGEX REPLACE "[=]" "\\\\=" PACKCXXFLAGS "${PACKCXXFLAGS}")
661# STRING(REGEX REPLACE "[$][(]ALICE_ROOT[)]" "\$ENV{ALICE_ROOT}" PACKCXXFLAGS "${PACKCXXFLAGS}")
662 EndIf(${lib} STREQUAL liblhapdf)
7f40fabf 663EndMacro(SpecialSettingsMadeByHand lib)