coverity fix
[u/mrichter/AliRoot.git] / cmake / CMakeDA.cmake
1 #--------------------------------------------------------------------
2 # CMakeDA.cmake file for AliRoot Build System
3 #
4 # Author: Anshul Goel (anshul.goel@cern.ch)
5 #         Port of previous Makefile build to DAQ targets and RPM
6 #
7
8 cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
9
10 # -----------Utilities--------------------
11
12 #list of detectors 
13 #set(ONLINEDETECTORS T00)
14 set(ONLINEDETECTORS SPD SDD SSD ACO GRP TST HLT EMC TRI T00 PMD CPV PHS FMD TPC TRD ZDC V00 MTR MCH HMP TOF)
15 function(expand output input)
16     string(REGEX MATCH "\\\${[^}]*}" m "${input}")
17     while(m)
18         string(REGEX REPLACE "\\\${(.*)}" "\\1" v "${m}")
19         string(REPLACE "\${${v}}" "${${v}}" input "${input}")
20         string(REGEX MATCH "\\\${[^}]*}" m "${input}")
21     endwhile()
22     set("${output}" "${input}" PARENT_SCOPE)
23 endfunction()
24
25 #function to get module for detector
26 function (detector_module _module detector)
27   #Map of online detectors to DA in pairs of ONLINEDETECTORNAME DAMODULE
28   set (DETECTORMODULEMAP SPD ITS SDD ITS SSD ITS HMP HMPID PHS PHOS CPV PHOS MCH MUON MTR MUON T00 T0 V00 VZERO ACO ACORDE EMC EMCAL)
29   list(FIND DETECTORMODULEMAP ${detector} _index)
30   if(_index STREQUAL "-1")
31     set(${_module} "${detector}" PARENT_SCOPE)
32   else()
33     math(EXPR _index "${_index}+1")
34     list(GET DETECTORMODULEMAP ${_index} _index)
35     set(${_module} ${_index} PARENT_SCOPE)
36   endif(_index STREQUAL "-1")
37 endfunction()
38
39 #function to get subDA for detector
40 function (detector_subda _subda detector)
41   #Map of online detectors to SUBDAMODULE in pairs of ONLINEDETECTORNAME SUBDAMODULE
42   set (DETECTORSUBDAMAP SPD SPD SDD SDD SSD SSD CPV CPV MCH TRK MTR TRG)
43   list(FIND DETECTORSUBDAMAP ${detector} _index)
44   if(_index STREQUAL "-1")
45     set(${_subda} "" PARENT_SCOPE)
46   else()
47     math(EXPR _index "${_index}+1")
48     list(GET DETECTORSUBDAMAP ${_index} _index)
49     set(${_subda} ${_index} PARENT_SCOPE)
50   endif(_index STREQUAL "-1")
51 endfunction()
52
53 #function to extract info
54 function (getinfo _info pattern file)
55   string(REGEX MATCH "${pattern}:[^\n]*" _match ${file})
56   if(_match)
57     string(REGEX REPLACE "${pattern}:[ ]*" "" _data ${_match})
58     string(REPLACE "(" "\\(" _data "${_data}")
59     string(REPLACE ")" "\\)" _data "${_data}")
60     string(REPLACE "<" "\\<" _data "${_data}")
61     string(REPLACE ">" "\\>" _data "${_data}")
62   endif(_match)
63   set(${_info} ${_data} PARENT_SCOPE)
64 endfunction()
65
66
67 foreach(oldetect ${ONLINEDETECTORS})
68 detector_module(h_module ${oldetect})
69   list(APPEND mod "-I${CMAKE_SOURCE_DIR}/${h_module}")
70 endforeach(oldetect ${ONLINEDETECTORS})
71 list(APPEND mod "-I${CMAKE_SOURCE_DIR}/include" "-I${CMAKE_SOURCE_DIR}/STEER" "-I${CMAKE_SOURCE_DIR}/ANALYSIS" "-I${CMAKE_SOURCE_DIR}/RAW" "-I${CMAKE_SOURCE_DIR}/STEER/STEER" "-I${CMAKE_SOURCE_DIR}/STEER/CDB" "-I${ROOTINCDIR}" "-I${CMAKE_SOURCE_DIR}/STEER/STEERBase" "-I${CMAKE_SOURCE_DIR}/STEER/AOD" "-I${CMAKE_SOURCE_DIR}/STEER/ESD" "-I${CMAKE_SOURCE_DIR}/MUON/mapping" "-I$ENV{AMORE}/include/amore")
72
73 # ----------Common stuff-------------------
74
75 #file(GLOB_RECURSE _dafiles $ENV{ALICE_ROOT}/*da.cxx)
76 file(GLOB_RECURSE _dafiles ${CMAKE_SOURCE_DIR}/*da.cxx)
77
78 set (DAINSTALL "$ENV{ALICE_INSTALL}/DA")
79 if(DAINSTALL STREQUAL "/DA") 
80   set(DAINSTALL "$ENV{ALICE_ROOT}/DA")
81 endif(DAINSTALL STREQUAL "/DA")
82
83
84 file(MAKE_DIRECTORY ${DAINSTALL})
85
86 string (REPLACE "-pedantic-errors" "" CXXFLAGS ${CXXFLAGS})
87
88 find_program(XML2 xml2-config)
89
90 if(AMORE_FOUND)
91   #Set compiler flags
92   set(CXXFLAGS "${CXXFLAGS} ${AMOREFLAGS}")
93   set(CFLAGS "${CFLAGS} ${AMOREFLAGS}")
94   set(CINTFLAGS "${CINTFLAGS} ${AMOREFLAGS}")
95 else()
96   set(AMORELIBS)
97 endif(AMORE_FOUND)
98
99 execute_process(COMMAND ${XML2} --libs OUTPUT_VARIABLE _xml2libs OUTPUT_STRIP_TRAILING_WHITESPACE)
100 execute_process(COMMAND ${DATE_CONFIG} --monitorlibs=noshift OUTPUT_VARIABLE MONITORLIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
101 execute_process(COMMAND $ENV{AMORE}/bin/amore-config --ldflags-da-static OUTPUT_VARIABLE _amore1 OUTPUT_STRIP_TRAILING_WHITESPACE)
102 execute_process(COMMAND $ENV{AMORE}/bin/amore-config --auxlibs  OUTPUT_VARIABLE _amore3 OUTPUT_STRIP_TRAILING_WHITESPACE)
103 execute_process(COMMAND date-config --rcproxylibs OUTPUT_VARIABLE _amore2 OUTPUT_STRIP_TRAILING_WHITESPACE)
104 execute_process(COMMAND date-config --monitorlibs=noshift OUTPUT_VARIABLE _monitor1 OUTPUT_STRIP_TRAILING_WHITESPACE)
105 string(REPLACE "\n" " " _amore1 "${_amore1}") 
106 set(AMOREDALIBS " ${_amore1} ${_amore2}")
107 set(AMOREDADLIBS " ${_amore3} ${_amore2}")
108 set(MONITORLIBS "${_monitor1} -lssl")
109 separate_arguments(MONITORLIBS)
110 separate_arguments(AMOREDALIBS)
111 separate_arguments(AMOREDADLIBS)
112 set(SYSLIBS -ldl -lpthread ${_xml2libs})
113 set(DATE_CFLAGS "${DATEFLAGS}")
114 separate_arguments(DATE_CFLAGS)
115 set(ROOTDLIBS "${ROOTCLIBS} -lRMySQL")
116 separate_arguments(ROOTDLIBS)
117
118 set(EXTRAROOTLIB "libRootExtra.a")
119 set(ROOTLIB "RootExtra")
120 file(GLOB _extraroot "$ENV{ROOTSYS}/montercarlo/vmc/src/*.o" "$ENV{ROOTSYS}/tree/treeplayer/src/*.o" "$ENV{ROOTSYS}/io/xmlparser/src/*.o" "$ENV{ROOTSYS}/math/minuit2/src/*.o")
121
122 add_library(${ROOTLIB} STATIC ${_extraroot})      
123 set_target_properties(${ROOTLIB} PROPERTIES LINKER_LANGUAGE CXX)
124
125 set(DAQDALIB_PATH $ENV{DAQDALIB_PATH})  
126 if(DAQDALIB_PATH)
127   set(DAQDADIR "${DAQDALIB_PATH}")
128 else()
129   set(DAQDADIR "$ENV{ALICE}/daqDAlib")
130 endif(DAQDALIB_PATH)
131 set(DAQDALIB "${DAQDADIR}/libdaqDA.a")
132
133 include_directories(${DAQDADIR} ${CMAKE_SOURCE_DIR}/RAW ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/STEER)
134 include_directories(SYSTEM ${ROOTINCDIR})
135
136 # ----------Create All Valid targets---------
137           
138 foreach(detector ${ONLINEDETECTORS} )
139
140   set(ONLINEDETECTORNAME ${detector})
141
142   detector_module(DAMODULE ${ONLINEDETECTORNAME})
143
144   detector_subda(SUBDAMODULE ${ONLINEDETECTORNAME})
145   
146   #ALIROOTALIBS
147
148   set(ALIROOTALIBS)
149   set(ALIROOTDLIBS)
150         set(BASIC_TARGET "daqDA-${ONLINEDETECTORNAME}-all")
151         add_custom_target(${BASIC_TARGET}
152         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
153         ) 
154   set(DYN_TARGET "daqDA-${ONLINEDETECTORNAME}-all-dyn")
155   add_custom_target(${DYN_TARGET}
156     WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
157     ) 
158         set(BASIC_RPM "daqDA-${ONLINEDETECTORNAME}-all-rpm")
159         add_custom_target(${BASIC_RPM}
160         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
161         )
162  list(APPEND ALIROOTALIBS RAWDatabase-static RAWDatarec-static RAWDatasim-static STEERBase-static STEER-static CDB-static ESD-static STAT-static AOD-static ANALYSIS-static ANALYSISalice-static )
163   list(APPEND ALIROOTDLIBS -lRAWDatabase -lRAWDatarec -lRAWDatasim -lSTEERBase -lSTEER -lCDB -lESD -lSTAT -lAOD -lANALYSIS -lANALYSISalice )
164
165   expand(ALIROOTALIBS2 "\${${DAMODULE}ALIBS}")
166   expand(ALIROOTDLIBS2 "\${${DAMODULE}LIBS}")
167   expand(DAINCDIRS "\${${DAMODULE}INC}")
168   list(APPEND ALIROOTALIBS ${ALIROOTALIBS2})
169   foreach (detlib ${ALIROOTDLIBS2}) 
170     list(APPEND ALIROOTDLIBS "-l${detlib}")
171   endforeach(detlib ${ALIROOTDLIBS2})  
172   # list(APPEND ALIROOTDLIBS ${ALIROOTDLIBS2})
173   
174   include_directories(${DAMODULE} ${SUBDIR} ${DAINCDIRS})
175 #Get detector algorithms for this detector
176   foreach(dafile ${_dafiles})
177
178     string(REGEX MATCH "${CMAKE_SOURCE_DIR}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}" match ${dafile})
179 #Found a valid target name
180         if(match)
181       string(REGEX REPLACE "${CMAKE_SOURCE_DIR}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}(.*)da\\.cxx" "\\1" DANAME ${dafile})
182 #Check for default DA 
183           if(DANAME)
184             set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}-${DANAME}")
185         else()
186             set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}")
187           endif(DANAME)
188         add_dependencies(${BASIC_TARGET} ${DATARGETNAME})  
189         add_dependencies(${BASIC_RPM} ${DATARGETNAME}-rpm) 
190       add_dependencies(${DYN_TARGET} ${DATARGETNAME}-dyn)
191          set(DATARGETDIR "${DAINSTALL}/${DAMODULE}/tgt_$ENV{ALICE_TARGET}")
192           file(MAKE_DIRECTORY ${DATARGETDIR})
193           set(DAOBJ "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.o")
194           set(DASRC "${DAMODULE}/${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx")
195           set(DALIB "${DAMODULE}${SUBDAMODULE}${DANAME}DA")
196           set(DAEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da.exe")
197           set(DADEP "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.d") 
198       set(DADYNEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da")
199
200         # DAVERSION
201       execute_process(COMMAND svn info ${CMAKE_SOURCE_DIR}/${DASRC} OUTPUT_VARIABLE _daversion OUTPUT_STRIP_TRAILING_WHITESPACE)
202           string(REGEX REPLACE ".*Last Changed Rev: ([^\n]+)\n.*" "\\1" DAVERSION ${_daversion})
203
204         #DAREVISION
205           execute_process(COMMAND svn info ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE _darevision OUTPUT_STRIP_TRAILING_WHITESPACE)
206           string(REGEX REPLACE ".*Revision: ([^\n]+)\n.*" "\\1" DAREVISION ${_darevision})
207         # DAROOTRELEASE 
208           execute_process(COMMAND root-config --version OUTPUT_VARIABLE _darootrelease OUTPUT_STRIP_TRAILING_WHITESPACE)
209           string(REGEX REPLACE "/" "." DAROOTRELEASE ${_darootrelease})
210         
211         # DAALIROOTRELEASE
212           string(REGEX REPLACE ".*URL: .*/(.+)/${DASRC}.*$" "\\1" DAALIROOTRELEASE ${_daversion})
213           string (REPLACE "-" "." DAALIROOTRELEASE "${DAALIROOTRELEASE}")
214         
215           set(DAARCNAME "${DATARGETNAME}")
216           #string(REPLACE "-" "" DAARCNAME "${DAARCNAME}")
217           set(DAARC "${DAARCNAME}-${DAVERSION}")
218           set(DATAR "${DATARGETDIR}/${DAARC}.src.tar.gz")
219           set(DASPECFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec")
220           set(DAMAKEFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.make")
221
222   
223       file(READ "${CMAKE_SOURCE_DIR}/${DASRC}" _dasrc)
224           getinfo(DACONTACT "Contact" ${_dasrc})
225           getinfo(DALINKPAGE "Link" ${_dasrc})
226           getinfo(DAREFRUN "Reference Run" ${_dasrc})
227           getinfo(DARUNTYPE "Run Type" ${_dasrc})
228           getinfo(DATYPE "DA Type" ${_dasrc})
229           getinfo(DANUMBEROFEVENTS "Number of events needed" ${_dasrc})
230           getinfo(DAINPUTFILES "Input Files" ${_dasrc})
231           getinfo(DAOUTPUTFILES "Output Files" ${_dasrc})
232           getinfo(DATRIGGERTYPE "Trigger types used" ${_dasrc})
233
234           if(NOT _dasrc)
235            message(FATAL_ERROR "SRC FILE MISSING")
236           endif(NOT _dasrc)
237
238 #----------- Targets ----------------------
239
240           set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
241           set(CMAKE_C_FLAGS "${CFLAGS}")
242           set(CMAKE_Fortran_FLAGS ${FFLAGS})
243           set(CMAKE_SHARED_LINKER_FLAGS ${SOFLAGS}) 
244           set(CMAKE_MODULE_LINKER_FLAGS ${LDFLAGS})
245
246 add_dependencies(DA-all ${DATARGETNAME})
247       add_dependencies(DA-dyn-all ${DATARGETNAME}-dyn)
248 add_custom_target(${DATARGETNAME}
249 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
250 )
251 add_dependencies(${DATARGETNAME} ${DAEXE})
252       add_custom_target(${DATARGETNAME}-dyn
253         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
254         )
255       add_dependencies(${DATARGETNAME}-dyn ${DADYNEXE})
256
257 set(ZIP)
258 foreach(_lib ${ALIROOTALIBS})
259 string(REGEX REPLACE "-static" "" _lib ${_lib})
260 list(APPEND ZIP && ar x "../lib${_lib}.a")
261 endforeach(_lib)
262 list (APPEND ZIP && ar r "../lib${DALIB}.a" "*.o")
263
264 add_custom_target(${DALIB}.a
265 COMMAND rm -rf junk${DAEXE} && mkdir -p junk${DAEXE}
266 COMMAND cd junk${DAEXE} ${ZIP}
267 COMMAND cd ../ && rm -rf junk${DAEXE}
268 DEPENDS ${ALIROOTALIBS} 
269 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} 
270 )
271
272 add_custom_command(
273 TARGET ${DATARGETNAME}-clean
274 COMMAND echo "***** Cleaning ${DAMODULE} ${SUBDAMODULE} ${DANAME} detector-algorithm *****"
275 COMMAND rm -f ${DASPECFILE}
276 COMMAND rm -f ${DATAR}
277 COMMAND rm -f ${DAEXE}
278 COMMAND rm -f ${DAOBJ}
279 COMMAND rm -f ${DADEP}
280 COMMAND rm -f ${DAMAKEFILE}
281 COMMAND rm -f ${DALIB}.a
282 COMMAND rm -f ${ALIROOTALIBS}
283 COMMAND rm -f ${EXTRAROOTLIB}
284 )
285
286 separate_arguments(SYSLIBS)
287 #execute_process(COMMAND ${AMORE}/amore-config --ldflags-da-static | tr "\n" " "  OUTPUT_VARIABLE _amore1 OUTPUT_STRIP_TRAILING_WHITESPACE)
288 #execute_process(COMMAND date-config --rcproxylibs OUTPUT_VARIABLE _amore2 OUTPUT_STRIP_TRAILING_WHITESPACE)
289 #execute_process(COMMAND date-config --monitorlibs=noshift OUTPUT_VARIABLE _monitor1 OUTPUT_STRIP_TRAILING_WHITESPACE)
290   
291 #set(AMOREDALIBS "-static ${_amore1} ${_amore2}\\")
292 #set(MONITORLIBS "${_monitor1}\\")
293
294 add_custom_target(DAMAKEFILE_${DAEXE}_)
295 add_custom_command( 
296 TARGET DAMAKEFILE_${DAEXE}_
297 COMMAND rm -f ${DAMAKEFILE}
298 COMMAND @echo "***** Making makefile ${DAMAKEFILE} *****"
299 COMMAND @echo '\#***************************************************' >> ${DAMAKEFILE}
300 COMMAND @echo '\# Makefile for Detector Algorithm' >> ${DAMAKEFILE}
301 COMMAND @echo '\#' >> ${DAMAKEFILE}
302 COMMAND @echo '\# It is necessary to setup build environment before' >> ${DAMAKEFILE}
303 COMMAND @echo '\# using make:' >> ${DAMAKEFILE}
304 COMMAND @echo '\# - define path to daqDAlib (env. DAQDALIB_PATH)' >> ${DAMAKEFILE}
305 COMMAND @echo '\#' >> ${DAMAKEFILE}
306 COMMAND @echo '\#*****************************************************' >> ${DAMAKEFILE}
307 COMMAND @echo "" >> ${DAMAKEFILE}
308 COMMAND @echo "CXX=g++" >> ${DAMAKEFILE}
309 COMMAND @echo "LD=g++" >> ${DAMAKEFILE}
310 COMMAND @echo "" >> ${DAMAKEFILE}
311 COMMAND @echo "CXXFLAGS=${CXXFLAGS}" >> ${DAMAKEFILE}
312 COMMAND @echo "LDFLAGS=${LDFLAGS}" >> ${DAMAKEFILE}
313 COMMAND @echo "" >> ${DAMAKEFILE}
314 COMMAND @echo 'ifeq ($$(DAQDALIB_PATH),)' >> ${DAMAKEFILE}
315 COMMAND @echo "DAQDADIR=${ALICE}/daqDAlib" >> ${DAMAKEFILE}
316 COMMAND @echo "else" >> ${DAMAKEFILE}
317 COMMAND @echo 'DAQDADIR=$$(DAQDALIB_PATH)' >> ${DAMAKEFILE}
318 COMMAND @echo "endif" >> ${DAMAKEFILE}
319 COMMAND @echo "" >> ${DAMAKEFILE}
320 COMMAND @echo 'DAQDALIB=$$(DAQDADIR)/libdaqDA.a' >> ${DAMAKEFILE}
321 #COMMAND @echo 'AMOREDALIBS=-static $$(shell $$(AMORE)/amore-config --ldflags-da-static) $$(shell date-config --rcproxylibs)' >> ${DAMAKEFILE}
322 #COMMAND @echo 'MONITORLIBS=$$(shell date-config --monitorlibs=noshift)' >> ${DAMAKEFILE}
323 #COMMAND @echo 'AMOREDALIBS=-static ${_amore1} ${_amore2}' >> ${DAMAKEFILE}
324 #COMMAND @echo 'MONITORLIBS=${monitor1}' >> ${DAMAKEFILE}
325 COMMAND @echo "" >> ${DAMAKEFILE}
326 COMMAND @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.exe: ${DAMODULE}${SUBDAMODULE}${DANAME}da.o" >> ${DAMAKEFILE}
327 COMMAND @echo -e '\t$$(LD) $$(LDFLAGS) -o ''$$''@ ''$$''< ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${DALIB}.a ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EXTRAROOTLIB} $$(ROOTSYS)/lib/libRoot.a $$(ROOTSYS)/lib/liblzma.a $$(ROOTSYS)/lib/libfreetype.a $$(ROOTSYS)/lib/libpcre.a ${SYSLIBS} $$(DAQDALIB) ${AMOREDALIBS} ${MONITORLIBS}' >> ${DAMAKEFILE}
328 COMMAND @echo "" >> ${DAMAKEFILE}
329 COMMAND @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.o: ${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx" >> ${DAMAKEFILE}
330 COMMAND @echo -e '\t$$(CXX) -c $$(CXXFLAGS) -I$$(DAQDADIR) ${mod} ''$$''< -o ''$$''@' >> ${DAMAKEFILE}
331 COMMAND @echo "" >> ${DAMAKEFILE}
332 COMMAND @echo "clean:" >> ${DAMAKEFILE}
333 COMMAND @echo -e '\t@rm -f ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe ${DAMODULE}${SUBDAMODULE}${DANAME}da.o' >> ${DAMAKEFILE}
334 COMMAND @echo "" >> ${DAMAKEFILE}
335 COMMAND @echo "install: ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe" >> ${DAMAKEFILE}
336 COMMAND @echo -e '\tif [ $$(INSTALL_PATH) == '' ]; then \\' >> ${DAMAKEFILE}
337 COMMAND @echo -e '\techo Environment variable INSTALL_PATH undefined, cannot continue\; \\' >> ${DAMAKEFILE}
338 COMMAND @echo -e '\texit 1\; \\' >> ${DAMAKEFILE}
339 COMMAND @echo -e '\tfi' >> ${DAMAKEFILE}
340 COMMAND @echo -e '\t@cp -p ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe $$(INSTALL_PATH)' >> ${DAMAKEFILE}
341 )
342
343 add_custom_target(DATAR_${DAEXE}_)
344 add_custom_command( 
345 TARGET DATAR_${DAEXE}_
346 COMMAND @echo "***** Making archive ${DATAR} *****"
347 COMMAND rm -rf ${DATAR}
348 COMMAND rm -rf junk
349 COMMAND mkdir junk && mkdir junk/${DAARC} 
350         COMMAND cp -a ${CMAKE_SOURCE_DIR}/${DASRC} junk/${DAARC} 
351 COMMAND cp -a ${DAMAKEFILE} junk/${DAARC}/Makefile 
352 COMMAND cp -a ${DASPECFILE} junk/${DAARC}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec
353 COMMAND cd junk && tar czf ${DATAR} * 
354 COMMAND cd .. && rm -rf junk
355 )
356 add_dependencies(DATAR_${DAEXE}_ DAMAKEFILE_${DAEXE}_ DASPECFILE_${DAEXE}_ ${DASRC}) 
357
358 add_custom_target(DASPECFILE_${DAEXE}_)
359
360 add_custom_command(
361 TARGET DASPECFILE_${DAEXE}_
362 COMMAND rm -f ${DASPECFILE}
363 COMMAND @echo "***** Making RPM spec-file ${DASPECFILE} *****"
364 COMMAND @echo '\# RPM specfile for $(DAMODULE)${SUBDAMODULE}$(DANAME) Detector Algorithm' >> ${DASPECFILE}
365 COMMAND @echo "Summary: ${ONLINEDETECTORNAME} Detector Algorithm" >> ${DASPECFILE}
366 COMMAND @echo "Name: ${DAARCNAME}" >> ${DASPECFILE}
367 COMMAND @echo "Version: ${DAVERSION}" >> ${DASPECFILE}
368 COMMAND @echo "Release: ${DAALIROOTRELEASE}.${DAREVISION}" >> ${DASPECFILE}
369 COMMAND @echo "License: CERN Alice DAQ/Offine" >> ${DASPECFILE}
370 COMMAND @echo "Source: %{name}-%{version}.src.tar.gz" >> ${DASPECFILE}
371 COMMAND @echo "Group: Applications/Alice" >> ${DASPECFILE}
372 COMMAND @echo "Prefix: /opt/%{name}" >> ${DASPECFILE}
373 COMMAND @echo "BuildRoot: %{_tmppath}/%{name}-root" >> ${DASPECFILE}
374 COMMAND @echo "" >> ${DASPECFILE}
375 COMMAND @echo '\# automatic dependencies' >> ${DASPECFILE}
376 COMMAND @echo "AutoReqProv: yes" >> ${DASPECFILE}
377 COMMAND @echo "" >> ${DASPECFILE}
378 COMMAND @echo '\# list here required RPM packages for compilation' >> ${DASPECFILE}
379 COMMAND @echo "BuildRequires: date" >> ${DASPECFILE} 
380 COMMAND @echo "" >> ${DASPECFILE}
381 COMMAND @echo '\# list here required RPM packages for runtime' >> ${DASPECFILE}
382 COMMAND @echo "Requires: date" >> ${DASPECFILE}
383 COMMAND @echo "" >> ${DASPECFILE}    
384 COMMAND @echo '\# You can specify other dependencies in the description tag below.' >> ${DASPECFILE}
385 COMMAND @echo "" >> ${DASPECFILE}
386 COMMAND @echo '\# description of the package' >> ${DASPECFILE}
387 COMMAND @echo "%description" >> ${DASPECFILE}
388 COMMAND @echo "This is the ${ONLINEDETECTORNAME} ${DANAME} DA for online calibration." >> ${DASPECFILE}
389 COMMAND @echo "It uses data from ${DAMODULE} detectors at run time." >> ${DASPECFILE}
390 COMMAND @echo "Build requires: daqDAlib, date, AliRoot ${DAALIROOTRELEASE},ROOT ${DAROOTRELEASE}." >> ${DASPECFILE}
391 COMMAND @echo "Runtime requires: date." >> ${DASPECFILE}
392 COMMAND @echo "Contact: ${DACONTACT}" >> ${DASPECFILE}
393 COMMAND @echo "Link: ${DALINKPAGE}" >> ${DASPECFILE}
394 COMMAND @echo "Reference Run: ${DAREFRUN}" >> ${DASPECFILE}
395 COMMAND @echo "Run type: ${DARUNTYPE}" >> ${DASPECFILE}
396 COMMAND @echo "DA type: ${DATYPE}" >> ${DASPECFILE}
397 COMMAND @echo "Number of events needed: ${DANUMBEROFEVENTS}" >> ${DASPECFILE}
398 COMMAND @echo "Input files: ${DAINPUTFILES}" >> ${DASPECFILE}
399 COMMAND @echo "Output files: ${DAOUTPUTFILES}" >> ${DASPECFILE}
400 COMMAND @echo "Trigger types used: ${DATRIGGERTYPE}" >> ${DASPECFILE}
401 COMMAND @echo "" >> ${DASPECFILE}
402 COMMAND @echo '\#*****************************************************************' >> ${DASPECFILE}
403 COMMAND @echo '\# Do not modify following scripts' >> ${DASPECFILE}
404 COMMAND @echo '\#*****************************************************************' >> ${DASPECFILE}
405 COMMAND @echo "" >> ${DASPECFILE}
406 COMMAND @echo "%define debug_package %{nil}" >> ${DASPECFILE}
407 COMMAND @echo "%define __os_install_post %{nil}" >> ${DASPECFILE}
408 COMMAND @echo "" >> ${DASPECFILE}
409 COMMAND @echo '\# here is defined the installation root directory' >> ${DASPECFILE}
410 COMMAND @echo "%define pkgname %{name}-%{version}" >> ${DASPECFILE}
411 COMMAND @echo "%define destdir %{prefix}" >> ${DASPECFILE}
412 COMMAND @echo "" >> ${DASPECFILE}
413 COMMAND @echo '\# pre-compilation script: extract from tarball' >> ${DASPECFILE}
414 COMMAND @echo "%prep" >> ${DASPECFILE}
415 COMMAND @echo '\# extract archive' >> ${DASPECFILE}
416 COMMAND @echo "%setup -n %{pkgname}" >> ${DASPECFILE}
417 COMMAND @echo "" >> ${DASPECFILE}
418 COMMAND @echo '\# compile' >> ${DASPECFILE}
419 COMMAND @echo "%build" >> ${DASPECFILE}
420 COMMAND @echo "export DATE_SITE=" >> ${DASPECFILE}
421 COMMAND @echo ". /date/setup.sh" >> ${DASPECFILE}
422 COMMAND @echo "gmake" >> ${DASPECFILE}
423 COMMAND @echo "" >> ${DASPECFILE}
424 COMMAND @echo '\# install runtime files' >> ${DASPECFILE}
425 COMMAND @echo "%install" >> ${DASPECFILE}
426 COMMAND @echo '\#remove install dir if existing' >> ${DASPECFILE}
427 COMMAND echo  '[ -d ''$$''RPM_BUILD_ROOT ] && rm -rf ''$$''RPM_BUILD_ROOT' >> ${DASPECFILE}
428 COMMAND @echo '\#make install in install root directory' >> ${DASPECFILE}
429 COMMAND @echo 'mkdir -p ''$$''RPM_BUILD_ROOT%{prefix}' >> ${DASPECFILE}
430 COMMAND @echo 'make install INSTALL_PATH=''$$''RPM_BUILD_ROOT%{prefix}' >> ${DASPECFILE}
431 COMMAND @echo "" >> ${DASPECFILE}
432 COMMAND @echo '\# clean RPM build files' >> ${DASPECFILE}
433 COMMAND @echo "%clean" >> ${DASPECFILE}
434 COMMAND @echo '\# remove installed files' >> ${DASPECFILE}
435 COMMAND @echo 'rm -rf ''$$''RPM_BUILD_ROOT' >> ${DASPECFILE}
436 COMMAND @echo '\# remove source files' >> ${DASPECFILE}
437 COMMAND @echo 'rm -rf ''$$''RPM_BUILD_DIR/%{pkgname}' >> ${DASPECFILE}
438 COMMAND @echo "" >> ${DASPECFILE}
439 COMMAND @echo '\# pre-install script' >> ${DASPECFILE}
440 COMMAND @echo "%pre" >> ${DASPECFILE}
441 COMMAND @echo "" >> ${DASPECFILE}
442 COMMAND @echo '\# list of files to be installed' >> ${DASPECFILE}
443 COMMAND @echo "%files" >> ${DASPECFILE}
444 COMMAND @echo '%defattr (-,root,root)' >> ${DASPECFILE}
445 COMMAND @echo "%{destdir}" >> ${DASPECFILE}
446 COMMAND @echo "" >> ${DASPECFILE}
447 COMMAND @echo '\# post-install script' >> ${DASPECFILE}
448 COMMAND @echo '\# launched after rpm installed' >> ${DASPECFILE}
449 COMMAND @echo "%post" >> ${DASPECFILE}
450 COMMAND @echo "" >> ${DASPECFILE}
451 COMMAND @echo '\# post-uninstall script' >> ${DASPECFILE}
452 COMMAND @echo '\# launched after rpm removed' >> ${DASPECFILE}
453 COMMAND @echo "%postun" >> ${DASPECFILE}
454 )
455
456
457 add_custom_target( ${DATARGETNAME}-rpm
458 )
459 add_dependencies(${DATARGETNAME}-rpm DATAR_${DAEXE}_ DASPECFILE_${DAEXE}_ ${LIBPATH} ${DALIB}.a DADEP_${DAEXE}_ ${ROOTLIB}     
460 )
461 add_custom_command(TARGET ${DATARGETNAME}-rpm
462 COMMAND mkdir -p ${CMAKE_BINARY_DIR}/junk/SOURCES ${CMAKE_BINARY_DIR}/junk/SPECS ${CMAKE_BINARY_DIR}/junk/BUILD ${CMAKE_BINARY_DIR}/junk/RPMS ${CMAKE_BINARY_DIR}/junk/SRPMS
463 COMMAND cp ${DATAR} ${CMAKE_BINARY_DIR}/junk/SOURCES
464 COMMAND rpmbuild --verbose --define "_topdir ${CMAKE_BINARY_DIR}/junk" --nodeps -bb ${DASPECFILE}
465 COMMAND cp `find './junk/' -name '${DAARC}*.rpm'` ./ 
466 COMMAND rm -rf junk
467 COMMAND echo "***** RPMS created and put ${CMAKE_BINARY_DIR} folder *****"
468 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}  
469 )
470
471
472 add_custom_target(${DAEXE}
473 COMMAND echo "***** Making executable ${DAEXE} *****"
474 COMMAND g++ ${LDFLAGS} ${DAOBJ} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${DALIB}.a ${EXTRAROOTLIB} ${ROOTSYS}/lib/libRoot.a ${ROOTSYS}/lib/liblzma.a ${ROOTSYS}/lib/libfreetype.a ${ROOTSYS}/lib/libpcre.a  ${SYSLIBS} ${DAQDALIB} ${AMOREDALIBS} ${MONITORLIBS} -o ${DAEXE}
475 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
476 )
477
478
479 #target_link_libraries(${DAEXE} "-L" "lib${DALIB}.a" ${DAOBJ} ${EXTRAROOTLIB} "${ROOTALIBDIR}/libRoot.a" "${ROOTALIBDIR}/libfreetype.a" "${ROOTALIBDIR}/libpcre.a" ${SYSLIBS} ${DAQDALIB} ${MONITORLIBS} ${AMOREDALIBS})
480
481 add_dependencies(${DAEXE} ${DASRC} DAOBJ_${DAEXE}_ ${BINPATH} ${LIBPATH} ${DALIB}.a ${DAQDALIB} ${ROOTLIB})
482
483       add_custom_target(${DADYNEXE}
484         COMMAND echo "***** Making executable ${DADYNEXE} *****"
485         COMMAND g++ ${LDFLAGS} -L${CMAKE_LIBRARY_OUTPUT_DIRECTORY} ${DAOBJ} ${ALIROOTDLIBS} ${ROOTDLIBS} ${SYSLIBS} ${DAQDALIB} ${AMOREDADLIBS} ${MONITORLIBS} -o ${DADYNEXE}
486         WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
487         )
488       add_dependencies(${DADYNEXE} ${DASRC} DAOBJ_${DAEXE}_ ${BINPATH} ${LIBPATH} ${DAQDALIB} ${ALIROOTDLIBS})
489
490 add_custom_target(DAOBJ_${DAEXE}_
491 )
492 add_custom_command(
493 TARGET DAOBJ_${DAEXE}_
494 COMMAND echo "***** Compiling ${DASRC} *****"
495 COMMAND echo "${DFLAGS}"
496         COMMAND g++ -c ${AMOREDEFINITIONS} -D${CMAKE_SYSTEM_NAME} ${DATE_CFLAGS} -I${DATE_ROOT}/infoLogger -I${DATE_ROOT}/logbook -I${DAQDADIR} -I${CMAKE_SOURCE_DIR}/RAW -I${CMAKE_BINARY_DIR}/include -I${ROOTINCDIR} ${mod} ${date_head} ${CMAKE_SOURCE_DIR}/${DASRC} -o ${DAOBJ}
497         #COMMAND g++ -c ${DATEFLAGS} -I${DAQDADIR} -I${CMAKE_SOURCE_DIR}/RAW -I${CMAKE_BINARY_DIR}/include -I${ROOTINCDIR} ${mod} ${date_head} ${CMAKE_SOURCE_DIR}/${DASRC} -o ${DAOBJ}
498 # -DDATE_SYS=${CMAKE_SYSTEM_NAME} -DDATE_SYS=Linux -Dlong32="int" -Dlong64="long long" -DdatePointer="long" -I${DATE_ROOT}/rorc -I${DATE_ROOT}/runControl -I${DATE_ROOT}/readList -I${DATE_ROOT}/eventBuilder -I${DATE_ROOT}/banksManager -I${DATE_ROOT}/bufferManager -I${DATE_ROOT}/db -I${DATE_ROOT}/commonDefs -I${DATE_ROOT}/monitoring
499         WORKING_DIRECTORY ${CMAKE_BINARY_DIR}  
500         # ${CMAKE_SOURCE_DIR} 
501 )
502 add_dependencies(DAOBJ_${DAEXE}_ DADEP_${DAEXE}_ )
503
504
505 add_custom_target(DADEP_${DAEXE}_)
506 add_custom_command(
507 TARGET DADEP_${DAEXE}_
508 COMMAND echo "***** Making detector-algorithm dependencies ${DADEP} *****"
509         COMMAND g++ -MM ${DATE_CFLAGS} -I${DAQDADIR} -I${CMAKE_SOURCE_DIR}/RAW -I${CMAKE_BINARY_DIR}/include -I${ROOTINCDIR} ${mod} ${date_head} ${CMAKE_SOURCE_DIR}/${DASRC} > ${DADEP}
510         WORKING_DIRECTORY ${CMAKE_BINARY_DIR}  
511         # ${CMAKE_SOURCE_DIR}
512         # -DDATE_SYS=Linux -Dlong32="int" -Dlong64="long long" -DdatePointer="long" -I${DATE_ROOT}/rorc -I${DATE_ROOT}/runControl -I${DATE_ROOT}/readList -I${DATE_ROOT}/eventBuilder -I${DATE_ROOT}/banksManager -I${DATE_ROOT}/bufferManager -I${DATE_ROOT}/db -I${DATE_ROOT}/commonDefs -I${DATE_ROOT}/monitoring -I${DATE_ROOT}/infoLogger -I${DATE_ROOT}/logbook
513 )
514
515
516 add_custom_command(TARGET clean
517 COMMAND rm -rf junk*.exe
518 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
519       add_custom_command(TARGET clean
520         COMMAND rm -rf ${DADYNEXE}
521         WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
522   
523
524         endif(match)
525   endforeach(dafile)
526 endforeach(detector)