Fix for side-effect bug causing incorrect filling of the trigger mask when the event...
[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
e74cf56b 72
6db31708 73set(EXTRAROOTLIB "libRootExtra.a")
9372fe67 74
6db31708 75file(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 76
e74cf56b 77add_library(${EXTRAROOTLIB} STATIC ${_extraroot})
78set_target_properties(${EXTRAROOTLIB} PROPERTIES LINKER_LANGUAGE CXX)
79
9372fe67 80set(DAQDALIB_PATH $ENV{DAQDALIB_PATH})
81if(DAQDALIB_PATH)
82 set(DAQDADIR "${DAQDALIB_PATH}")
83else()
84 set(DAQDADIR "$ENV{ALICE}/daqDAlib")
85endif(DAQDALIB_PATH)
86set(DAQDALIB "${DAQDADIR}/libdaqDA.a")
87
e74cf56b 88include_directories(${DAQDADIR} RAW include)
9372fe67 89include_directories(SYSTEM ${ROOTINCDIR})
90
6db31708 91# ----------Create All Valid targets---------
92
93foreach(detector ${ONLINEDETECTORS} )
94
95 #ALIROOTALIBS
9372fe67 96
6db31708 97 set(ALIROOTALIBS)
9372fe67 98
6db31708 99 list(APPEND ALIROOTALIBS RAWDatabase_a RAWDatarec_a RAWDatasim_a STEERBase_a STEER_a CDB_a ESD_a STAT_a AOD_a )
100
101 set(ONLINEDETECTORNAME ${detector})
9372fe67 102
6db31708 103 detector_module(DAMODULE ${ONLINEDETECTORNAME})
9372fe67 104
6db31708 105 detector_subda(SUBDAMODULE ${ONLINEDETECTORNAME})
9372fe67 106
6db31708 107#Get detector algorithms for this detector
9372fe67 108
6db31708 109 foreach(dafile ${_dafiles})
9372fe67 110
6db31708 111 string(REGEX MATCH "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}" match ${dafile})
112#Found a valid target name
113 if(match)
114 string(REGEX REPLACE "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}(.*)da\\.cxx" "\\1" DANAME ${dafile})
115#Check for default DA
116 if(DANAME)
117 set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}-${DANAME}")
118 else()
119 set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}")
120 endif(DANAME)
6db31708 121
122 set(DATARGETDIR "${DAINSTALL}/${DAMODULE}/tgt_$ENV{ALICE_TARGET}")
123 file(MAKE_DIRECTORY ${DATARGETDIR})
124
125 set(DASRC "${DAMODULE}/${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx")
126 set(DALIB "${DAMODULE}${SUBDAMODULE}${DANAME}DA")
127 set(DAEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da")
128
129 # DAVERSION
130 execute_process(COMMAND svn info $ENV{ALICE_ROOT}/${DASRC} OUTPUT_VARIABLE _daversion OUTPUT_STRIP_TRAILING_WHITESPACE)
131 string(REGEX REPLACE ".*Last Changed Rev: ([^\n]+)\n.*" "\\1" DAVERSION ${_daversion})
132
133 # DAROOTRELEASE
134 execute_process(COMMAND root-config --version OUTPUT_VARIABLE _darootrelease OUTPUT_STRIP_TRAILING_WHITESPACE)
135 string(REGEX REPLACE "/" "." DAROOTRELEASE ${_darootrelease})
136
137 # DAALIROOTRELEASE
138 string(REGEX REPLACE ".*URL: .*/(.+)/${DASRC}.*$" "\\1" DAALIROOTRELEASE ${_daversion})
139
140 set(DAARCNAME "${DATARGETNAME}")
141 set(DAARC "${DAARCNAME}-${DAVERSION}")
142 set(DATAR "${DATARGETDIR}/${DAARC}.src.tar.gz")
143 set(DASPECFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec")
144 set(DAMAKEFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.make")
6db31708 145
6db31708 146
147# Super Duper Hack :D
148 file(GLOB _damodule "$ENV{ALICE_ROOT}/${DAMODULE}/lib${DAMODULE}*.pkg" )
149
6db31708 150 foreach(_submodule ${_damodule})
151 string(REGEX REPLACE ".*lib(${DAMODULE}.*)" "\\1" _submodule ${_submodule})
152 string(REGEX REPLACE "\\.pkg" "_a" _submodule ${_submodule})
153 list(APPEND ALIROOTALIBS "${_submodule}")
6db31708 154 endforeach(_submodule)
155
6db31708 156 list(REMOVE_DUPLICATES ALIROOTALIBS)
157 if(EXTRADAMODULE)
158 ##**set
159 endif(EXTRADAMODULE)
160
161 file(READ "$ENV{ALICE_ROOT}/${DASRC}" _dasrc)
162 getinfo(DACONTACT "Contact" ${_dasrc})
163 getinfo(DALINKPAGE "Link" ${_dasrc})
164 getinfo(DAREFRUN "Reference Run" ${_dasrc})
165 getinfo(DARUNTYPE "Run Type" ${_dasrc})
166 getinfo(DATYPE "DA Type" ${_dasrc})
167 getinfo(DANUMBEROFEVENTS "Number of events needed" ${_dasrc})
168 getinfo(DAINPUTFILES "Input Files" ${_dasrc})
169 getinfo(DAOUTPUTFILES "Output Files" ${_dasrc})
170 getinfo(DATRIGGERTYPE "Trigger types used" ${_dasrc})
171
172 if(NOT _dasrc)
173 message(FATAL_ERROR "SRC FILE MISSING")
174 endif(NOT _dasrc)
175
6db31708 176#----------- Targets ----------------------
177
9372fe67 178 set(CMAKE_CXX_FLAGS ${CXXFLAGS})
179 set(CMAKE_C_FLAGS ${CFLAGS})
180 set(CMAKE_Fortran_FLAGS ${FFLAGS})
6db31708 181 set(CMAKE_SHARED_LINKER_FLAGS ${SOFLAGS})
182 set(CMAKE_MODULE_LINKER_FLAGS ${LDFLAGS})
183
6db31708 184 set(ZIP)
185 foreach(_lib ${ALIROOTALIBS})
186 string(REGEX REPLACE "-all" "_a" _lib ${_lib})
187 list(APPEND ZIP && ar x "../lib${_lib}.a")
188 endforeach(_lib)
189 list (APPEND ZIP && ar r "../${DALIB}.a" "*.o")
190
191 add_custom_target("${DALIB}_x" rm -rf junk && mkdir -p junk
192 COMMAND cd junk ${ZIP}
193 COMMAND cd ../ && rm -rf junk
194 DEPENDS ${ALIROOTALIBS}
195 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
196
197 add_custom_target(${DATARGETNAME} DEPENDS ${DAEXE} )
198 add_executable(${DAEXE} ${DASRC} )
199 set_property(TARGET ${DAEXE} PROPERTY EXCLUDE_FROM_ALL TRUE)
200 add_dependencies(${DAEXE} ${DALIB}_x)
201 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})
e74cf56b 202
203# add_custom_command(TARGET ${DAEXE}
204# PRE_LINK
205# COMMAND ${CMAKE_AR} r ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EXTRAROOTLIB} ${_extraroot})
6db31708 206 endif(match)
207 endforeach(dafile)
208endforeach(detector)