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${ALICE_ROOT}/${h_module}")
70 endforeach(oldetect ${ONLINEDETECTORS})
71 list(APPEND mod "-I${ALICE_ROOT}/include" "-I${ALICE_ROOT}/STEER" "-I${ALICE_ROOT}/ANALYSIS" "-I${ALICE_ROOT}/RAW" "-I${ALICE_ROOT}/STEER/STEER" "-I${ALICE_ROOT}/STEER/CDB" "-I${ROOTSYS}/include" "-I${ALICE_ROOT}/STEER/STEERBase" "-I${ALICE_ROOT}/STEER/AOD" "-I${ALICE_ROOT}/STEER/ESD" "-I${ALICE_ROOT}/MUON/mapping" "-I$ENV{AMORE}/include/amore")
72
73 # ----------Common stuff-------------------
74
75 file(GLOB_RECURSE _dafiles $ENV{ALICE_ROOT}/*da.cxx)
76 set (DAINSTALL "$ENV{ALICE_INSTALL}/DA")
77 if(DAINSTALL STREQUAL "/DA") 
78   set(DAINSTALL "$ENV{ALICE_ROOT}/DA")
79 endif(DAINSTALL STREQUAL "/DA")
80
81
82 file(MAKE_DIRECTORY ${DAINSTALL})
83
84 string (REPLACE "-pedantic-errors" "" CXXFLAGS ${CXXFLAGS})
85
86 find_program(XML2 xml2-config)
87
88 if(AMORE_FOUND)
89   #Set compiler flags
90   set(CXXFLAGS "${CXXFLAGS} ${AMOREFLAGS}")
91   set(CFLAGS "${CFLAGS} ${AMOREFLAGS}")
92   set(CINTFLAGS "${CINTFLAGS} ${AMOREFLAGS}")
93 else()
94   set(AMORELIBS)
95 endif(AMORE_FOUND)
96
97 execute_process(COMMAND ${XML2} --libs OUTPUT_VARIABLE _xml2libs OUTPUT_STRIP_TRAILING_WHITESPACE)
98 execute_process(COMMAND ${DATE_CONFIG} --monitorlibs=noshift OUTPUT_VARIABLE MONITORLIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
99 execute_process(COMMAND $ENV{AMORE}/amore-config --ldflags-da-static OUTPUT_VARIABLE _amore1 OUTPUT_STRIP_TRAILING_WHITESPACE)
100 execute_process(COMMAND date-config --rcproxylibs OUTPUT_VARIABLE _amore2 OUTPUT_STRIP_TRAILING_WHITESPACE)
101 execute_process(COMMAND date-config --monitorlibs=noshift OUTPUT_VARIABLE _monitor1 OUTPUT_STRIP_TRAILING_WHITESPACE)
102 string(REPLACE "\n" " " _amore1 "${_amore1}") 
103 set(AMOREDALIBS "-static ${_amore1} ${_amore2}")
104 set(MONITORLIBS "${_monitor1}")
105
106 separate_arguments(MONITORLIBS)
107 separate_arguments(AMOREDALIBS)
108 set(SYSLIBS -ldl -lpthread ${_xml2libs})
109
110
111 set(EXTRAROOTLIB "libRootExtra.a")
112 set(ROOTLIB "RootExtra")
113 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")
114
115 add_library(${ROOTLIB} STATIC ${_extraroot})      
116 set_target_properties(${ROOTLIB} PROPERTIES LINKER_LANGUAGE CXX)
117
118 set(DAQDALIB_PATH $ENV{DAQDALIB_PATH})  
119 if(DAQDALIB_PATH)
120   set(DAQDADIR "${DAQDALIB_PATH}")
121 else()
122   set(DAQDADIR "$ENV{ALICE}/daqDAlib")
123 endif(DAQDALIB_PATH)
124 set(DAQDALIB "${DAQDADIR}/libdaqDA.a")
125
126 include_directories(${DAQDADIR} ${ALICE_ROOT}/RAW ${ALICE_ROOT}/include ${ALICE_ROOT}/STEER)
127 include_directories(SYSTEM ${ROOTINCDIR})
128
129 # ----------Create All Valid targets---------
130           
131 foreach(detector ${ONLINEDETECTORS} )
132
133   set(ONLINEDETECTORNAME ${detector})
134
135   detector_module(DAMODULE ${ONLINEDETECTORNAME})
136
137   detector_subda(SUBDAMODULE ${ONLINEDETECTORNAME})
138   
139   #ALIROOTALIBS
140
141   set(ALIROOTALIBS)
142         set(BASIC_TARGET "daqDA-${ONLINEDETECTORNAME}-all")
143         add_custom_target(${BASIC_TARGET}
144         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
145         ) 
146         set(BASIC_RPM "daqDA-${ONLINEDETECTORNAME}-all-rpm")
147         add_custom_target(${BASIC_RPM}
148         WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
149         )
150  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 )
151
152   expand(ALIROOTALIBS2 "\${${DAMODULE}ALIBS}")
153   expand(DAINCDIRS "\${${DAMODULE}INC}")
154   list(APPEND ALIROOTALIBS ${ALIROOTALIBS2})
155   
156   include_directories(${DAMODULE} ${SUBDIR} ${DAINCDIRS})
157 #Get detector algorithms for this detector
158
159   foreach(dafile ${_dafiles})
160
161         string(REGEX MATCH "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}" match ${dafile})
162 #Found a valid target name
163         if(match)
164           string(REGEX REPLACE "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}(.*)da\\.cxx" "\\1" DANAME ${dafile})
165 #Check for default DA 
166           if(DANAME)
167             set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}-${DANAME}")
168         else()
169             set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}")
170           endif(DANAME)
171         add_dependencies(${BASIC_TARGET} ${DATARGETNAME})  
172         add_dependencies(${BASIC_RPM} ${DATARGETNAME}-rpm) 
173          set(DATARGETDIR "${DAINSTALL}/${DAMODULE}/tgt_$ENV{ALICE_TARGET}")
174           file(MAKE_DIRECTORY ${DATARGETDIR})
175           set(DAOBJ "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.o")
176           set(DASRC "${DAMODULE}/${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx")
177           set(DALIB "${DAMODULE}${SUBDAMODULE}${DANAME}DA")
178           set(DAEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da.exe")
179           set(DADEP "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.d") 
180         # DAVERSION
181           execute_process(COMMAND svn info $ENV{ALICE_ROOT}/${DASRC} OUTPUT_VARIABLE _daversion OUTPUT_STRIP_TRAILING_WHITESPACE)
182           string(REGEX REPLACE ".*Last Changed Rev: ([^\n]+)\n.*" "\\1" DAVERSION ${_daversion})
183
184         #DAREVISION
185           execute_process(COMMAND svn info ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE _darevision OUTPUT_STRIP_TRAILING_WHITESPACE)
186           string(REGEX REPLACE ".*Revision: ([^\n]+)\n.*" "\\1" DAREVISION ${_darevision})
187         # DAROOTRELEASE 
188           execute_process(COMMAND root-config --version OUTPUT_VARIABLE _darootrelease OUTPUT_STRIP_TRAILING_WHITESPACE)
189           string(REGEX REPLACE "/" "." DAROOTRELEASE ${_darootrelease})
190         
191         # DAALIROOTRELEASE
192           string(REGEX REPLACE ".*URL: .*/(.+)/${DASRC}.*$" "\\1" DAALIROOTRELEASE ${_daversion})
193           string (REPLACE "-" "." DAALIROOTRELEASE "${DAALIROOTRELEASE}")
194         
195           set(DAARCNAME "${DATARGETNAME}")
196           #string(REPLACE "-" "" DAARCNAME "${DAARCNAME}")
197           set(DAARC "${DAARCNAME}-${DAVERSION}")
198           set(DATAR "${DATARGETDIR}/${DAARC}.src.tar.gz")
199           set(DASPECFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec")
200           set(DAMAKEFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.make")
201
202   
203           file(READ "$ENV{ALICE_ROOT}/${DASRC}" _dasrc)
204           getinfo(DACONTACT "Contact" ${_dasrc})
205           getinfo(DALINKPAGE "Link" ${_dasrc})
206           getinfo(DAREFRUN "Reference Run" ${_dasrc})
207           getinfo(DARUNTYPE "Run Type" ${_dasrc})
208           getinfo(DATYPE "DA Type" ${_dasrc})
209           getinfo(DANUMBEROFEVENTS "Number of events needed" ${_dasrc})
210           getinfo(DAINPUTFILES "Input Files" ${_dasrc})
211           getinfo(DAOUTPUTFILES "Output Files" ${_dasrc})
212           getinfo(DATRIGGERTYPE "Trigger types used" ${_dasrc})
213
214           if(NOT _dasrc)
215            message(FATAL_ERROR "SRC FILE MISSING")
216           endif(NOT _dasrc)
217
218 #----------- Targets ----------------------
219
220           set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
221           set(CMAKE_C_FLAGS "${CFLAGS}")
222           set(CMAKE_Fortran_FLAGS ${FFLAGS})
223           set(CMAKE_SHARED_LINKER_FLAGS ${SOFLAGS}) 
224           set(CMAKE_MODULE_LINKER_FLAGS ${LDFLAGS})
225
226 add_dependencies(DA-all ${DATARGETNAME})
227 add_custom_target(${DATARGETNAME}
228 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
229 )
230 add_dependencies(${DATARGETNAME} ${DAEXE})
231
232 set(ZIP)
233 foreach(_lib ${ALIROOTALIBS})
234 string(REGEX REPLACE "-static" "" _lib ${_lib})
235 list(APPEND ZIP && ar x "../lib${_lib}.a")
236 endforeach(_lib)
237 list (APPEND ZIP && ar r "../lib${DALIB}.a" "*.o")
238
239 add_custom_target(${DALIB}.a
240 COMMAND rm -rf junk${DAEXE} && mkdir -p junk${DAEXE}
241 COMMAND cd junk${DAEXE} ${ZIP}
242 COMMAND cd ../ && rm -rf junk${DAEXE}
243 DEPENDS ${ALIROOTALIBS} 
244 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} 
245 )
246
247 add_custom_command(
248 TARGET ${DATARGETNAME}-clean
249 COMMAND echo "***** Cleaning ${DAMODULE} ${SUBDAMODULE} ${DANAME} detector-algorithm *****"
250 COMMAND rm -f ${DASPECFILE}
251 COMMAND rm -f ${DATAR}
252 COMMAND rm -f ${DAEXE}
253 COMMAND rm -f ${DAOBJ}
254 COMMAND rm -f ${DADEP}
255 COMMAND rm -f ${DAMAKEFILE}
256 COMMAND rm -f ${DALIB}.a
257 COMMAND rm -f ${ALIROOTALIBS}
258 COMMAND rm -f ${EXTRAROOTLIB}
259 )
260
261 separate_arguments(SYSLIBS)
262 #execute_process(COMMAND ${AMORE}/amore-config --ldflags-da-static | tr "\n" " "  OUTPUT_VARIABLE _amore1 OUTPUT_STRIP_TRAILING_WHITESPACE)
263 #execute_process(COMMAND date-config --rcproxylibs OUTPUT_VARIABLE _amore2 OUTPUT_STRIP_TRAILING_WHITESPACE)
264 #execute_process(COMMAND date-config --monitorlibs=noshift OUTPUT_VARIABLE _monitor1 OUTPUT_STRIP_TRAILING_WHITESPACE)
265   
266 #set(AMOREDALIBS "-static ${_amore1} ${_amore2}\\")
267 #set(MONITORLIBS "${_monitor1}\\")
268
269 add_custom_target(DAMAKEFILE_${DAEXE}_)
270 add_custom_command( 
271 TARGET DAMAKEFILE_${DAEXE}_
272 COMMAND rm -f ${DAMAKEFILE}
273 COMMAND @echo "***** Making makefile ${DAMAKEFILE} *****"
274 COMMAND @echo '\#***************************************************' >> ${DAMAKEFILE}
275 COMMAND @echo '\# Makefile for Detector Algorithm' >> ${DAMAKEFILE}
276 COMMAND @echo '\#' >> ${DAMAKEFILE}
277 COMMAND @echo '\# It is necessary to setup build environment before' >> ${DAMAKEFILE}
278 COMMAND @echo '\# using make:' >> ${DAMAKEFILE}
279 COMMAND @echo '\# - define path to daqDAlib (env. DAQDALIB_PATH)' >> ${DAMAKEFILE}
280 COMMAND @echo '\#' >> ${DAMAKEFILE}
281 COMMAND @echo '\#*****************************************************' >> ${DAMAKEFILE}
282 COMMAND @echo "" >> ${DAMAKEFILE}
283 COMMAND @echo "CXX=g++" >> ${DAMAKEFILE}
284 COMMAND @echo "LD=g++" >> ${DAMAKEFILE}
285 COMMAND @echo "" >> ${DAMAKEFILE}
286 COMMAND @echo "CXXFLAGS=${CXXFLAGS}" >> ${DAMAKEFILE}
287 COMMAND @echo "LDFLAGS=${LDFLAGS}" >> ${DAMAKEFILE}
288 COMMAND @echo "" >> ${DAMAKEFILE}
289 COMMAND @echo 'ifeq ($$(DAQDALIB_PATH),)' >> ${DAMAKEFILE}
290 COMMAND @echo "DAQDADIR=${ALICE}/daqDAlib" >> ${DAMAKEFILE}
291 COMMAND @echo "else" >> ${DAMAKEFILE}
292 COMMAND @echo 'DAQDADIR=$$(DAQDALIB_PATH)' >> ${DAMAKEFILE}
293 COMMAND @echo "endif" >> ${DAMAKEFILE}
294 COMMAND @echo "" >> ${DAMAKEFILE}
295 COMMAND @echo 'DAQDALIB=$$(DAQDADIR)/libdaqDA.a' >> ${DAMAKEFILE}
296 #COMMAND @echo 'AMOREDALIBS=-static $$(shell $$(AMORE)/amore-config --ldflags-da-static) $$(shell date-config --rcproxylibs)' >> ${DAMAKEFILE}
297 #COMMAND @echo 'MONITORLIBS=$$(shell date-config --monitorlibs=noshift)' >> ${DAMAKEFILE}
298 #COMMAND @echo 'AMOREDALIBS=-static ${_amore1} ${_amore2}' >> ${DAMAKEFILE}
299 #COMMAND @echo 'MONITORLIBS=${monitor1}' >> ${DAMAKEFILE}
300 COMMAND @echo "" >> ${DAMAKEFILE}
301 COMMAND @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.exe: ${DAMODULE}${SUBDAMODULE}${DANAME}da.o" >> ${DAMAKEFILE}
302 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}
303 COMMAND @echo "" >> ${DAMAKEFILE}
304 COMMAND @echo "${DAMODULE}${SUBDAMODULE}${DANAME}da.o: ${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx" >> ${DAMAKEFILE}
305 COMMAND @echo -e '\t$$(CXX) -c $$(CXXFLAGS) -I$$(DAQDADIR) ${mod} ''$$''< -o ''$$''@' >> ${DAMAKEFILE}
306 COMMAND @echo "" >> ${DAMAKEFILE}
307 COMMAND @echo "clean:" >> ${DAMAKEFILE}
308 COMMAND @echo -e '\t@rm -f ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe ${DAMODULE}${SUBDAMODULE}${DANAME}da.o' >> ${DAMAKEFILE}
309 COMMAND @echo "" >> ${DAMAKEFILE}
310 COMMAND @echo "install: ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe" >> ${DAMAKEFILE}
311 COMMAND @echo -e '\tif [ $$(INSTALL_PATH) == '' ]; then \\' >> ${DAMAKEFILE}
312 COMMAND @echo -e '\techo Environment variable INSTALL_PATH undefined, cannot continue\; \\' >> ${DAMAKEFILE}
313 COMMAND @echo -e '\texit 1\; \\' >> ${DAMAKEFILE}
314 COMMAND @echo -e '\tfi' >> ${DAMAKEFILE}
315 COMMAND @echo -e '\t@cp -p ${DAMODULE}${SUBDAMODULE}${DANAME}da.exe $$(INSTALL_PATH)' >> ${DAMAKEFILE}
316 )
317
318 add_custom_target(DATAR_${DAEXE}_)
319 add_custom_command( 
320 TARGET DATAR_${DAEXE}_
321 COMMAND @echo "***** Making archive ${DATAR} *****"
322 COMMAND rm -rf ${DATAR}
323 COMMAND rm -rf junk
324 COMMAND mkdir junk && mkdir junk/${DAARC} 
325 COMMAND cp -a ${ALICE_ROOT}/${DASRC} junk/${DAARC} 
326 COMMAND cp -a ${DAMAKEFILE} junk/${DAARC}/Makefile 
327 COMMAND cp -a ${DASPECFILE} junk/${DAARC}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec
328 COMMAND cd junk && tar czf ${DATAR} * 
329 COMMAND cd .. && rm -rf junk
330 )
331 add_dependencies(DATAR_${DAEXE}_ DAMAKEFILE_${DAEXE}_ DASPECFILE_${DAEXE}_ ${DASRC}) 
332
333 add_custom_target(DASPECFILE_${DAEXE}_)
334
335 add_custom_command(
336 TARGET DASPECFILE_${DAEXE}_
337 COMMAND rm -f ${DASPECFILE}
338 COMMAND @echo "***** Making RPM spec-file ${DASPECFILE} *****"
339 COMMAND @echo '\# RPM specfile for $(DAMODULE)${SUBDAMODULE}$(DANAME) Detector Algorithm' >> ${DASPECFILE}
340 COMMAND @echo "Summary: ${ONLINEDETECTORNAME} Detector Algorithm" >> ${DASPECFILE}
341 COMMAND @echo "Name: ${DAARCNAME}" >> ${DASPECFILE}
342 COMMAND @echo "Version: ${DAVERSION}" >> ${DASPECFILE}
343 COMMAND @echo "Release: ${DAALIROOTRELEASE}.${DAREVISION}" >> ${DASPECFILE}
344 COMMAND @echo "License: CERN Alice DAQ/Offine" >> ${DASPECFILE}
345 COMMAND @echo "Source: %{name}-%{version}.src.tar.gz" >> ${DASPECFILE}
346 COMMAND @echo "Group: Applications/Alice" >> ${DASPECFILE}
347 COMMAND @echo "Prefix: /opt/%{name}" >> ${DASPECFILE}
348 COMMAND @echo "BuildRoot: %{_tmppath}/%{name}-root" >> ${DASPECFILE}
349 COMMAND @echo "" >> ${DASPECFILE}
350 COMMAND @echo '\# automatic dependencies' >> ${DASPECFILE}
351 COMMAND @echo "AutoReqProv: yes" >> ${DASPECFILE}
352 COMMAND @echo "" >> ${DASPECFILE}
353 COMMAND @echo '\# list here required RPM packages for compilation' >> ${DASPECFILE}
354 COMMAND @echo "BuildRequires: date" >> ${DASPECFILE} 
355 COMMAND @echo "" >> ${DASPECFILE}
356 COMMAND @echo '\# list here required RPM packages for runtime' >> ${DASPECFILE}
357 COMMAND @echo "Requires: date" >> ${DASPECFILE}
358 COMMAND @echo "" >> ${DASPECFILE}    
359 COMMAND @echo '\# You can specify other dependencies in the description tag below.' >> ${DASPECFILE}
360 COMMAND @echo "" >> ${DASPECFILE}
361 COMMAND @echo '\# description of the package' >> ${DASPECFILE}
362 COMMAND @echo "%description" >> ${DASPECFILE}
363 COMMAND @echo "This is the ${ONLINEDETECTORNAME} ${DANAME} DA for online calibration." >> ${DASPECFILE}
364 COMMAND @echo "It uses data from ${DAMODULE} detectors at run time." >> ${DASPECFILE}
365 COMMAND @echo "Build requires: daqDAlib, date, AliRoot ${DAALIROOTRELEASE},ROOT ${DAROOTRELEASE}." >> ${DASPECFILE}
366 COMMAND @echo "Runtime requires: date." >> ${DASPECFILE}
367 COMMAND @echo "Contact: ${DACONTACT}" >> ${DASPECFILE}
368 COMMAND @echo "Link: ${DALINKPAGE}" >> ${DASPECFILE}
369 COMMAND @echo "Reference Run: ${DAREFRUN}" >> ${DASPECFILE}
370 COMMAND @echo "Run type: ${DARUNTYPE}" >> ${DASPECFILE}
371 COMMAND @echo "DA type: ${DATYPE}" >> ${DASPECFILE}
372 COMMAND @echo "Number of events needed: ${DANUMBEROFEVENTS}" >> ${DASPECFILE}
373 COMMAND @echo "Input files: ${DAINPUTFILES}" >> ${DASPECFILE}
374 COMMAND @echo "Output files: ${DAOUTPUTFILES}" >> ${DASPECFILE}
375 COMMAND @echo "Trigger types used: ${DATRIGGERTYPE}" >> ${DASPECFILE}
376 COMMAND @echo "" >> ${DASPECFILE}
377 COMMAND @echo '\#*****************************************************************' >> ${DASPECFILE}
378 COMMAND @echo '\# Do not modify following scripts' >> ${DASPECFILE}
379 COMMAND @echo '\#*****************************************************************' >> ${DASPECFILE}
380 COMMAND @echo "" >> ${DASPECFILE}
381 COMMAND @echo "%define debug_package %{nil}" >> ${DASPECFILE}
382 COMMAND @echo "%define __os_install_post %{nil}" >> ${DASPECFILE}
383 COMMAND @echo "" >> ${DASPECFILE}
384 COMMAND @echo '\# here is defined the installation root directory' >> ${DASPECFILE}
385 COMMAND @echo "%define pkgname %{name}-%{version}" >> ${DASPECFILE}
386 COMMAND @echo "%define destdir %{prefix}" >> ${DASPECFILE}
387 COMMAND @echo "" >> ${DASPECFILE}
388 COMMAND @echo '\# pre-compilation script: extract from tarball' >> ${DASPECFILE}
389 COMMAND @echo "%prep" >> ${DASPECFILE}
390 COMMAND @echo '\# extract archive' >> ${DASPECFILE}
391 COMMAND @echo "%setup -n %{pkgname}" >> ${DASPECFILE}
392 COMMAND @echo "" >> ${DASPECFILE}
393 COMMAND @echo '\# compile' >> ${DASPECFILE}
394 COMMAND @echo "%build" >> ${DASPECFILE}
395 COMMAND @echo "export DATE_SITE=" >> ${DASPECFILE}
396 COMMAND @echo ". /date/setup.sh" >> ${DASPECFILE}
397 COMMAND @echo "gmake" >> ${DASPECFILE}
398 COMMAND @echo "" >> ${DASPECFILE}
399 COMMAND @echo '\# install runtime files' >> ${DASPECFILE}
400 COMMAND @echo "%install" >> ${DASPECFILE}
401 COMMAND @echo '\#remove install dir if existing' >> ${DASPECFILE}
402 COMMAND echo  '[ -d ''$$''RPM_BUILD_ROOT ] && rm -rf ''$$''RPM_BUILD_ROOT' >> ${DASPECFILE}
403 COMMAND @echo '\#make install in install root directory' >> ${DASPECFILE}
404 COMMAND @echo 'mkdir -p ''$$''RPM_BUILD_ROOT%{prefix}' >> ${DASPECFILE}
405 COMMAND @echo 'make install INSTALL_PATH=''$$''RPM_BUILD_ROOT%{prefix}' >> ${DASPECFILE}
406 COMMAND @echo "" >> ${DASPECFILE}
407 COMMAND @echo '\# clean RPM build files' >> ${DASPECFILE}
408 COMMAND @echo "%clean" >> ${DASPECFILE}
409 COMMAND @echo '\# remove installed files' >> ${DASPECFILE}
410 COMMAND @echo 'rm -rf ''$$''RPM_BUILD_ROOT' >> ${DASPECFILE}
411 COMMAND @echo '\# remove source files' >> ${DASPECFILE}
412 COMMAND @echo 'rm -rf ''$$''RPM_BUILD_DIR/%{pkgname}' >> ${DASPECFILE}
413 COMMAND @echo "" >> ${DASPECFILE}
414 COMMAND @echo '\# pre-install script' >> ${DASPECFILE}
415 COMMAND @echo "%pre" >> ${DASPECFILE}
416 COMMAND @echo "" >> ${DASPECFILE}
417 COMMAND @echo '\# list of files to be installed' >> ${DASPECFILE}
418 COMMAND @echo "%files" >> ${DASPECFILE}
419 COMMAND @echo '%defattr (-,root,root)' >> ${DASPECFILE}
420 COMMAND @echo "%{destdir}" >> ${DASPECFILE}
421 COMMAND @echo "" >> ${DASPECFILE}
422 COMMAND @echo '\# post-install script' >> ${DASPECFILE}
423 COMMAND @echo '\# launched after rpm installed' >> ${DASPECFILE}
424 COMMAND @echo "%post" >> ${DASPECFILE}
425 COMMAND @echo "" >> ${DASPECFILE}
426 COMMAND @echo '\# post-uninstall script' >> ${DASPECFILE}
427 COMMAND @echo '\# launched after rpm removed' >> ${DASPECFILE}
428 COMMAND @echo "%postun" >> ${DASPECFILE}
429 )
430
431
432 add_custom_target( ${DATARGETNAME}-rpm
433 )
434 add_dependencies(${DATARGETNAME}-rpm DATAR_${DAEXE}_ DASPECFILE_${DAEXE}_ ${LIBPATH} ${DALIB}.a DADEP_${DAEXE}_ ${ROOTLIB}     
435 )
436 add_custom_command(TARGET ${DATARGETNAME}-rpm
437 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
438 COMMAND cp ${DATAR} ${CMAKE_BINARY_DIR}/junk/SOURCES
439 COMMAND rpmbuild --verbose --define "_topdir ${CMAKE_BINARY_DIR}/junk" --nodeps -bb ${DASPECFILE}
440 COMMAND cp `find './junk/' -name '${DAARC}*.rpm'` ./ 
441 COMMAND rm -rf junk
442 COMMAND echo "***** RPMS created and put ${CMAKE_BINARY_DIR} folder *****"
443 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}  
444 )
445
446
447 add_custom_target(${DAEXE}
448 COMMAND echo "***** Making executable ${DAEXE} *****"
449 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}
450 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
451 )
452
453
454 #target_link_libraries(${DAEXE} "-L" "lib${DALIB}.a" ${DAOBJ} ${EXTRAROOTLIB} "${ROOTALIBDIR}/libRoot.a" "${ROOTALIBDIR}/libfreetype.a" "${ROOTALIBDIR}/libpcre.a" ${SYSLIBS} ${DAQDALIB} ${MONITORLIBS} ${AMOREDALIBS})
455
456 add_dependencies(${DAEXE} ${DASRC} DAOBJ_${DAEXE}_ ${BINPATH} ${LIBPATH} ${DALIB}.a ${DAQDALIB} ${ROOTLIB})
457
458
459 add_custom_target(DAOBJ_${DAEXE}_
460 )
461 add_custom_command(
462 TARGET DAOBJ_${DAEXE}_
463 COMMAND echo "***** Compiling ${DASRC} *****"
464 COMMAND echo "${DFLAGS}"
465 COMMAND g++ -c -D${CMAKE_SYSTEM_NAME} -DDATE_SYS=${CMAKE_SYSTEM_NAME} -Dlong32="int" -Dlong64="long long" -DdatePointer="long" -I/date/rorc -I/date/runControl -I/date/readList -I/date/eventBuilder -I/date/banksManager -I/date/bufferManager -I/date/db -I/date/commonDefs -I/date/monitoring -I/date/infoLogger -I/date/logbook -I${DAQDADIR} -I${ALICE_ROOT}/RAW -I${CMAKE_BINARY_DIR}/include -I$ENV{ROOTSYS}/include ${mod} ${date_head} ${ALICE_ROOT}/${DASRC} -o ${DAOBJ}
466 #COMMAND g++ -c ${DATEFLAGS} -I${DAQDADIR} -I${ALICE_ROOT}/RAW -I${CMAKE_BINARY_DIR}/include -I$ENV{ROOTSYS}/include ${mod} ${date_head} ${ALICE_ROOT}/${DASRC} -o ${DAOBJ}
467
468 WORKING_DIRECTORY ${ALICE_ROOT} 
469 )
470 add_dependencies(DAOBJ_${DAEXE}_ DADEP_${DAEXE}_ )
471
472
473
474 add_custom_target(DADEP_${DAEXE}_)
475 add_custom_command(
476 TARGET DADEP_${DAEXE}_
477 COMMAND echo "***** Making detector-algorithm dependencies ${DADEP} *****"
478 COMMAND g++ -MM -DLinux -DDATE_SYS=Linux -Dlong32="int" -Dlong64="long long" -DdatePointer="long" -I/date/rorc -I/date/runControl -I/date/readList -I/date/eventBuilder -I/date/banksManager -I/date/bufferManager -I/date/db -I/date/commonDefs -I/date/monitoring -I/date/infoLogger -I/date/logbook -I${DAQDADIR} -I${ALICE_ROOT}/RAW -I${CMAKE_BINARY_DIR}/include -I$ENV{ROOTSYS}/include ${mod} ${date_head} ${ALICE_ROOT}/${DASRC} > ${DADEP}
479 WORKING_DIRECTORY ${ALICE_ROOT}
480 )
481
482
483 add_custom_command(TARGET clean
484 COMMAND rm -rf junk*.exe
485 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
486   
487
488         endif(match)
489   endforeach(dafile)
490 endforeach(detector)