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