Fixes for #77589, Setting optimisation with cmake (Natalia)
[u/mrichter/AliRoot.git] / cmake / ALICE_CMake.cmake
1 # -*- mode: cmake -*-
2
3 # AliRoot Build System Utility Macro and Function definitions
4 #
5 # Author: Johny Jose (johny.jose@cern.ch)
6 #         Port of previous Makefile build to cmake
7
8 cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
9
10 macro(ALICE_DevFlagsOutput)
11
12   if(ALICEDEV STREQUAL "YES")
13     message(STATUS "FFLAGS    : ${FFLAGS}")
14     message(STATUS "CXXFLAGS  : ${CXXFLAGS}")
15     message(STATUS "CFLAGS    : ${CFLAGS}")
16     message(STATUS "SOFLAGS   : ${SOFLAGS}")
17     message(STATUS "LDFLAGS   : ${LDFLAGS}")
18     message(STATUS "SHLIB     : ${SHLIB}")
19     message(STATUS "SYSLIBS   : ${SYSLIBS}")
20     message(STATUS "CINTFLAGS : ${CINTFLAGS}")
21   endif(ALICEDEV STREQUAL "YES")
22
23 endmacro(ALICE_DevFlagsOutput)
24
25 function(ALICE_CleanOutput _output input)
26
27   string(REGEX REPLACE "\n" " " clean "${input}")
28   set(${_output} ${clean} PARENT_SCOPE)
29
30 endfunction(ALICE_CleanOutput)
31
32 function(ALICE_CorrectPaths _output value )
33
34   set(corrected)
35   foreach(path ${value})
36     set(external)
37     string(REGEX MATCH "^/" external "${path}")
38     if(NOT external)
39       list(APPEND corrected "${CMAKE_SOURCE_DIR}/${path}" )
40     else()
41       list(APPEND corrected "${path}")
42     endif(NOT external)
43   endforeach(path)
44   set(${_output} ${corrected} PARENT_SCOPE)
45
46 endfunction(ALICE_CorrectPaths)
47
48 function(ALICE_Format _output prefix suffix input)
49
50 # DevNotes - input should be put in quotes or the complete list does not get passed to the function
51   set(format)
52   foreach(arg ${input})
53     set(item ${arg})
54     if(prefix)
55       string(REGEX MATCH "^${prefix}" pre "${arg}")
56     endif(prefix)
57     if(suffix)
58       string(REGEX MATCH "${suffix}$" suf "${arg}")
59     endif(suffix)
60     if(NOT pre)
61       set(item "${prefix}${item}")
62     endif(NOT pre)
63     if(NOT suf)
64       set(item "${item}${suffix}")
65     endif(NOT suf)
66     list(APPEND format ${item})
67   endforeach(arg)
68   set(${_output} ${format} PARENT_SCOPE)
69
70 endfunction(ALICE_Format)
71
72 function(ALICE_CheckLibraries _output input)
73
74   set(format)
75   foreach(arg ${input})
76     set(item ${arg})
77     string(REGEX MATCH "^(/|-)" preformatted "${item}")
78     if(NOT preformatted)
79       set(item "-l${item}")
80     endif(NOT preformatted)
81     list(APPEND format ${item})
82   endforeach(arg)
83   set(${_output} ${format} PARENT_SCOPE)
84   
85 endfunction(ALICE_CheckLibraries)
86
87 function(ALICE_RootConfig _output parameters)
88
89   if(ROOT_CONFIG)
90     execute_process(COMMAND ${ROOT_CONFIG} ${parameters} OUTPUT_VARIABLE result ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
91     if(error)
92       message(FATAL_ERROR "root-config ERROR : ${error}")
93     endif(error)
94     ALICE_CleanOutput(result "${result}")
95     set(${_output} "${result}" PARENT_SCOPE)
96   else()
97     message(FATAL_ERROR "root-config not found")
98   endif(ROOT_CONFIG)
99
100 endfunction(ALICE_RootConfig)
101
102 macro(ALICE_CheckOutOfSourceBuild)
103   
104   #Check if previous in-source build failed
105   if(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt OR EXISTS ${CMAKE_SOURCE_DIR}/CMakeFiles)
106     message(FATAL_ERROR "CMakeCache.txt or CMakeFiles exists in source directory! Please remove them before running cmake $ALICE_ROOT")
107   endif(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt OR EXISTS ${CMAKE_SOURCE_DIR}/CMakeFiles)
108   
109   #Get Real Paths of the source and binary directories
110   get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
111   get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
112   
113   #Check for in-source builds
114   if(${srcdir} STREQUAL ${bindir})
115     message(FATAL_ERROR "AliRoot cannot be built in-source! Please run cmake $ALICE_ROOT outside the source directory")
116   endif(${srcdir} STREQUAL ${bindir})
117
118 endmacro(ALICE_CheckOutOfSourceBuild)
119
120 macro(ALICE_ConfigureCompiler)
121
122   if(ALIPROFILE STREQUAL "YES")
123     set(ALICE_TARGET ${ALICE_TARGET}PROF)
124     set(FFLAGS "-pg ${FFLAGS}")
125     set(CXXFLAGS "-pg ${CXXFLAGS}")
126     set(CFLAGS "-pg ${CFLAGS}")
127     set(SOFLAGS "-pg ${SOFLAGS}")
128     set(LDFLAGS "-pg ${LDFLAGS}")
129   endif(ALIPROFILE STREQUAL "YES")
130
131   ALICE_RootConfig(RCFLAGS --auxcflags)
132   ALICE_RootConfig(RLFLAGS --ldflags)
133
134   set(CXXFLAGS "${CXXFLAGS} ${RCFLAGS}")
135   set(CFLAGS  "${CFLAGS} ${RCFLAGS}")
136   set(SOFLAGS "${SOFLAGS} ${RLFLAGS}")
137   set(LDFLAGS "${LDFLAGS} ${RLFLAGS}")
138
139   if(NOT ALICXXWARN STREQUAL "NO")
140     set(CXXFLAGS "${CXXFLAGS} ${CXXWARN}")
141   endif(NOT ALICXXWARN STREQUAL "NO")
142
143   set(CXXFLAGS "${DATEFLAGS} ${CXXFLAGS}")
144   set(CFLAGS "${DATEFLAGS} ${CFLAGS}")
145   set(CINTFLAGS "${DATEFLAGS}")
146
147 endmacro(ALICE_ConfigureCompiler)
148
149 macro(ALICE_ConfigurePlatform)
150   
151   ALICE_GetTarget()
152   include("CMake${ALICE_TARGET}")
153   
154 endmacro(ALICE_ConfigurePlatform)
155
156 macro(ALICE_GetTarget)
157   
158   #Set ALICE_TARGET if it has not been set yet
159   if(NOT ALICE_TARGET)  
160     set(ALICE_TARGET $ENV{ALICE_TARGET})
161     #If ALICE_TARGET is not defined assign default values
162     if(NOT ALICE_TARGET)
163       message(WARNING "Environment variable ALICE_TARGET is not set ! Setting to default value.")
164       ALICE_RootConfig(ALICE_TARGET --arch)
165       message("ALICE_TARGET set to ${ALICE_TARGET}")
166     endif(NOT ALICE_TARGET)
167   endif(NOT ALICE_TARGET)
168
169 endmacro(ALICE_GetTarget) 
170
171 macro(ALICE_ResetPackage)
172
173   set(MODDIR ${MODULE})
174   set(MODDIRI ${PROJECT_SOURCE_DIR}/${MODULE})
175
176   set(SRCS)
177   set(HDRS)
178   set(FSRCS)
179   set(DHDR)
180   set(CSRCS)
181   set(CHDRS)
182   set(EINCLUDE)
183   set(EDEFINE)
184   set(ELIBS)
185   set(ELIBSDIR)
186   set(PACKFFLAGS)
187   set(PACKCXXFLAGS)
188   set(PACKCFLAGS)
189   set(PACKDYFLAGS)
190   set(PACKSOFLAGS)
191   set(PACKLDFLAGS)
192   set(PACKBLIBS)
193   set(EXPORT)
194   set(EHDRS)
195   set(CINTHDRS)
196   set(CINTAUTOLINK)
197   set(ARLIBS)
198   set(SHLIBS)
199
200   #HLT Variables
201   set(MODULE_HDRS)
202   set(MODULE_SRCS)
203   set(MODULE_DHDR)
204   set(CLASS_HDRS)
205   set(LIBRARY_DEP)
206   set(HLTDEFS)
207   set(HLTSOFLAGS) 
208
209
210   set(PSRCS)
211   set(PHDRS)
212   set(PFSRCS)
213   set(PDHDR)
214   set(PCSRCS)
215   set(PCHDRS)
216   set(PEINCLUDE)
217   set(PEDEFINE)
218   set(PELIBS)
219   set(PELIBSDIR)
220   set(PPACKFFLAGS)
221   set(PPACKCXXFLAGS)
222   set(PPACKCFLAGS)
223   set(PPACKDYFLAGS)
224   set(PPACKSOFLAGS)
225   set(PPACKLDFLAGS)
226   set(PPACKBLIBS)
227   set(PEXPORT)
228   set(PEHDRS)
229   set(PCINTHDRS)
230   set(PCINTAUTOLINK)
231   set(PARLIBS)
232   set(PSHLIBS)
233   set(PDS)
234
235 endmacro(ALICE_ResetPackage)
236
237 function(ALICE_SetPackageVariable _var ext setvalue unsetvalue )
238
239 #DevNotes - setvalue and unsetcalue should both be put in quotes or cmake throws an error if they have undefined values
240   if(setvalue)
241     set(${_var} ${setvalue} PARENT_SCOPE)
242     set(${PACKAGE}${ext} ${setvalue} PARENT_SCOPE)
243   else()
244     set(${_var} ${unsetvalue} PARENT_SCOPE)
245     set(${PACKAGE}${ext} ${unsetvalue} PARENT_SCOPE)
246   endif(setvalue)
247
248 endfunction(ALICE_SetPackageVariable)
249
250 macro(ALICE_BuildPackage)
251  
252   list(APPEND EINCLUDE STEER) 
253
254   ALICE_SetPackageVariable(PFFLAGS "FFLAGS" "${PACKFFLAGS}" "${FFLAGS}")
255   ALICE_SetPackageVariable(PCFLAGS "CFLAGS" "${PACKCFLAGS}" "${CFLAGS}")
256   ALICE_SetPackageVariable(PCXXFLAGS "CXXFLAGS" "${PACKCXXFLAGS}" "${CXXFLAGS}")
257   ALICE_SetPackageVariable(PSOFLAGS "SOFLAGS" "${PACKSOFLAGS}" "${SOFLAGS}")
258   ALICE_SetPackageVariable(PLDFLAGS "LDFLAGS" "${PACKLDFLAGS}" "${LDFLAGS}")
259   ALICE_SetPackageVariable(PDCXXFLAGS "DCXXFLAGS" "${PACKDCXXFLAGS}" "${CXXFLAGSNO}")
260   ALICE_SetPackageVariable(PBLIBS "BLIBS" "${PACKBLIBS}" "${LIBS}")
261
262   set(WITHDICT)
263   if(DHDR OR CINTAUTOLINK)
264     set(WITHDICT TRUE)
265   endif(DHDR OR CINTAUTOLINK)
266
267   ALICE_SetPackageVariable(PEDEFINE "EDEFINE" "${EDEFINE}" "${EDEFINE}")
268   ALICE_SetPackageVariable(PEXPORT "EXPORT" "${EXPORT}" "${EXPORT}")
269   ALICE_SetPackageVariable(PEXPORTDEST "EXPORTDEST" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
270   ALICE_SetPackageVariable(PINC "INC" "${EINCLUDE};${MODULE}" "${EINCLUDE};${MODULE}")
271   ALICE_SetPackageVariable(PELIBS "ELIBS" "${ELIBS}" "${ELIBS}")
272   ALICE_SetPackageVariable(PELIBSDIR "ELIBSDIR" "${ELIBSDIR}" "${ELIBSDIR}")
273   
274   ALICE_SetPackageVariable(PCS "CS" "${CSRCS}" "${CSRCS}")
275   ALICE_SetPackageVariable(PCH "CH" "${CHDRS}" "${CHDRS}")
276   
277   ALICE_SetPackageVariable(PFS "FS" "${FSRCS}" "${FSRCS}")
278
279   ALICE_SetPackageVariable(PS "S" "${SRCS}" "${SRCS}")
280   ALICE_SetPackageVariable(PH "H" "${HDRS} ${EHDRS}" "${HDRS} ${EHDRS}")
281   ALICE_SetPackageVariable(PCINTHDRS "CINTHDRS" "${CINTHDRS}" "${PH}")
282   
283   string( REPLACE ".h" "" PCINTCLASSES "${PCINTHDRS}")
284   set ( ${PACKAGE}CINTCLASSES ${PCINTCLASSES})
285
286   ALICE_SetPackageVariable(PDH "DH" "${DHDR}" "")
287
288   if(CINTAUTOLINK)
289     ALICE_SetPackageVariable(PDAL "DAL" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h")
290     ALICE_SetPackageVariable(PDH "DH" "${PDAL}" "${PDAL}")
291     ALICE_GenerateLinkDef()
292   endif(CINTAUTOLINK)
293
294   if(lib)
295     list(APPEND PMLIBS ${PACKAGE})
296     list(APPEND ALLLIBS ${PACKAGE})
297     list(APPEND PMALIBS ${PACKAGE}-static)
298     list(APPEND ALLALIBS ${PACKAGE}-static)
299     list(APPEND BINLIBS ${PACKAGE})
300   else()
301     list(APPEND ALLEXECS ${PACKAGE})
302   endif(lib)
303   set(${MODULE}ALIBS "${PMALIBS}" PARENT_SCOPE)
304   set(${MODULE}LIBS "${PMLIBS}" PARENT_SCOPE)
305   set(${MODULE}INC "${EINCLUDE}" PARENT_SCOPE)
306   list(APPEND INCLUDEFILES ${PEXPORTDEST})
307   if(WITHDICT)  
308     ALICE_SetPackageVariable(PDS "DS" "G__${PACKAGE}.cxx" "G__${PACKAGE}.cxx")
309     ALICE_GenerateDictionary()
310   else()
311     if(lib)
312       message(STATUS "No dictionary generated for ${PACKAGE}")  
313     endif(lib)
314   endif(WITHDICT)
315   if(PS OR PCS OR PFS)
316     if(lib)
317       ALICE_BuildLibrary()
318     elseif(bin)
319       ALICE_BuildExecutable()
320     endif(lib)
321   endif(PS OR PCS OR PFS)
322   ALICE_CopyHeaders()
323   ALICE_BuildPAR()
324
325 endmacro(ALICE_BuildPackage)
326
327
328 macro(ALICE_BuildModule)
329
330   add_definitions(-D_MODULE="${MODULE}")
331   foreach(PACKAGEFILE ${PACKAGES})
332       set(lib)
333       set(bin)
334       string(REGEX MATCH "CMakelib" lib "${PACKAGEFILE}")
335       string(REGEX MATCH "CMakebin" bin "${PACKAGEFILE}")
336       get_filename_component(PACKAGE ${PACKAGEFILE} NAME)
337       string(REGEX REPLACE "^CMake(lib|bin)(.*)\\.pkg" "\\2" PACKAGE "${PACKAGE}")
338       if(ALICEDEV)
339         message("Adding package ${PACKAGE} in ${MODULE}")
340       endif(ALICEDEV)
341       ALICE_ResetPackage()
342       include(${PACKAGEFILE})
343       ALICE_BuildPackage()
344      
345       get_property(EXCLUDEPACKAGE TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL) 
346       if(NOT EXCLUDEPACKAGE)
347         install(TARGETS ${PACKAGE} 
348                 RUNTIME DESTINATION bin/tgt_${ALICE_TARGET}
349                 LIBRARY DESTINATION lib/tgt_${ALICE_TARGET}
350                 ARCHIVE DESTINATION bin/tgt_${ALICE_TARGET})
351       endif(NOT EXCLUDEPACKAGE)
352   endforeach(PACKAGEFILE)
353   ALICE_CheckModule()
354 endmacro(ALICE_BuildModule)
355
356 macro(ALICE_GenerateDictionary)
357  
358   if(ALICEDEV STREQUAL "YES")
359     message("Generating Dictionary rule for ${PACKAGE}")
360     message("${ROOTCINT} -f ${PDS} -c ${PEDEFINE} ${CINTFLAGS} ${PINC} ${PCINTHDRS} ${PDH}")
361   endif(ALICEDEV STREQUAL "YES")
362  
363   # Split up all arguments
364
365   set(DEDEFINE ${PEDEFINE})
366   set(DCINTFLAGS ${CINTFLAGS})
367   set(DINC ${PINC})
368   set(DCINTHDRS ${PCINTHDRS})
369   set(DDH ${PDH})
370   separate_arguments(DEDEFINE)
371   separate_arguments(DCINTFLAGS)
372   separate_arguments(DINC)
373   separate_arguments(DCINTHDRS)
374   separate_arguments(DDH)
375   # Format neccesary arguments
376   ALICE_Format(DINC "-I" "" "${DINC};${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
377   set_source_files_properties(${PDS} PROPERTIES GENERATED TRUE)
378   set_source_files_properties(${PDS} PROPERTIES COMPILE_FLAGS "-w")
379   add_custom_command(OUTPUT  ${PDS}
380                      COMMAND cd ${PROJECT_SOURCE_DIR} && ${ROOTCINT} -f ${CMAKE_CURRENT_BINARY_DIR}/${PDS} -c -D_MODULE=\\\"${MODULE}\\\" ${DEDEFINE} ${DCINTFLAGS} ${DINC} ${DCINTHDRS} ${DDH}
381                      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
382                      DEPENDS ${DCINTHDRS} ${DDH}
383                      )
384   add_custom_target(G${PACKAGE})
385   add_dependencies(G${PACKAGE} ${PDS})
386
387 endmacro(ALICE_GenerateDictionary)
388
389 macro(ALICE_BuildLibrary)
390
391   ALICE_DevFlagsOutput()
392   set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS}")
393   set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS}")
394   set(CMAKE_Fortran_FLAGS ${PEDEFINE} ${PFFLAGS})
395   set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS}) 
396   set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
397   
398   
399   separate_arguments(PINC)
400   separate_arguments(EINCLUDE)
401   separate_arguments(PELIBSDIR)
402   separate_arguments(PBLIBS)
403   separate_arguments(PELIBS)
404   separate_arguments(SHLIB)
405
406   ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
407   ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
408
409   ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
410   ALICE_CorrectPaths(PINC "${PINC}")
411
412   include_directories(SYSTEM ${ROOTINCDIR})
413   include_directories(${PINC})  
414   include_directories(${EINCLUDE})
415   include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
416   
417   add_library(${PACKAGE} SHARED ${PCS} ${PFS} ${PS} ${PDS})
418   set_target_properties(${PACKAGE} PROPERTIES SUFFIX .so)  
419   
420
421   if(PELIBS OR SHLIB)
422     target_link_libraries(${PACKAGE} ${PELIBSDIR} ${PELIBS} ${SHLIB})
423   endif(PELIBS OR SHLIB)
424   
425   add_dependencies(${MODULE}-all ${PACKAGE})
426      
427   add_library(${PACKAGE}-static STATIC EXCLUDE_FROM_ALL ${PCS} ${PFS} ${PS} ${PDS})
428   set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME ${PACKAGE})
429   if(PELIBS OR ALLIB)
430     target_link_libraries(${PACKAGE}-static ${PELIBSDIR} ${PELIBS} ${ALLIB})
431   endif(PELIBS OR ALLIB)
432
433   add_dependencies(${MODULE}-all-static ${PACKAGE}-static)
434   if(ALIPROFILE STREQUAL "YES")
435     add_dependencies(${MODULE}-all ${MODULE}-static)
436   endif(ALIPROFILE STREQUAL "YES")
437
438   list(FIND EXCLUDEMODULES ${MODULE} RESULT)
439   if(NOT RESULT STREQUAL "-1")
440     message(STATUS "${MODULE} will not be built by default. Type make ${MODULE}-all to build.")
441     set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
442   endif(NOT RESULT STREQUAL "-1")
443
444   set_target_properties(${PACKAGE} PROPERTIES INSTALL_NAME_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
445
446 endmacro(ALICE_BuildLibrary)
447
448 macro(ALICE_BuildExecutable)
449
450   ALICE_DevFlagsOutput()
451   set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS} ${EXEFLAGS}")
452   set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS} ${EXEFLAGS}")
453   set(CMAKE_Fortran_FLAGS "${PEDEFINE} ${PFFLAGS} ${EXEFLAGS}")
454   set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS}) 
455   set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
456   
457   separate_arguments(PINC)
458   separate_arguments(EINCLUDE)
459   separate_arguments(PELIBSDIR)
460   separate_arguments(PBLIBS)
461   separate_arguments(PELIBS)
462   separate_arguments(SHLIB)
463   
464   ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
465   ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
466
467   ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
468   ALICE_CorrectPaths(PINC "${PINC}")
469
470   include_directories(SYSTEM ${ROOTINCDIR})
471   include_directories(${PINC})  
472   include_directories(${EINCLUDE})
473   include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
474
475   if(ALIPROFILE STREQUAL "YES")
476     add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
477     if(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
478       target_link_libraries(${PACKAGE} ${ARLIBS} ${SHLIBS} ${PBLIBS} ${EXEFLAGS})
479     endif(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
480     add_dependencies(${MODULE}-all ${PACKAGE})
481   else()
482     add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
483     if(PELIBS OR PBLIBS OR EXEFLAGS)
484       target_link_libraries(${PACKAGE} ${BINLIBDIRS} ${PELIBSDIR} ${PELIBS} ${PBLIBS} ${EXEFLAGS})
485     endif(PELIBS OR PBLIBS OR EXEFLAGS)
486     add_dependencies(${MODULE}-all ${PACKAGE})
487   endif(ALIPROFILE STREQUAL "YES")
488
489 # AliMDC
490 # ------------------------------
491   if(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
492
493     add_executable(${PACKAGE}-static ${PFS} ${PCS} ${PS} ${PDS})
494     set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME alimdca)
495     add_custom_target( libAliMDC
496                         COMMAND rm -rf ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a
497                         COMMAND rm -rf junkmdc
498                         COMMAND mkdir junkmdc && cd junkmdc && ar x ../libRAWDatabase.a && ar x ../libMDC.a && ar x ../libESD.a && ar x ../libSTEERBase.a && ar r ../libAliMDC.a *.o && cd .. && rm -rf junkmdc
499                         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
500     add_custom_target( root-static-libs 
501                        COMMAND make static
502                        WORKING_DIRECTORY ${ROOTSYS} )
503                        
504     add_dependencies(libAliMDC RAWDatabase-static STEERBase-static MDC-static ESD-static)
505     add_dependencies(${PACKAGE}-static libAliMDC root-static-libs)
506     target_link_libraries(${PACKAGE}-static ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${ROOTLIBDIR}/libRoot.a ${ROOTLIBDIR}/libfreetype.a ${ROOTLIBDIR}/libpcre.a -pthread -ldl -lcurses)
507
508     install(TARGETS ${PACKAGE}-static RUNTIME DESTINATION bin/tgt_${ALICE_TARGET} COMPONENT MDC)
509     install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${ROOTLIBDIR}/libRoot.a ${ROOTLIBDIR}/libfreetype.a ${ROOTLIBDIR}/libpcre.a DESTINATION lib/tgt_${ALICE_TARGET} COMPONENT MDC)
510     install(FILES ${PROJECT_SOURCE_DIR}/RAW/mdc.h DESTINATION include COMPONENT MDC)
511     set(CPACK_RPM_PACKAGE_SUMMARY "AliMDC static libraries")
512     set(CPACK_RPM_PACKAGE_NAME "alimdc")
513     set(CPACK_RPM_PACKAGE_VERSION "${ALIMDCVERSION}")
514     set(CPACK_RPM_PACKAGE_RELEASE "${ALIMDCRELEASE}")
515     set(CPACK_RPM_PACKAGE_LICENSE "License: CERN ALICE Off-line Group")
516     set(CPACK_RPM_PACKAGE_VENDOR "ALICE Core Off-line Group")
517     set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AliMDC static libraries")
518     set(CPACK_RPM_PACKAGE_GROUP "Applications/Alice")
519     set(CPACK_RPM_PACKAGE_REQUIRES "glibc")
520     set(CPACK_PACKAGE_VERSION "1.0.0")
521     set(CPACK_PACKAGE_VERSION_MAJOR "1")
522     set(CPACK_PACKAGE_VERSION_MINOR "0")
523     set(CPACK_PACKAGE_VERSION_PATCH "0")
524     set(CPACK_PACKAGE_INSTALL_DIRECTORY "/opt/")
525     add_component_package(MDC alimdc-rpm)
526
527   endif(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
528
529   list(FIND EXCLUDEMODULES ${MODULE} RESULT)
530   if(NOT RESULT STREQUAL "-1")
531     set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
532   endif(NOT RESULT STREQUAL "-1")
533
534 endmacro(ALICE_BuildExecutable)
535
536 macro(ALICE_CopyHeaders)
537   
538   if(EXPORT )
539     set(HEADERS ${EXPORT})
540     set(_headersdep)
541     foreach(header ${HEADERS})
542       add_custom_command(OUTPUT ${PEXPORTDEST}/${header}
543                          COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/${MODULE}/${header} ${PEXPORTDEST}/${header}
544                          DEPENDS ${CMAKE_SOURCE_DIR}/${MODULE}/${header})
545       list(APPEND _headersdep ${PEXPORTDEST}/${header})
546       install(FILES ${header} DESTINATION include)
547     endforeach(header)
548     add_custom_target(${PACKAGE}-headers DEPENDS ${_headersdep})
549     add_dependencies(${PACKAGE} ${PACKAGE}-headers)
550   endif(EXPORT)
551
552 endmacro(ALICE_CopyHeaders)
553
554 macro(ALICE_GenerateLinkDef)
555
556   file (WRITE ${PDAL} "//--------------------------------------------------------------------------------\n")
557   file (APPEND ${PDAL} "// This is an automatically generated Root Dictionary Linkdef file for ${PACKAGE}\n")
558   file (APPEND ${PDAL} "// !!! DO NOT EDIT THIS FILE !!!\n")
559   file (APPEND ${PDAL} "#ifdef __CINT__\n")
560   file (APPEND ${PDAL} "#pragma link off all globals;\n")
561   file (APPEND ${PDAL} "#pragma link off all classes;\n")
562   file (APPEND ${PDAL} "#pragma link off all functions;\n")
563   foreach (class ${PCINTCLASSES})
564     get_filename_component(classname ${class} NAME)
565     file(APPEND ${PDAL} "#pragma link C++ class ${classname}+;\n")
566   endforeach(class)
567   file (APPEND ${PDAL} "#endif\n")
568 endmacro(ALICE_GenerateLinkDef)
569
570 macro(ALICE_BuildPAR)
571   
572   if(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
573     set(PARSRCS)
574     foreach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
575       get_filename_component(srcdir ${file} PATH)
576       add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par                         
577                          COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${srcdir}
578                          COMMAND cp -pR ${file} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}
579                          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
580       list(APPEND PARSRCS ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par)
581     endforeach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
582     
583     add_custom_target(${PACKAGE}.par
584                       COMMAND sed -e 's/include .\(ROOTSYS\)\\/test\\/Makefile.arch/include Makefile.arch/\; s/PACKAGE = .*/PACKAGE = ${PACKAGE}/\; s,SRCS *=.*,SRCS = ${SRCS},\;' < Makefile | sed -e 's,HDRS *=.*,HDRS = ${HDRS},\; s,FSRCS *=.*,FSRCS = ${FSRCS},\; s,DHDR *=.*,DHDR = ${DHDR},' > ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/Makefile
585                       COMMAND cp -pR ${ROOTSYS}/test/Makefile.arch ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/Makefile.arch
586                       COMMAND cp -pR PROOF-INF.${PACKAGE} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/PROOF-INF
587 #                      COMMAND cp -pR lib${PACKAGE}.pkg ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
588                       COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} tar --exclude=.svn -czhf ${CMAKE_BINARY_DIR}/${PACKAGE}.par ${PACKAGE}
589                       COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
590                       COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red --bold "${PACKAGE}.par has been created in ${CMAKE_BINARY_DIR}"
591                       DEPENDS ${PARSRCS} 
592                       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
593
594
595     add_dependencies(${PACKAGE}.par ${SRCS} ${FSRCS} ${HDRS} ${DHDR})
596     add_dependencies(par-all ${PACKAGE}.par)
597     add_dependencies(${MODULE}-par-all ${PACKAGE}.par)
598
599     add_custom_target(test-${PACKAGE}.par
600                       COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red --bold "The file ${PACKAGE}.par is now being tested, in case of an error check in par-tmp/${PACKAGE}."
601                       COMMAND ${CMAKE_COMMAND} -E make_directory par-tmp
602                       COMMAND ${CMAKE_COMMAND} -E chdir par-tmp tar xfz ../${PACKAGE}.par && ${CMAKE_COMMAND} -E chdir par-tmp/${PACKAGE} PROOF-INF/BUILD.sh
603                       COMMAND ${CMAKE_COMMAND} -E remove_directory par-tmp
604                       COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green --bold "${PACKAGE}.par testing succeeded"
605                       WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
606
607     add_dependencies(test-${PACKAGE}.par ${PACKAGE}.par)
608     add_dependencies(test-par-all test-${PACKAGE}.par)
609     add_dependencies(test-${MODULE}-par-all test-${PACKAGE}.par)
610
611   endif(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
612   # endif(EXISTS ${ALICE_ROOT}/${MODULE}/PROOF-INF.${PACKAGE})
613
614 endmacro(ALICE_BuildPAR)
615