Add AnalysisTask for mini jet activity
[u/mrichter/AliRoot.git] / cmake / CMakeDA.cmake
CommitLineData
9372fe67 1cmake_minimum_required(VERSION 2.8.2 FATAL_ERROR)
6db31708 2
3# -----------Utilities--------------------
4
5#list of detectors
6set(ONLINEDETECTORS SPD SDD SSD TPC TRD TOF HMP PHS CPV PMD MCH MTR FMD T00 V00 ZDC ACO TRI EMC HLT TST GRP)
7
8#function to get module for detector
9function (detector_module _module detector)
10 #Map of online detectors to DA in pairs of ONLINEDETECTORNAME DAMODULE
11 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)
12 list(FIND DETECTORMODULEMAP ${detector} _index)
13 if(_index STREQUAL "-1")
14 set(${_module} "${detector}" PARENT_SCOPE)
15 else()
16 math(EXPR _index "${_index}+1")
17 list(GET DETECTORMODULEMAP ${_index} _index)
18 set(${_module} ${_index} PARENT_SCOPE)
19 endif(_index STREQUAL "-1")
20endfunction()
21
22#function to get subDA for detector
23function (detector_subda _subda detector)
24 #Map of online detectors to SUBDAMODULE in pairs of ONLINEDETECTORNAME SUBDAMODULE
25 set (DETECTORSUBDAMAP SPD SPD SDD SDD SSD SSD CPV CPV MCH TRK MTR TRG)
26 list(FIND DETECTORSUBDAMAP ${detector} _index)
27 if(_index STREQUAL "-1")
28 set(${_subda} "" PARENT_SCOPE)
29 else()
30 math(EXPR _index "${_index}+1")
31 list(GET DETECTORSUBDAMAP ${_index} _index)
32 set(${_subda} ${_index} PARENT_SCOPE)
33 endif(_index STREQUAL "-1")
34endfunction()
35
36#function to extract info
37function (getinfo _info pattern file)
38 string(REGEX MATCH "${pattern}:[^\n]*" _match ${file})
39 if(_match)
40 string(REGEX REPLACE "${pattern}:[ ]*" "" _data ${_match})
41 endif(_match)
42 set(${_info} ${_data} PARENT_SCOPE)
43endfunction()
44
45# ----------Common stuff-------------------
46
47file(GLOB_RECURSE _dafiles $ENV{ALICE_ROOT}/*da.cxx)
9372fe67 48set(DAINSTALL "$ENV{ALICE_INSTALL}/DA")
6db31708 49
50file(MAKE_DIRECTORY ${DAINSTALL})
51
9372fe67 52string (REPLACE "-pedantic-errors" "" CXXFLAGS ${CXXFLAGS})
6db31708 53
6db31708 54find_program(XML2 xml2-config)
55
9372fe67 56if(AMORE_FOUND)
57 #Set compiler flags
58 set(CXXFLAGS "${CXXFLAGS} ${AMOREFLAGS}")
59 set(CFLAGS "${CFLAGS} ${AMOREFLAGS}")
60 set(CINTFLAGS "${CINTFLAGS} ${AMOREFLAGS}")
6db31708 61else()
62 set(AMORELIBS)
9372fe67 63endif(AMORE_FOUND)
6db31708 64
6db31708 65execute_process(COMMAND ${XML2} --libs OUTPUT_VARIABLE _xml2libs OUTPUT_STRIP_TRAILING_WHITESPACE)
9372fe67 66execute_process(COMMAND ${DATE_CONFIG} --monitorlibs=noshift OUTPUT_VARIABLE MONITORLIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
6db31708 67
9372fe67 68separate_arguments(MONITORLIBS)
6db31708 69
6db31708 70set(SYSLIBS -ldl -lpthread ${_xml2libs})
9372fe67 71
6db31708 72set(EXTRAROOTLIB "libRootExtra.a")
9372fe67 73
6db31708 74file(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")
9372fe67 75
76set(DAQDALIB_PATH $ENV{DAQDALIB_PATH})
77if(DAQDALIB_PATH)
78 set(DAQDADIR "${DAQDALIB_PATH}")
79else()
80 set(DAQDADIR "$ENV{ALICE}/daqDAlib")
81endif(DAQDALIB_PATH)
82set(DAQDALIB "${DAQDADIR}/libdaqDA.a")
83
84include_directories(${DAQDADIR} RAW)
85include_directories(SYSTEM ${ROOTINCDIR})
86
6db31708 87#message("${_extraroot}")
88
89
90#add_custom_target(TARGET ${EXTRAROOTLIB} COMMAND ${CMAKE_AR} r $ENV{ALICE_INSTALL}/lib/tgt_$ENV{ALICE_TARGET}/${EXTRAROOTLIB} ${_extraroot} COMMAND pwd)
91
92message("RAW SRCS ${RAWDatabase_SRC}")
93
94# ----------Create All Valid targets---------
95
96foreach(detector ${ONLINEDETECTORS} )
97
98 #ALIROOTALIBS
9372fe67 99
6db31708 100 set(ALIROOTALIBS)
9372fe67 101
6db31708 102 list(APPEND ALIROOTALIBS RAWDatabase_a RAWDatarec_a RAWDatasim_a STEERBase_a STEER_a CDB_a ESD_a STAT_a AOD_a )
103
104 set(ONLINEDETECTORNAME ${detector})
9372fe67 105
6db31708 106 detector_module(DAMODULE ${ONLINEDETECTORNAME})
9372fe67 107
6db31708 108 detector_subda(SUBDAMODULE ${ONLINEDETECTORNAME})
9372fe67 109
6db31708 110#Get detector algorithms for this detector
9372fe67 111
6db31708 112 foreach(dafile ${_dafiles})
9372fe67 113
6db31708 114 string(REGEX MATCH "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}" match ${dafile})
115#Found a valid target name
116 if(match)
117 string(REGEX REPLACE "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}(.*)da\\.cxx" "\\1" DANAME ${dafile})
118#Check for default DA
119 if(DANAME)
120 set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}-${DANAME}")
121 else()
122 set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}")
123 endif(DANAME)
124 message("${DATARGETNAME}")
125
126 set(DATARGETDIR "${DAINSTALL}/${DAMODULE}/tgt_$ENV{ALICE_TARGET}")
127 file(MAKE_DIRECTORY ${DATARGETDIR})
128
129 set(DASRC "${DAMODULE}/${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx")
130 set(DALIB "${DAMODULE}${SUBDAMODULE}${DANAME}DA")
131 set(DAEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da")
132
133 # DAVERSION
134 execute_process(COMMAND svn info $ENV{ALICE_ROOT}/${DASRC} OUTPUT_VARIABLE _daversion OUTPUT_STRIP_TRAILING_WHITESPACE)
135 string(REGEX REPLACE ".*Last Changed Rev: ([^\n]+)\n.*" "\\1" DAVERSION ${_daversion})
136
137 # DAROOTRELEASE
138 execute_process(COMMAND root-config --version OUTPUT_VARIABLE _darootrelease OUTPUT_STRIP_TRAILING_WHITESPACE)
139 string(REGEX REPLACE "/" "." DAROOTRELEASE ${_darootrelease})
140
141 # DAALIROOTRELEASE
142 string(REGEX REPLACE ".*URL: .*/(.+)/${DASRC}.*$" "\\1" DAALIROOTRELEASE ${_daversion})
143
144 set(DAARCNAME "${DATARGETNAME}")
145 set(DAARC "${DAARCNAME}-${DAVERSION}")
146 set(DATAR "${DATARGETDIR}/${DAARC}.src.tar.gz")
147 set(DASPECFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec")
148 set(DAMAKEFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.make")
6db31708 149
6db31708 150
151# Super Duper Hack :D
152 file(GLOB _damodule "$ENV{ALICE_ROOT}/${DAMODULE}/lib${DAMODULE}*.pkg" )
153
154 message(${_damodule})
155 foreach(_submodule ${_damodule})
156 string(REGEX REPLACE ".*lib(${DAMODULE}.*)" "\\1" _submodule ${_submodule})
157 string(REGEX REPLACE "\\.pkg" "_a" _submodule ${_submodule})
158 list(APPEND ALIROOTALIBS "${_submodule}")
159 message("Adding ${_submodule}")
160 endforeach(_submodule)
161
162# file(WRITE "$ENV{ALICE_INSTALL}/tmp" "list(APPEND ALIROOTALIBS ${DAMODULE}-all)")
163# include("$ENV{ALICE_INSTALL}/tmp")
164
165 list(REMOVE_DUPLICATES ALIROOTALIBS)
166 if(EXTRADAMODULE)
167 ##**set
168 endif(EXTRADAMODULE)
169
170 file(READ "$ENV{ALICE_ROOT}/${DASRC}" _dasrc)
171 getinfo(DACONTACT "Contact" ${_dasrc})
172 getinfo(DALINKPAGE "Link" ${_dasrc})
173 getinfo(DAREFRUN "Reference Run" ${_dasrc})
174 getinfo(DARUNTYPE "Run Type" ${_dasrc})
175 getinfo(DATYPE "DA Type" ${_dasrc})
176 getinfo(DANUMBEROFEVENTS "Number of events needed" ${_dasrc})
177 getinfo(DAINPUTFILES "Input Files" ${_dasrc})
178 getinfo(DAOUTPUTFILES "Output Files" ${_dasrc})
179 getinfo(DATRIGGERTYPE "Trigger types used" ${_dasrc})
180
181 if(NOT _dasrc)
182 message(FATAL_ERROR "SRC FILE MISSING")
183 endif(NOT _dasrc)
184
6db31708 185#----------- Targets ----------------------
186
9372fe67 187 set(CMAKE_CXX_FLAGS ${CXXFLAGS})
188 set(CMAKE_C_FLAGS ${CFLAGS})
189 set(CMAKE_Fortran_FLAGS ${FFLAGS})
6db31708 190 set(CMAKE_SHARED_LINKER_FLAGS ${SOFLAGS})
191 set(CMAKE_MODULE_LINKER_FLAGS ${LDFLAGS})
192
6db31708 193 set(ZIP)
194 foreach(_lib ${ALIROOTALIBS})
195 string(REGEX REPLACE "-all" "_a" _lib ${_lib})
196 list(APPEND ZIP && ar x "../lib${_lib}.a")
197 endforeach(_lib)
198 list (APPEND ZIP && ar r "../${DALIB}.a" "*.o")
199
200 add_custom_target("${DALIB}_x" rm -rf junk && mkdir -p junk
201 COMMAND cd junk ${ZIP}
202 COMMAND cd ../ && rm -rf junk
203 DEPENDS ${ALIROOTALIBS}
204 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
205
206 add_custom_target(${DATARGETNAME} DEPENDS ${DAEXE} )
207 add_executable(${DAEXE} ${DASRC} )
208 set_property(TARGET ${DAEXE} PROPERTY EXCLUDE_FROM_ALL TRUE)
209 add_dependencies(${DAEXE} ${DALIB}_x)
210 target_link_libraries(${DAEXE} "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DALIB}.a" ${EXTRAROOTLIB} "${ROOTLIBDIR}/libRoot.a" "${ROOTLIBDIR}/libfreetype.a" "${ROOTLIBDIR}/libpcre.a" ${SYSLIBS} ${DAQDALIB} ${MONITORLIBS} ${AMOREDALIBS})
211 add_custom_command(TARGET ${DAEXE}
212 PRE_LINK
213 COMMAND ${CMAKE_AR} r ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EXTRAROOTLIB} ${_extraroot})
6db31708 214 endif(match)
215 endforeach(dafile)
216endforeach(detector)