Completely reengineered version of CMake build system (Johny)
[u/mrichter/AliRoot.git] / cmake / CMakeDA.cmake
CommitLineData
6db31708 1cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
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)
48set(DAINSTALL "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
49
50file(MAKE_DIRECTORY ${DAINSTALL})
51
52#**Set compiler flags
53
54
55find_program(AMORE amore-config)
56#temporary
57find_program(DATE date-config)
58find_program(ROOT_CONFIG root-config)
59find_program(XML2 xml2-config)
60
61if(AMORE)
62 execute_process(COMMAND ${AMORE} --cflags --includes OUTPUT_VARIABLE AMOREFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
63 #**Set compiler flags
64 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AMOREFLAGS}")
65 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${AMOREFLAGS}")
66
67 execute_process(COMMAND ${AMORE} --ldflags-da-static OUTPUT_VARIABLE _lddaflags OUTPUT_STRIP_TRAILING_WHITESPACE)
68 string(REGEX REPLACE "\n" " " _lddaflags ${_lddaflags})
69 execute_process(COMMAND ${DATE} --rcproxylibs OUTPUT_VARIABLE _rcproxylib OUTPUT_STRIP_TRAILING_WHITESPACE)
70 set(AMOREDALIBS "-static ${_lddaflags} ${_rcproxylib}")
71else()
72 set(AMORELIBS)
73endif(AMORE)
74
75execute_process(COMMAND ${ROOT_CONFIG} --libdir OUTPUT_VARIABLE ROOTLIBDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
76execute_process(COMMAND ${XML2} --libs OUTPUT_VARIABLE _xml2libs OUTPUT_STRIP_TRAILING_WHITESPACE)
77execute_process(COMMAND ${DATE} --monitorlibs=noshift OUTPUT_VARIABLE MONITORLIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
78
79
80string(REGEX REPLACE " " ";" MONITORLIBS ${MONITORLIBS})
81set(SYSLIBS -ldl -lpthread ${_xml2libs})
82set(EXTRAROOTLIB "libRootExtra.a")
83file(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")
84#message("${_extraroot}")
85
86
87#add_custom_target(TARGET ${EXTRAROOTLIB} COMMAND ${CMAKE_AR} r $ENV{ALICE_INSTALL}/lib/tgt_$ENV{ALICE_TARGET}/${EXTRAROOTLIB} ${_extraroot} COMMAND pwd)
88
89message("RAW SRCS ${RAWDatabase_SRC}")
90
91# ----------Create All Valid targets---------
92
93foreach(detector ${ONLINEDETECTORS} )
94
95 #ALIROOTALIBS
96 set(ALIROOTALIBS)
97 list(APPEND ALIROOTALIBS RAWDatabase_a RAWDatarec_a RAWDatasim_a STEERBase_a STEER_a CDB_a ESD_a STAT_a AOD_a )
98
99 set(ONLINEDETECTORNAME ${detector})
100 detector_module(DAMODULE ${ONLINEDETECTORNAME})
101 detector_subda(SUBDAMODULE ${ONLINEDETECTORNAME})
102#Get detector algorithms for this detector
103 foreach(dafile ${_dafiles})
104 string(REGEX MATCH "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}" match ${dafile})
105#Found a valid target name
106 if(match)
107 string(REGEX REPLACE "$ENV{ALICE_ROOT}/${DAMODULE}/${DAMODULE}${SUBDAMODULE}(.*)da\\.cxx" "\\1" DANAME ${dafile})
108#Check for default DA
109 if(DANAME)
110 set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}-${DANAME}")
111 else()
112 set(DATARGETNAME "daqDA-${ONLINEDETECTORNAME}")
113 endif(DANAME)
114 message("${DATARGETNAME}")
115
116 set(DATARGETDIR "${DAINSTALL}/${DAMODULE}/tgt_$ENV{ALICE_TARGET}")
117 file(MAKE_DIRECTORY ${DATARGETDIR})
118
119 set(DASRC "${DAMODULE}/${DAMODULE}${SUBDAMODULE}${DANAME}da.cxx")
120 set(DALIB "${DAMODULE}${SUBDAMODULE}${DANAME}DA")
121 set(DAEXE "${DAMODULE}${SUBDAMODULE}${DANAME}da")
122
123 # DAVERSION
124 execute_process(COMMAND svn info $ENV{ALICE_ROOT}/${DASRC} OUTPUT_VARIABLE _daversion OUTPUT_STRIP_TRAILING_WHITESPACE)
125 string(REGEX REPLACE ".*Last Changed Rev: ([^\n]+)\n.*" "\\1" DAVERSION ${_daversion})
126
127 # DAROOTRELEASE
128 execute_process(COMMAND root-config --version OUTPUT_VARIABLE _darootrelease OUTPUT_STRIP_TRAILING_WHITESPACE)
129 string(REGEX REPLACE "/" "." DAROOTRELEASE ${_darootrelease})
130
131 # DAALIROOTRELEASE
132 string(REGEX REPLACE ".*URL: .*/(.+)/${DASRC}.*$" "\\1" DAALIROOTRELEASE ${_daversion})
133
134 set(DAARCNAME "${DATARGETNAME}")
135 set(DAARC "${DAARCNAME}-${DAVERSION}")
136 set(DATAR "${DATARGETDIR}/${DAARC}.src.tar.gz")
137 set(DASPECFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.spec")
138 set(DAMAKEFILE "${DATARGETDIR}/${DAMODULE}${SUBDAMODULE}${DANAME}da.make")
139 set(DAQDALIB_PATH $ENV{DAQDALIB_PATH})
140 if(DAQDALIB_PATH)
141 set(DAQDADIR "${DAQDALIB_PATH}")
142 else()
143 set(DAQDADIR "$ENV{ALICE}/daqDAlib")
144 endif(DAQDALIB_PATH)
145
146 set(DAQDALIB "${DAQDADIR}/libdaqDA.a")
147
148# message(${DAVERSION})
149# message(${DAALIROOTRELEASE})
150
151 ##**set(EXTRADAMODULE ALIROOTALIBS
152# file(READ "$ENV{ALICE_ROOT}/${DAMODULE}/CMake_lib${DAMODULE}.txt" _modulesrc )
153# message("${_modulesrc}")
154# string(REGEX MATCHALL "[^ ]+\\.cxx" DAMODULE_SRC ${_modulesrc})
155
156# set(MODULEALIB ${DAMODULE}_SRC)
157#
158
159# message("MODULE SRCS - ${DAMODULE_SRC}")
160# string(REGEX MATCH "[^\n]*"
161# list(APPEND ALIROOTALIBS ${DAMODULE_SRC})
162
163# Super Duper Hack :D
164 file(GLOB _damodule "$ENV{ALICE_ROOT}/${DAMODULE}/lib${DAMODULE}*.pkg" )
165
166 message(${_damodule})
167 foreach(_submodule ${_damodule})
168 string(REGEX REPLACE ".*lib(${DAMODULE}.*)" "\\1" _submodule ${_submodule})
169 string(REGEX REPLACE "\\.pkg" "_a" _submodule ${_submodule})
170 list(APPEND ALIROOTALIBS "${_submodule}")
171 message("Adding ${_submodule}")
172 endforeach(_submodule)
173
174# file(WRITE "$ENV{ALICE_INSTALL}/tmp" "list(APPEND ALIROOTALIBS ${DAMODULE}-all)")
175# include("$ENV{ALICE_INSTALL}/tmp")
176
177 list(REMOVE_DUPLICATES ALIROOTALIBS)
178 if(EXTRADAMODULE)
179 ##**set
180 endif(EXTRADAMODULE)
181
182 file(READ "$ENV{ALICE_ROOT}/${DASRC}" _dasrc)
183 getinfo(DACONTACT "Contact" ${_dasrc})
184 getinfo(DALINKPAGE "Link" ${_dasrc})
185 getinfo(DAREFRUN "Reference Run" ${_dasrc})
186 getinfo(DARUNTYPE "Run Type" ${_dasrc})
187 getinfo(DATYPE "DA Type" ${_dasrc})
188 getinfo(DANUMBEROFEVENTS "Number of events needed" ${_dasrc})
189 getinfo(DAINPUTFILES "Input Files" ${_dasrc})
190 getinfo(DAOUTPUTFILES "Output Files" ${_dasrc})
191 getinfo(DATRIGGERTYPE "Trigger types used" ${_dasrc})
192
193 if(NOT _dasrc)
194 message(FATAL_ERROR "SRC FILE MISSING")
195 endif(NOT _dasrc)
196
197# message("${_dasrc}")
198# message("DACONTACT - ${DACONTACT}")
199# message("DALINKPAGE - ${DALINKPAGE}")
200# message("DAREFFUN - ${DAREFFUN}")
201# message("DARUNTYPE - ${DARUNTYPE}")
202# message("DATYPE - ${DATYPE}")
203# message("DANUMBEROFEVENTS - ${DANUMBEROFEVENTS}")
204# message("DAINPUTFILES - ${DAINPUTFILES}")
205# message("DAOUTPUTFILES - ${DAOUTPUTFILES}")
206# message("DATRIGGERTYPE - ${DATRIGGERTYPE}")
207
208#----------- Targets ----------------------
209
210 set(CMAKE_CXX_FLAGS "${CXXFLAGS}")
211 set(CMAKE_C_FLAGS "${CFLAGS}")
212 set(CMAKE_Fortran_FLAGS "${FFLAGS}")
213 set(CMAKE_SHARED_LINKER_FLAGS ${SOFLAGS})
214 set(CMAKE_MODULE_LINKER_FLAGS ${LDFLAGS})
215
216 include_directories(${MODULES} ${DAQDADIR} )
217 include_directories(SYSTEM ${ROOTINCDIR})
218 set(ZIP)
219 foreach(_lib ${ALIROOTALIBS})
220 string(REGEX REPLACE "-all" "_a" _lib ${_lib})
221 list(APPEND ZIP && ar x "../lib${_lib}.a")
222 endforeach(_lib)
223 list (APPEND ZIP && ar r "../${DALIB}.a" "*.o")
224
225 add_custom_target("${DALIB}_x" rm -rf junk && mkdir -p junk
226 COMMAND cd junk ${ZIP}
227 COMMAND cd ../ && rm -rf junk
228 DEPENDS ${ALIROOTALIBS}
229 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
230
231 add_custom_target(${DATARGETNAME} DEPENDS ${DAEXE} )
232 add_executable(${DAEXE} ${DASRC} )
233 set_property(TARGET ${DAEXE} PROPERTY EXCLUDE_FROM_ALL TRUE)
234 add_dependencies(${DAEXE} ${DALIB}_x)
235 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})
236 add_custom_command(TARGET ${DAEXE}
237 PRE_LINK
238 COMMAND ${CMAKE_AR} r ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${EXTRAROOTLIB} ${_extraroot})
239# message("${DALIB} --> ${ALIROOTALIBS}")
240 endif(match)
241 endforeach(dafile)
242endforeach(detector)