7918bb123995e0bf9fa41607235775297cdc104b
[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   string(REPLACE "-std=c++11" " " RCFLAGS "${RCFLAGS}")
136   set(CFLAGS  "${CFLAGS} ${RCFLAGS}")
137   set(SOFLAGS "${SOFLAGS} ${RLFLAGS}")
138   set(LDFLAGS "${LDFLAGS} ${RLFLAGS}")
139
140   if(NOT ALICXXWARN STREQUAL "NO")
141     set(CXXFLAGS "${CXXFLAGS} ${CXXWARN}")
142   endif(NOT ALICXXWARN STREQUAL "NO")
143
144   set(CXXFLAGS "${DATEFLAGS} ${CXXFLAGS}")
145   set(CFLAGS "${DATEFLAGS} ${CFLAGS}")
146   set(CINTFLAGS "${DATEFLAGS}")
147
148 endmacro(ALICE_ConfigureCompiler)
149
150 macro(ALICE_ConfigurePlatform)
151   
152   ALICE_GetTarget()
153   include("CMake${ALICE_TARGET}")
154   
155 endmacro(ALICE_ConfigurePlatform)
156
157 macro(ALICE_GetTarget)
158   
159   #Set ALICE_TARGET if it has not been set yet
160   if(NOT ALICE_TARGET)  
161     set(ALICE_TARGET $ENV{ALICE_TARGET})
162     #If ALICE_TARGET is not defined assign default values
163     if(NOT ALICE_TARGET)
164       message(WARNING "Environment variable ALICE_TARGET is not set ! Setting to default value.")
165       ALICE_RootConfig(ALICE_TARGET --arch)
166       message("ALICE_TARGET set to ${ALICE_TARGET}")
167     endif(NOT ALICE_TARGET)
168   endif(NOT ALICE_TARGET)
169
170 endmacro(ALICE_GetTarget) 
171
172 macro(ALICE_ResetPackage)
173
174   set(MODDIR ${MODULE})
175   set(MODDIRI ${PROJECT_SOURCE_DIR}/${MODULE})
176
177   set(SRCS)
178   set(HDRS)
179   set(FSRCS)
180   set(DHDR)
181   set(CSRCS)
182   set(CHDRS)
183   set(EINCLUDE)
184   set(EDEFINE)
185   set(ELIBS)
186   set(ELIBSDIR)
187   set(PACKFFLAGS)
188   set(PACKCXXFLAGS)
189   set(PACKCFLAGS)
190   set(PACKDYFLAGS)
191   set(PACKSOFLAGS)
192   set(PACKLDFLAGS)
193   set(PACKBLIBS)
194   set(EXPORT)
195   set(EHDRS)
196   set(CINTHDRS)
197   set(CINTAUTOLINK)
198   set(ARLIBS)
199   set(SHLIBS)
200
201   #HLT Variables
202   set(MODULE_HDRS)
203   set(MODULE_SRCS)
204   set(MODULE_DHDR)
205   set(CLASS_HDRS)
206   set(LIBRARY_DEP)
207   set(HLTDEFS)
208   set(HLTSOFLAGS) 
209
210
211   set(PSRCS)
212   set(PHDRS)
213   set(PFSRCS)
214   set(PDHDR)
215   set(PCSRCS)
216   set(PCHDRS)
217   set(PEINCLUDE)
218   set(PEDEFINE)
219   set(PELIBS)
220   set(PELIBSDIR)
221   set(PPACKFFLAGS)
222   set(PPACKCXXFLAGS)
223   set(PPACKCFLAGS)
224   set(PPACKDYFLAGS)
225   set(PPACKSOFLAGS)
226   set(PPACKLDFLAGS)
227   set(PPACKBLIBS)
228   set(PEXPORT)
229   set(PEHDRS)
230   set(PCINTHDRS)
231   set(PCINTAUTOLINK)
232   set(PARLIBS)
233   set(PSHLIBS)
234   set(PDS)
235
236 endmacro(ALICE_ResetPackage)
237
238 function(ALICE_SetPackageVariable _var ext setvalue unsetvalue )
239
240 #DevNotes - setvalue and unsetcalue should both be put in quotes or cmake throws an error if they have undefined values
241   if(setvalue)
242     set(${_var} ${setvalue} PARENT_SCOPE)
243     set(${PACKAGE}${ext} ${setvalue} PARENT_SCOPE)
244   else()
245     set(${_var} ${unsetvalue} PARENT_SCOPE)
246     set(${PACKAGE}${ext} ${unsetvalue} PARENT_SCOPE)
247   endif(setvalue)
248
249 endfunction(ALICE_SetPackageVariable)
250
251 macro(ALICE_BuildPackage)
252  
253   list(APPEND EINCLUDE STEER) 
254
255   ALICE_SetPackageVariable(PFFLAGS "FFLAGS" "${PACKFFLAGS}" "${FFLAGS}")
256   ALICE_SetPackageVariable(PCFLAGS "CFLAGS" "${PACKCFLAGS}" "${CFLAGS}")
257   ALICE_SetPackageVariable(PCXXFLAGS "CXXFLAGS" "${PACKCXXFLAGS}" "${CXXFLAGS}")
258   ALICE_SetPackageVariable(PSOFLAGS "SOFLAGS" "${PACKSOFLAGS}" "${SOFLAGS}")
259   ALICE_SetPackageVariable(PLDFLAGS "LDFLAGS" "${PACKLDFLAGS}" "${LDFLAGS}")
260   ALICE_SetPackageVariable(PDCXXFLAGS "DCXXFLAGS" "${PACKDCXXFLAGS}" "${CXXFLAGSNO}")
261   ALICE_SetPackageVariable(PBLIBS "BLIBS" "${PACKBLIBS}" "${LIBS}")
262
263   set(WITHDICT)
264   if(DHDR OR CINTAUTOLINK)
265     set(WITHDICT TRUE)
266   endif(DHDR OR CINTAUTOLINK)
267
268   ALICE_SetPackageVariable(PEDEFINE "EDEFINE" "${EDEFINE}" "${EDEFINE}")
269   ALICE_SetPackageVariable(PEXPORT "EXPORT" "${EXPORT}" "${EXPORT}")
270 #  message(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
271   ALICE_SetPackageVariable(PEXPORTDEST "EXPORTDEST" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
272   ALICE_SetPackageVariable(PINC "INC" "${EINCLUDE};${MODULE}" "${EINCLUDE};${MODULE}")
273   ALICE_SetPackageVariable(PELIBS "ELIBS" "${ELIBS}" "${ELIBS}")
274   ALICE_SetPackageVariable(PELIBSDIR "ELIBSDIR" "${ELIBSDIR}" "${ELIBSDIR}")
275   
276   ALICE_SetPackageVariable(PCS "CS" "${CSRCS}" "${CSRCS}")
277   ALICE_SetPackageVariable(PCH "CH" "${CHDRS}" "${CHDRS}")
278   
279   ALICE_SetPackageVariable(PFS "FS" "${FSRCS}" "${FSRCS}")
280
281   ALICE_SetPackageVariable(PS "S" "${SRCS}" "${SRCS}")
282   ALICE_SetPackageVariable(PH "H" "${HDRS} ${EHDRS}" "${HDRS} ${EHDRS}")
283   ALICE_SetPackageVariable(PCINTHDRS "CINTHDRS" "${CINTHDRS}" "${PH}")
284   
285   string( REPLACE ".h" "" PCINTCLASSES "${PCINTHDRS}")
286   set ( ${PACKAGE}CINTCLASSES ${PCINTCLASSES})
287
288   ALICE_SetPackageVariable(PDH "DH" "${DHDR}" "")
289
290   if(CINTAUTOLINK)
291     ALICE_SetPackageVariable(PDAL "DAL" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h")
292     ALICE_SetPackageVariable(PDH "DH" "${PDAL}" "${PDAL}")
293     ALICE_GenerateLinkDef()
294   endif(CINTAUTOLINK)
295
296   if(lib)
297     list(APPEND PMLIBS ${PACKAGE})
298     list(APPEND ALLLIBS ${PACKAGE})
299     list(APPEND PMALIBS ${PACKAGE}-static)
300     list(APPEND ALLALIBS ${PACKAGE}-static)
301     list(APPEND BINLIBS ${PACKAGE})
302   else()
303     list(APPEND ALLEXECS ${PACKAGE})
304   endif(lib)
305   set(${MODULE}ALIBS "${PMALIBS}" PARENT_SCOPE)
306   set(${MODULE}LIBS "${PMLIBS}" PARENT_SCOPE)
307   set(${MODULE}INC "${EINCLUDE}" PARENT_SCOPE)
308   list(APPEND INCLUDEFILES ${PEXPORTDEST})
309   if(WITHDICT)  
310     ALICE_SetPackageVariable(PDS "DS" "G__${PACKAGE}.cxx" "G__${PACKAGE}.cxx")
311     ALICE_GenerateDictionary()
312   else()
313     if(lib)
314       message(STATUS "No dictionary generated for ${PACKAGE}")  
315     endif(lib)
316   endif(WITHDICT)
317   if(PS OR PCS OR PFS)
318     if(lib)
319       ALICE_BuildLibrary()
320     elseif(bin)
321       ALICE_BuildExecutable()
322     endif(lib)
323   endif(PS OR PCS OR PFS)
324   ALICE_CopyHeaders()
325   ALICE_BuildPAR()
326
327 endmacro(ALICE_BuildPackage)
328
329
330 macro(ALICE_BuildModule)
331
332   add_definitions(-D_MODULE_="${MODULE}")
333   foreach(PACKAGEFILE ${PACKAGES})
334       set(lib)
335       set(bin)
336       string(REGEX MATCH "CMakelib" lib "${PACKAGEFILE}")
337       string(REGEX MATCH "CMakebin" bin "${PACKAGEFILE}")
338       get_filename_component(PACKAGE ${PACKAGEFILE} NAME)
339       string(REGEX REPLACE "^CMake(lib|bin)(.*)\\.pkg" "\\2" PACKAGE "${PACKAGE}")
340       if(ALICEDEV)
341         message("Adding package ${PACKAGE} in ${MODULE}")
342       endif(ALICEDEV)
343       ALICE_ResetPackage()
344       include(${PACKAGEFILE})
345       ALICE_BuildPackage()
346      
347       get_property(EXCLUDEPACKAGE TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL) 
348       if(NOT EXCLUDEPACKAGE)
349         install(TARGETS ${PACKAGE} 
350                 RUNTIME DESTINATION bin/tgt_${ALICE_TARGET}
351                 LIBRARY DESTINATION lib/tgt_${ALICE_TARGET}
352                 ARCHIVE DESTINATION bin/tgt_${ALICE_TARGET})
353       endif(NOT EXCLUDEPACKAGE)
354   endforeach(PACKAGEFILE)
355   ALICE_CheckModule()
356 endmacro(ALICE_BuildModule)
357
358 macro(ALICE_GenerateDictionary)
359  
360   if(ALICEDEV STREQUAL "YES")
361     message("Generating Dictionary rule for ${PACKAGE}")
362     message("${ROOTCINT} -f ${PDS} -c ${PEDEFINE} ${CINTFLAGS} ${PINC} ${PCINTHDRS} ${PDH}")
363   endif(ALICEDEV STREQUAL "YES")
364  
365   # Split up all arguments
366
367   set(DEDEFINE ${PEDEFINE})
368   set(DCINTFLAGS ${CINTFLAGS})
369   set(DINC ${PINC})
370   set(DCINTHDRS ${PCINTHDRS})
371   set(DDH ${PDH})
372   separate_arguments(DEDEFINE)
373   separate_arguments(DCINTFLAGS)
374   separate_arguments(DINC)
375   separate_arguments(DCINTHDRS)
376   separate_arguments(DDH)
377   # Format neccesary arguments
378   ALICE_Format(DINC "-I" "" "${DINC};${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
379   set_source_files_properties(${PDS} PROPERTIES GENERATED TRUE)
380   set_source_files_properties(${PDS} PROPERTIES COMPILE_FLAGS "-w")
381   add_custom_command(OUTPUT  ${PDS}
382                      COMMAND cd ${PROJECT_SOURCE_DIR} && ${ROOTCINT} -f ${CMAKE_CURRENT_BINARY_DIR}/${PDS} -c -D_MODULE=\\\"${MODULE}\\\" ${DEDEFINE} ${DCINTFLAGS} ${DINC} ${DCINTHDRS} ${DDH}
383                      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
384                      DEPENDS ${DCINTHDRS} ${DDH}
385                      )
386   add_custom_target(G${PACKAGE})
387   add_dependencies(G${PACKAGE} ${PDS})
388
389 endmacro(ALICE_GenerateDictionary)
390
391 macro(ALICE_BuildLibrary)
392
393   ALICE_DevFlagsOutput()
394   set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS}")
395   set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS}")
396   set(CMAKE_Fortran_FLAGS "${PEDEFINE} ${PFFLAGS}")
397   set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS}) 
398   set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
399   
400   
401   separate_arguments(PINC)
402   separate_arguments(EINCLUDE)
403   separate_arguments(PELIBSDIR)
404   separate_arguments(PBLIBS)
405   separate_arguments(PELIBS)
406   separate_arguments(SHLIB)
407
408   ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
409   ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
410
411   ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
412   ALICE_CorrectPaths(PINC "${PINC}")
413
414   include_directories(SYSTEM ${ROOTINCDIR})
415   include_directories(${PINC})  
416   include_directories(${EINCLUDE})
417   include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
418   
419   add_library(${PACKAGE} SHARED ${PCS} ${PFS} ${PS} ${PDS})
420   set_target_properties(${PACKAGE} PROPERTIES SUFFIX .so)  
421   
422
423   if(PELIBS OR SHLIB)
424     target_link_libraries(${PACKAGE} ${PELIBSDIR} ${PELIBS} ${SHLIB})
425   endif(PELIBS OR SHLIB)
426   
427   add_dependencies(${MODULE}-all ${PACKAGE})
428      
429   add_library(${PACKAGE}-static STATIC EXCLUDE_FROM_ALL ${PCS} ${PFS} ${PS} ${PDS})
430   set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME ${PACKAGE})
431   if(PELIBS OR ALLIB)
432     target_link_libraries(${PACKAGE}-static ${PELIBSDIR} ${PELIBS} ${ALLIB})
433   endif(PELIBS OR ALLIB)
434
435   add_dependencies(${MODULE}-all-static ${PACKAGE}-static)
436   if(ALIPROFILE STREQUAL "YES")
437     add_dependencies(${MODULE}-all ${MODULE}-static)
438   endif(ALIPROFILE STREQUAL "YES")
439
440   list(FIND EXCLUDEMODULES ${MODULE} RESULT)
441   if(NOT RESULT STREQUAL "-1")
442     message(STATUS "${MODULE} will not be built by default. Type make ${MODULE}-all to build.")
443     set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
444   endif(NOT RESULT STREQUAL "-1")
445
446   set_target_properties(${PACKAGE} PROPERTIES INSTALL_NAME_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
447
448 endmacro(ALICE_BuildLibrary)
449
450 macro(ALICE_BuildExecutable)
451
452   ALICE_DevFlagsOutput()
453   set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS} ${EXEFLAGS}")
454   set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS} ${EXEFLAGS}")
455   set(CMAKE_Fortran_FLAGS "${PEDEFINE} ${PFFLAGS} ${EXEFLAGS}")
456   set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS}) 
457   set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
458   
459   separate_arguments(PINC)
460   separate_arguments(EINCLUDE)
461   separate_arguments(PELIBSDIR)
462   separate_arguments(PBLIBS)
463   separate_arguments(PELIBS)
464   separate_arguments(SHLIB)
465   
466   ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
467   ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
468
469   ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
470   ALICE_CorrectPaths(PINC "${PINC}")
471
472   include_directories(SYSTEM ${ROOTINCDIR})
473   include_directories(${PINC})  
474   include_directories(${EINCLUDE})
475   include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
476
477   if(ALIPROFILE STREQUAL "YES")
478     add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
479     if(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
480       target_link_libraries(${PACKAGE} ${ARLIBS} ${SHLIBS} ${PBLIBS} ${EXEFLAGS})
481     endif(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
482     add_dependencies(${MODULE}-all ${PACKAGE})
483   else()
484     add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
485     if(PELIBS OR PBLIBS OR EXEFLAGS)
486       target_link_libraries(${PACKAGE} ${BINLIBDIRS} ${PELIBSDIR} ${PELIBS} ${PBLIBS} ${EXEFLAGS})
487     endif(PELIBS OR PBLIBS OR EXEFLAGS)
488     add_dependencies(${MODULE}-all ${PACKAGE})
489   endif(ALIPROFILE STREQUAL "YES")
490
491 # AliMDC
492 # ------------------------------
493   if(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
494
495     add_executable(${PACKAGE}-static ${PFS} ${PCS} ${PS} ${PDS})
496     set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME alimdca)
497     add_custom_target( libAliMDC
498                         COMMAND rm -rf ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a
499                         COMMAND rm -rf junkmdc
500                         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
501                         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
502     add_custom_target( root-static-libs 
503                        COMMAND make static
504                        WORKING_DIRECTORY ${ROOTSYS} )
505                        
506     add_dependencies(libAliMDC RAWDatabase-static STEERBase-static MDC-static ESD-static)
507     add_dependencies(${PACKAGE}-static libAliMDC root-static-libs)
508     target_link_libraries(${PACKAGE}-static ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${ROOTLIBDIR}/libRoot.a ${ROOTLIBDIR}/libfreetype.a ${ROOTLIBDIR}/libpcre.a -pthread -ldl -lcurses)
509
510     install(TARGETS ${PACKAGE}-static RUNTIME DESTINATION bin/tgt_${ALICE_TARGET} COMPONENT MDC)
511     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)
512     install(FILES ${PROJECT_SOURCE_DIR}/RAW/mdc.h DESTINATION include COMPONENT MDC)
513     set(CPACK_RPM_PACKAGE_SUMMARY "AliMDC static libraries")
514     set(CPACK_RPM_PACKAGE_NAME "alimdc")
515     set(CPACK_RPM_PACKAGE_VERSION "${ALIMDCVERSION}")
516     set(CPACK_RPM_PACKAGE_RELEASE "${ALIMDCRELEASE}")
517     set(CPACK_RPM_PACKAGE_LICENSE "License: CERN ALICE Off-line Group")
518     set(CPACK_RPM_PACKAGE_VENDOR "ALICE Core Off-line Group")
519     set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AliMDC static libraries")
520     set(CPACK_RPM_PACKAGE_GROUP "Applications/Alice")
521     set(CPACK_RPM_PACKAGE_REQUIRES "glibc")
522     set(CPACK_PACKAGE_VERSION "1.0.0")
523     set(CPACK_PACKAGE_VERSION_MAJOR "1")
524     set(CPACK_PACKAGE_VERSION_MINOR "0")
525     set(CPACK_PACKAGE_VERSION_PATCH "0")
526     set(CPACK_PACKAGE_INSTALL_DIRECTORY "/opt/")
527     add_component_package(MDC alimdc-rpm)
528
529   endif(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
530
531   list(FIND EXCLUDEMODULES ${MODULE} RESULT)
532   if(NOT RESULT STREQUAL "-1")
533     set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
534   endif(NOT RESULT STREQUAL "-1")
535
536 endmacro(ALICE_BuildExecutable)
537
538 macro(ALICE_CopyHeaders)
539   
540   if(EXPORT )
541     set(HEADERS ${EXPORT})
542     set(_headersdep)
543     foreach(header ${HEADERS})
544       get_filename_component( header_name ${header} NAME )
545       add_custom_command(OUTPUT ${PEXPORTDEST}/${header_name}
546                          COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/${MODULE}/${header} ${PEXPORTDEST}/${header_name}
547                          DEPENDS ${CMAKE_SOURCE_DIR}/${MODULE}/${header})
548       list(APPEND _headersdep ${PEXPORTDEST}/${header_name})
549       install(FILES ${header} DESTINATION include)
550     endforeach(header)
551     add_custom_target(${PACKAGE}-headers DEPENDS ${_headersdep})
552     add_dependencies(${PACKAGE} ${PACKAGE}-headers)
553   endif(EXPORT)
554
555 endmacro(ALICE_CopyHeaders)
556
557 macro(ALICE_GenerateLinkDef)
558   set(PCLASSES)
559   foreach (class ${PCINTCLASSES})
560     get_filename_component(classname ${class} NAME)
561     # set(PCLASSES ${PCLASSES} "\\n#pragma link C++ class ${classname}+;")
562     set(PCLASSES ${PCLASSES} "${classname}")
563   endforeach(class)
564
565   add_custom_command(OUTPUT ${PDAL}
566     COMMAND sh ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh ${PCLASSES} > ${PDAL} 
567     DEPENDS ${PCINTHDRS} ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh)
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\)\\/\\(etc\\|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}/etc/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