Additional patch for #83850: Please consider deprecating CINTAUTOLINK (Christian)
[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 #  message(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
270   ALICE_SetPackageVariable(PEXPORTDEST "EXPORTDEST" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
271   ALICE_SetPackageVariable(PINC "INC" "${EINCLUDE};${MODULE}" "${EINCLUDE};${MODULE}")
272   ALICE_SetPackageVariable(PELIBS "ELIBS" "${ELIBS}" "${ELIBS}")
273   ALICE_SetPackageVariable(PELIBSDIR "ELIBSDIR" "${ELIBSDIR}" "${ELIBSDIR}")
274   
275   ALICE_SetPackageVariable(PCS "CS" "${CSRCS}" "${CSRCS}")
276   ALICE_SetPackageVariable(PCH "CH" "${CHDRS}" "${CHDRS}")
277   
278   ALICE_SetPackageVariable(PFS "FS" "${FSRCS}" "${FSRCS}")
279
280   ALICE_SetPackageVariable(PS "S" "${SRCS}" "${SRCS}")
281   ALICE_SetPackageVariable(PH "H" "${HDRS} ${EHDRS}" "${HDRS} ${EHDRS}")
282   ALICE_SetPackageVariable(PCINTHDRS "CINTHDRS" "${CINTHDRS}" "${PH}")
283   
284   string( REPLACE ".h" "" PCINTCLASSES "${PCINTHDRS}")
285   set ( ${PACKAGE}CINTCLASSES ${PCINTCLASSES})
286
287   ALICE_SetPackageVariable(PDH "DH" "${DHDR}" "")
288
289   if(CINTAUTOLINK)
290     ALICE_SetPackageVariable(PDAL "DAL" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h")
291     ALICE_SetPackageVariable(PDH "DH" "${PDAL}" "${PDAL}")
292     ALICE_GenerateLinkDef()
293   endif(CINTAUTOLINK)
294
295   if(lib)
296     list(APPEND PMLIBS ${PACKAGE})
297     list(APPEND ALLLIBS ${PACKAGE})
298     list(APPEND PMALIBS ${PACKAGE}-static)
299     list(APPEND ALLALIBS ${PACKAGE}-static)
300     list(APPEND BINLIBS ${PACKAGE})
301   else()
302     list(APPEND ALLEXECS ${PACKAGE})
303   endif(lib)
304   set(${MODULE}ALIBS "${PMALIBS}" PARENT_SCOPE)
305   set(${MODULE}LIBS "${PMLIBS}" PARENT_SCOPE)
306   set(${MODULE}INC "${EINCLUDE}" PARENT_SCOPE)
307   list(APPEND INCLUDEFILES ${PEXPORTDEST})
308   if(WITHDICT)  
309     ALICE_SetPackageVariable(PDS "DS" "G__${PACKAGE}.cxx" "G__${PACKAGE}.cxx")
310     ALICE_GenerateDictionary()
311   else()
312     if(lib)
313       message(STATUS "No dictionary generated for ${PACKAGE}")  
314     endif(lib)
315   endif(WITHDICT)
316   if(PS OR PCS OR PFS)
317     if(lib)
318       ALICE_BuildLibrary()
319     elseif(bin)
320       ALICE_BuildExecutable()
321     endif(lib)
322   endif(PS OR PCS OR PFS)
323   ALICE_CopyHeaders()
324   ALICE_BuildPAR()
325
326 endmacro(ALICE_BuildPackage)
327
328
329 macro(ALICE_BuildModule)
330
331   add_definitions(-D_MODULE_="${MODULE}")
332   foreach(PACKAGEFILE ${PACKAGES})
333       set(lib)
334       set(bin)
335       string(REGEX MATCH "CMakelib" lib "${PACKAGEFILE}")
336       string(REGEX MATCH "CMakebin" bin "${PACKAGEFILE}")
337       get_filename_component(PACKAGE ${PACKAGEFILE} NAME)
338       string(REGEX REPLACE "^CMake(lib|bin)(.*)\\.pkg" "\\2" PACKAGE "${PACKAGE}")
339       if(ALICEDEV)
340         message("Adding package ${PACKAGE} in ${MODULE}")
341       endif(ALICEDEV)
342       ALICE_ResetPackage()
343       include(${PACKAGEFILE})
344       ALICE_BuildPackage()
345      
346       get_property(EXCLUDEPACKAGE TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL) 
347       if(NOT EXCLUDEPACKAGE)
348         install(TARGETS ${PACKAGE} 
349                 RUNTIME DESTINATION bin/tgt_${ALICE_TARGET}
350                 LIBRARY DESTINATION lib/tgt_${ALICE_TARGET}
351                 ARCHIVE DESTINATION bin/tgt_${ALICE_TARGET})
352       endif(NOT EXCLUDEPACKAGE)
353   endforeach(PACKAGEFILE)
354   ALICE_CheckModule()
355 endmacro(ALICE_BuildModule)
356
357 macro(ALICE_GenerateDictionary)
358  
359   if(ALICEDEV STREQUAL "YES")
360     message("Generating Dictionary rule for ${PACKAGE}")
361     message("${ROOTCINT} -f ${PDS} -c ${PEDEFINE} ${CINTFLAGS} ${PINC} ${PCINTHDRS} ${PDH}")
362   endif(ALICEDEV STREQUAL "YES")
363  
364   # Split up all arguments
365
366   set(DEDEFINE ${PEDEFINE})
367   set(DCINTFLAGS ${CINTFLAGS})
368   set(DINC ${PINC})
369   set(DCINTHDRS ${PCINTHDRS})
370   set(DDH ${PDH})
371   separate_arguments(DEDEFINE)
372   separate_arguments(DCINTFLAGS)
373   separate_arguments(DINC)
374   separate_arguments(DCINTHDRS)
375   separate_arguments(DDH)
376   # Format neccesary arguments
377   ALICE_Format(DINC "-I" "" "${DINC};${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
378   set_source_files_properties(${PDS} PROPERTIES GENERATED TRUE)
379   set_source_files_properties(${PDS} PROPERTIES COMPILE_FLAGS "-w")
380   add_custom_command(OUTPUT  ${PDS}
381                      COMMAND cd ${PROJECT_SOURCE_DIR} && ${ROOTCINT} -f ${CMAKE_CURRENT_BINARY_DIR}/${PDS} -c -D_MODULE=\\\"${MODULE}\\\" ${DEDEFINE} ${DCINTFLAGS} ${DINC} ${DCINTHDRS} ${DDH}
382                      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
383                      DEPENDS ${DCINTHDRS} ${DDH}
384                      )
385   add_custom_target(G${PACKAGE})
386   add_dependencies(G${PACKAGE} ${PDS})
387
388 endmacro(ALICE_GenerateDictionary)
389
390 macro(ALICE_BuildLibrary)
391
392   ALICE_DevFlagsOutput()
393   set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS}")
394   set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS}")
395   set(CMAKE_Fortran_FLAGS ${PEDEFINE} ${PFFLAGS})
396   set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS}) 
397   set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
398   
399   
400   separate_arguments(PINC)
401   separate_arguments(EINCLUDE)
402   separate_arguments(PELIBSDIR)
403   separate_arguments(PBLIBS)
404   separate_arguments(PELIBS)
405   separate_arguments(SHLIB)
406
407   ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
408   ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
409
410   ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
411   ALICE_CorrectPaths(PINC "${PINC}")
412
413   include_directories(SYSTEM ${ROOTINCDIR})
414   include_directories(${PINC})  
415   include_directories(${EINCLUDE})
416   include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
417   
418   add_library(${PACKAGE} SHARED ${PCS} ${PFS} ${PS} ${PDS})
419   set_target_properties(${PACKAGE} PROPERTIES SUFFIX .so)  
420   
421
422   if(PELIBS OR SHLIB)
423     target_link_libraries(${PACKAGE} ${PELIBSDIR} ${PELIBS} ${SHLIB})
424   endif(PELIBS OR SHLIB)
425   
426   add_dependencies(${MODULE}-all ${PACKAGE})
427      
428   add_library(${PACKAGE}-static STATIC EXCLUDE_FROM_ALL ${PCS} ${PFS} ${PS} ${PDS})
429   set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME ${PACKAGE})
430   if(PELIBS OR ALLIB)
431     target_link_libraries(${PACKAGE}-static ${PELIBSDIR} ${PELIBS} ${ALLIB})
432   endif(PELIBS OR ALLIB)
433
434   add_dependencies(${MODULE}-all-static ${PACKAGE}-static)
435   if(ALIPROFILE STREQUAL "YES")
436     add_dependencies(${MODULE}-all ${MODULE}-static)
437   endif(ALIPROFILE STREQUAL "YES")
438
439   list(FIND EXCLUDEMODULES ${MODULE} RESULT)
440   if(NOT RESULT STREQUAL "-1")
441     message(STATUS "${MODULE} will not be built by default. Type make ${MODULE}-all to build.")
442     set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
443   endif(NOT RESULT STREQUAL "-1")
444
445   set_target_properties(${PACKAGE} PROPERTIES INSTALL_NAME_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
446
447 endmacro(ALICE_BuildLibrary)
448
449 macro(ALICE_BuildExecutable)
450
451   ALICE_DevFlagsOutput()
452   set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS} ${EXEFLAGS}")
453   set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS} ${EXEFLAGS}")
454   set(CMAKE_Fortran_FLAGS "${PEDEFINE} ${PFFLAGS} ${EXEFLAGS}")
455   set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS}) 
456   set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
457   
458   separate_arguments(PINC)
459   separate_arguments(EINCLUDE)
460   separate_arguments(PELIBSDIR)
461   separate_arguments(PBLIBS)
462   separate_arguments(PELIBS)
463   separate_arguments(SHLIB)
464   
465   ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
466   ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
467
468   ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
469   ALICE_CorrectPaths(PINC "${PINC}")
470
471   include_directories(SYSTEM ${ROOTINCDIR})
472   include_directories(${PINC})  
473   include_directories(${EINCLUDE})
474   include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
475
476   if(ALIPROFILE STREQUAL "YES")
477     add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
478     if(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
479       target_link_libraries(${PACKAGE} ${ARLIBS} ${SHLIBS} ${PBLIBS} ${EXEFLAGS})
480     endif(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
481     add_dependencies(${MODULE}-all ${PACKAGE})
482   else()
483     add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
484     if(PELIBS OR PBLIBS OR EXEFLAGS)
485       target_link_libraries(${PACKAGE} ${BINLIBDIRS} ${PELIBSDIR} ${PELIBS} ${PBLIBS} ${EXEFLAGS})
486     endif(PELIBS OR PBLIBS OR EXEFLAGS)
487     add_dependencies(${MODULE}-all ${PACKAGE})
488   endif(ALIPROFILE STREQUAL "YES")
489
490 # AliMDC
491 # ------------------------------
492   if(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
493
494     add_executable(${PACKAGE}-static ${PFS} ${PCS} ${PS} ${PDS})
495     set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME alimdca)
496     add_custom_target( libAliMDC
497                         COMMAND rm -rf ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a
498                         COMMAND rm -rf junkmdc
499                         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
500                         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
501     add_custom_target( root-static-libs 
502                        COMMAND make static
503                        WORKING_DIRECTORY ${ROOTSYS} )
504                        
505     add_dependencies(libAliMDC RAWDatabase-static STEERBase-static MDC-static ESD-static)
506     add_dependencies(${PACKAGE}-static libAliMDC root-static-libs)
507     target_link_libraries(${PACKAGE}-static ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${ROOTLIBDIR}/libRoot.a ${ROOTLIBDIR}/libfreetype.a ${ROOTLIBDIR}/libpcre.a -pthread -ldl -lcurses)
508
509     install(TARGETS ${PACKAGE}-static RUNTIME DESTINATION bin/tgt_${ALICE_TARGET} COMPONENT MDC)
510     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)
511     install(FILES ${PROJECT_SOURCE_DIR}/RAW/mdc.h DESTINATION include COMPONENT MDC)
512     set(CPACK_RPM_PACKAGE_SUMMARY "AliMDC static libraries")
513     set(CPACK_RPM_PACKAGE_NAME "alimdc")
514     set(CPACK_RPM_PACKAGE_VERSION "${ALIMDCVERSION}")
515     set(CPACK_RPM_PACKAGE_RELEASE "${ALIMDCRELEASE}")
516     set(CPACK_RPM_PACKAGE_LICENSE "License: CERN ALICE Off-line Group")
517     set(CPACK_RPM_PACKAGE_VENDOR "ALICE Core Off-line Group")
518     set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AliMDC static libraries")
519     set(CPACK_RPM_PACKAGE_GROUP "Applications/Alice")
520     set(CPACK_RPM_PACKAGE_REQUIRES "glibc")
521     set(CPACK_PACKAGE_VERSION "1.0.0")
522     set(CPACK_PACKAGE_VERSION_MAJOR "1")
523     set(CPACK_PACKAGE_VERSION_MINOR "0")
524     set(CPACK_PACKAGE_VERSION_PATCH "0")
525     set(CPACK_PACKAGE_INSTALL_DIRECTORY "/opt/")
526     add_component_package(MDC alimdc-rpm)
527
528   endif(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
529
530   list(FIND EXCLUDEMODULES ${MODULE} RESULT)
531   if(NOT RESULT STREQUAL "-1")
532     set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
533   endif(NOT RESULT STREQUAL "-1")
534
535 endmacro(ALICE_BuildExecutable)
536
537 macro(ALICE_CopyHeaders)
538   
539   if(EXPORT )
540     set(HEADERS ${EXPORT})
541     set(_headersdep)
542     foreach(header ${HEADERS})
543       add_custom_command(OUTPUT ${PEXPORTDEST}/${header}
544                          COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/${MODULE}/${header} ${PEXPORTDEST}/${header}
545                          DEPENDS ${CMAKE_SOURCE_DIR}/${MODULE}/${header})
546       list(APPEND _headersdep ${PEXPORTDEST}/${header})
547       install(FILES ${header} DESTINATION include)
548     endforeach(header)
549     add_custom_target(${PACKAGE}-headers DEPENDS ${_headersdep})
550     add_dependencies(${PACKAGE} ${PACKAGE}-headers)
551   endif(EXPORT)
552
553 endmacro(ALICE_CopyHeaders)
554
555 macro(ALICE_GenerateLinkDef)
556   set(PCLASSES)
557   foreach (class ${PCINTCLASSES})
558     get_filename_component(classname ${class} NAME)
559     # set(PCLASSES ${PCLASSES} "\\n#pragma link C++ class ${classname}+;")
560     set(PCLASSES ${PCLASSES} "${classname}")
561   endforeach(class)
562
563   add_custom_command(OUTPUT ${PDAL}
564     COMMAND sh ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh ${PCLASSES} > ${PDAL} 
565     DEPENDS ${PCINTHDRS} ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh)
566 endmacro(ALICE_GenerateLinkDef)
567
568 macro(ALICE_BuildPAR)
569   
570   if(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
571     set(PARSRCS)
572     foreach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
573       get_filename_component(srcdir ${file} PATH)
574       add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par                         
575                          COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${srcdir}
576                          COMMAND cp -pR ${file} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}
577                          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
578       list(APPEND PARSRCS ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par)
579     endforeach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
580     
581     add_custom_target(${PACKAGE}.par
582                       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
583                       COMMAND cp -pR ${ROOTSYS}/test/Makefile.arch ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/Makefile.arch
584                       COMMAND cp -pR PROOF-INF.${PACKAGE} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/PROOF-INF
585 #                      COMMAND cp -pR lib${PACKAGE}.pkg ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
586                       COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} tar --exclude=.svn -czhf ${CMAKE_BINARY_DIR}/${PACKAGE}.par ${PACKAGE}
587                       COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
588                       COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red --bold "${PACKAGE}.par has been created in ${CMAKE_BINARY_DIR}"
589                       DEPENDS ${PARSRCS} 
590                       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
591
592
593     add_dependencies(${PACKAGE}.par ${SRCS} ${FSRCS} ${HDRS} ${DHDR})
594     add_dependencies(par-all ${PACKAGE}.par)
595     add_dependencies(${MODULE}-par-all ${PACKAGE}.par)
596
597     add_custom_target(test-${PACKAGE}.par
598                       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}."
599                       COMMAND ${CMAKE_COMMAND} -E make_directory par-tmp
600                       COMMAND ${CMAKE_COMMAND} -E chdir par-tmp tar xfz ../${PACKAGE}.par && ${CMAKE_COMMAND} -E chdir par-tmp/${PACKAGE} PROOF-INF/BUILD.sh
601                       COMMAND ${CMAKE_COMMAND} -E remove_directory par-tmp
602                       COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green --bold "${PACKAGE}.par testing succeeded"
603                       WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
604
605     add_dependencies(test-${PACKAGE}.par ${PACKAGE}.par)
606     add_dependencies(test-par-all test-${PACKAGE}.par)
607     add_dependencies(test-${MODULE}-par-all test-${PACKAGE}.par)
608
609   endif(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
610   # endif(EXISTS ${ALICE_ROOT}/${MODULE}/PROOF-INF.${PACKAGE})
611
612 endmacro(ALICE_BuildPAR)
613