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