alimdc-rpm target (Anshul)
[u/mrichter/AliRoot.git] / CMakeLists.txt
1 # -*- mode: cmake -*-
2
3 # Top level CMakeList.txt file for the AliRoot Build System
4 #
5 # Author: Johny Jose (johny.jose@cern.ch)
6 #         Port of previous Makefile build to cmake
7
8
9 cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
10
11 #--------------------------------------------------------------------------------#
12 # Set Basic CMake Configuration                                                  #
13 #--------------------------------------------------------------------------------#
14
15 project(AliRoot CXX C Fortran)
16
17 # Environment variables
18 set(ALICE_ROOT $ENV{ALICE_ROOT})
19 set(ALICE $ENV{ALICE})
20 set(ALICE_INSTALL $ENV{ALICE_INSTALL})
21 if(${ALICE_INSTALL} MATCHES ${CMAKE_BINARY_DIR})
22   message(FATAL_ERROR "Install dir should be different from build dir")
23 endif(${ALICE_INSTALL} MATCHES ${CMAKE_BINARY_DIR})
24 # Environment for SHUTTLE
25 set(DIMDIR $ENV{DIMDIR})
26 set(ODIR $ENV{ODIR})
27
28 if(NOT ALICE)
29   message(WARNING "Environment variable ALICE is not set")
30 endif(NOT ALICE)
31
32 if(NOT ALICE_ROOT)
33   message(FATAL_ERROR "Please set ALICE_ROOT to the AliRoot source directory")
34 endif(NOT ALICE_ROOT)
35
36 # Set AliRoot Installation directory 
37 if(NOT ALICE_INSTALL)
38   message(STATUS "AliRoot files will be installed in ${ALICE_ROOT}. You can specify a different location by setting ALICE_INSTALL environment variable")
39   set(ALICE_INSTALL ${ALICE_ROOT})
40 else()
41   message(STATUS "AliRoot files will be installed in ${ALICE_INSTALL}")
42 endif(NOT ALICE_INSTALL)
43 set(CMAKE_INSTALL_PREFIX ${ALICE_INSTALL})
44
45 get_filename_component(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}" REALPATH)
46 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
47 set(CPACK_COMPONENTS_ALL MDC)
48
49 include(ALICE_CMake)
50
51 #--------------------------------------------------------------------------------#
52 # Find Packages                                                                  #
53 #--------------------------------------------------------------------------------#
54
55 # Subversion
56 # ------------------------------
57
58 find_package(Subversion REQUIRED)
59
60 # ROOT
61 # ------------------------------
62
63 find_package(ROOT REQUIRED)
64
65 # IRST Rule Checker 
66 # ------------------------------
67
68 find_package(RuleChecker)
69
70 # DATE
71 # ------------------------------ 
72
73 find_package(DATE)
74
75 # GEANT3
76 # ------------------------------
77
78 find_package(GEANT3)
79
80 # AMORE
81 # ------------------------------
82
83 find_package(AMORE)
84
85 # AliRoot CPack configuration                                                    
86 #-------------------------------
87
88 find_package(CPack)
89
90
91 #--------------------------------------------------------------------------------#
92 # Environment/Compiler Configuration                                             #
93 #--------------------------------------------------------------------------------#
94
95 ALICE_CheckOutOfSourceBuild()
96 ALICE_RootConfig(CMAKE_CXX_COMPILER --cxx)
97 ALICE_RootConfig(CMAKE_C_COMPILER --cc)
98 ALICE_RootConfig(CMAKE_Fortran_COMPILER --f77)
99 ALICE_ConfigurePlatform()
100 ALICE_ConfigureCompiler()
101
102
103 #--------------------------------------------------------------------------------#
104 # AliRoot Path Settings                                                          #
105 #--------------------------------------------------------------------------------#
106
107 ALICE_DevFlagsOutput()
108 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/tgt_${ALICE_TARGET}")
109 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
110 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
111 set(CMAKE_INCLUDE_EXPORT_DIRECTORY "${PROJECT_BINARY_DIR}/include")
112 file(MAKE_DIRECTORY ${CMAKE_INCLUDE_EXPORT_DIRECTORY})
113 set(EXPORTDIRS "${ALICE_INSTALL}/include")
114 set(BINLIBDIRS "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
115
116
117 #--------------------------------------------------------------------------------#
118 # AliRoot Modules                                                                #
119 #--------------------------------------------------------------------------------#
120
121 # Exclude Module from all target
122 # ------------------------------
123
124 #set(EXCLUDEMODULES THydjet SHUTTLE)
125
126
127 # Standard Modules
128 # ------------------------------
129 set(ALIROOTMODULES STEER PHOS TRD TPC ZDC MUON PMD FMD TOF ITS ACORDE HMPID T0 BCM STRUCT VZERO THijing THbtp EMCAL THerwig TEPEMGEN FASTSIM TPHIC RAW MONITOR ANALYSIS JETAN HLT STAT TTherminator CORRFW DPMJET TDPMjet PWG0 PWG1 PWG2 PWG3 PWG4 TRIGGER PYTHIA8 TAmpt OADB )
130
131 if(THydjet)
132   list(APPEND ALIROOTMODULES THydjet)
133 endif(THydjet)
134
135 if(SHUTTLE)
136   list(APPEND ALIROOTMODULES SHUTTLE)
137 endif(SHUTTLE)
138
139 # Additional Modules
140 # ------------------------------
141 list(APPEND ALIROOTMODULES TUHKMgen EPOS)
142
143 # EVE
144 # ------------------------------
145 ALICE_RootConfig(EVE --has-opengl)
146 if(NOT EVE STREQUAL "no")
147   list(APPEND ALIROOTMODULES EVE)
148 endif(NOT EVE STREQUAL "no")
149
150 # CERN Modules
151 # ------------------------------
152 set(CERNMODULES LHAPDF HIJING MICROCERN HERWIG)
153
154 # Check for Pythia 6
155 if(EXISTS ${ROOTINCDIR}/TPythia6.h)
156   set(PYTHIA6 TRUE)
157   list(APPEND CERNMODULES PYTHIA6 EVGEN)
158 elseif(NOT NOPYTHIA)
159   message(FATAL_ERROR "ROOT must have Pythia6 enabled !")
160 endif(EXISTS ${ROOTINCDIR}/TPythia6.h)
161
162 # Set Final list of modules 
163 set(MODULES ${ALIROOTMODULES} ${CERNMODULES} ALIROOT)
164
165 # Set Module directories
166 set(MODDIRS ${MODULES})
167
168 # Libraries for Linking
169 # ------------------------------
170 set(ALILIBS MUON TPC PMD TRD FMD TOF ITS PHOS ACORDE HMPID VZERO ZDC STRUCT T0 EVGEN STEER TRIGGER)
171 set(LIBS ${ROOTCLIBS} ${ROOTPLIBS} ${SYSLIBS})
172
173 # Configure ARVerion.h
174 # ------------------------------
175 if(Subversion_FOUND)
176   if(EXISTS ${PROJECT_SOURCE_DIR}/.svn/ )
177   Subversion_WC_INFO(${PROJECT_SOURCE_DIR} PROJECT)
178   set(ALIROOT_SVN_REVISION ${PROJECT_WC_REVISION})
179   set(ALIROOT_SVN_BRANCH ${PROJECT_WC_URL})
180   string(REGEX MATCH "[^/]+$" ALIROOT_SVN_BRANCH ${ALIROOT_SVN_BRANCH})
181
182   elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git/ )
183     execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND git svn info OUTPUT_VARIABLE OUTPUTVAR)
184     string(REPLACE "\n" ";" OUTPUTVAR ${OUTPUTVAR})
185     foreach(f ${OUTPUTVAR})
186       if(${f} MATCHES URL)
187         string(REGEX MATCH "[^/]+$" ALIROOT_SVN_BRANCH ${f})
188       elseif(${f} MATCHES Revision)
189         string(REGEX MATCH "[^: ]+$" ALIROOT_SVN_REVISION ${f})
190       endif(${f} MATCHES URL)   
191     endforeach()
192   endif(EXISTS ${PROJECT_SOURCE_DIR}/.svn/ )
193
194   message(STATUS "Aliroot Revision - ${ALIROOT_SVN_REVISION} Branch - ${ALIROOT_SVN_BRANCH}")
195   if(EXISTS ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
196     file(REMOVE ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
197   endif(EXISTS ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
198   configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h @ONLY)
199 endif(Subversion_FOUND)
200
201 #--------------------------------------------------------------------------------#
202 # Build Modules                                                                  #
203 #--------------------------------------------------------------------------------#
204
205 # Module Variables
206 # ------------------------------
207 set(ALLLIBS)
208 set(ALLEXECS)
209 set(INCLUDEFILES)
210 set(BINLIBS)
211 set(EXPORTFILES)
212
213 # Top Level Build Targets
214 # ------------------------------
215
216 add_custom_target(alilibs-static)
217 add_custom_target(include-headers ALL)
218 add_custom_target(DA-all)
219 add_custom_target(check-all) 
220 add_custom_target(check-hxml)
221 add_custom_target(smell-all) 
222 add_custom_target(htmldoc) 
223 add_custom_target(par-all)
224 add_custom_target(test-par-all)
225
226 #NY file(GLOB CFILES_LIST ${CMAKE_SOURCE_DIR}/macros/*.C)
227
228 add_custom_command(TARGET htmldoc
229                    PRE_BUILD
230                    COMMAND mkdir -p html
231                    COMMAND rm -rf html/roothtml
232                    COMMAND rm -f html/picts
233                    COMMAND cd html &&
234                             aliroot -q -b \"mkhtml.C(0,1)\"
235                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
236
237
238 # Add Modules   
239 # ------------------------------
240 foreach(MODULE ${MODDIRS})
241   set(${MODULE}ALIBS)
242   configure_file(${PROJECT_SOURCE_DIR}/cmake/Module.tmp ${PROJECT_SOURCE_DIR}/${MODULE}/CMakeLists.txt @ONLY)
243   add_custom_target(${MODULE}-all ALL)
244   add_custom_target(${MODULE}-par-all)
245   add_custom_target(test-${MODULE}-par-all)
246   add_custom_target(${MODULE}-all-static)
247   add_dependencies(alilibs-static "${MODULE}-static")
248   add_subdirectory(${MODULE})
249   
250 #NY  set(dir "${CMAKE_SOURCE_DIR}/${MODULE}")
251 #NY  if (EXISTS "${dir}")
252 #NY      file(GLOB CFILES_MOD ${dir}/*.C)
253 #NY      list(LENGTH CFILES_MOD len)
254 #NY      if (${len} GREATER 0)
255 #NY        list(APPEND CFILES_LIST "${CFILES_MOD}")
256 #NY      endif (${len} GREATER 0)
257 #NY  endif(EXISTS "${dir}")
258 endforeach(MODULE)
259
260 #NY foreach(cfile ${CFILES_LIST})
261 #NY     add_custom_command(TARGET htmldoc
262 #NY                    PRE_BUILD
263 #NY                    COMMAND cd html && 
264 #NY                            aliroot -b -q \"mkhtml.C(\"${cfile}\")\" > /dev/null
265 #NY                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
266 #NY endforeach(cfile)
267
268 if(DATE_FOUND AND AMORE_FOUND)
269   include (CMakeDA)
270 endif(DATE_FOUND AND AMORE_FOUND)
271
272 if(RULECHECKER_FOUND)
273     add_custom_target(factfile DEPENDS ${FACTFILE})
274     add_custom_command( OUTPUT ${FACTFILE}
275                         COMMAND ${CMAKE_COMMAND} -E echo "Re-generating factfile"
276                         COMMAND ${JAVA_RUNTIME}  -Xmx1024M -jar ${FACTEXTRACTOR_JAR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}                    
277                         DEPENDS check-hxml ${CMAKE_BINARY_DIR}/check-hxml-touchfile ${_factfile_deps} 
278                         WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
279 endif(RULECHECKER_FOUND)
280
281 #--------------------------------------------------------------------------------#
282 # Additional Targets                                                             #
283 #--------------------------------------------------------------------------------#
284
285 # AliMdc RPM
286 # ------------------------------
287
288 execute_process(
289 COMMAND root-config --libdir 
290 OUTPUT_VARIABLE ROOTALIBDIR)
291 string(REPLACE "\n" "" ROOTALIBDIR ${ROOTALIBDIR}) 
292
293 execute_process(
294 COMMAND root-config --arch 
295 OUTPUT_VARIABLE ARCHITECTURE)
296
297
298 set(AEXT a)
299 set(LIBPATH ${CMAKE_BINARY_DIR}/lib/tgt_${ALICE_TARGET})
300 set(BINPATH ${CMAKE_BINARY_DIR}/bin/tgt_${ALICE_TARGET})
301 set(EXPORTDIR ${ALICE_ROOT}/include)
302 set(BINLIBDIRS -L${ALICE_ROOT}/${LIBPATH})
303 set(RAWDIRO ${CMAKE_BINARY_DIR}/RAW)
304 set(ALIMDCSPECFILE ${RAWDIRO}/alimdc.spec)
305 set(RAWDatabaseALIB ${LIBPATH}/libRAWDatabase.${AEXT})
306 set(ESDALIB ${LIBPATH}/libESD.${AEXT})
307 set(STEERBaseALIB ${LIBPATH}/libSTEERBase.${AEXT})
308 set(MDCALIB ${LIBPATH}/libMDC.${AEXT})
309 set(MODDIRO RAW/tgt_${ALICE_TARGET})
310
311
312 if( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
313 set(ALIMDCARCHDIR x86_64)
314 elseif( ${ARCHITECTURE} MATCHES "linux" )
315 set(ALIMDCARCHDIR i386)
316 elseif( ${ARCHITECTURE} MATCHES "linuxia64gcc" )
317 set(ALIMDCARCHDIR ia64)
318 elseif(NOT DEFINED ${ARCHITECTURE})
319 message( "Unknown architecture" )
320 exit(1)
321 else( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
322 message( "Unknown architecture" )
323 exit(1)
324 endif( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
325
326
327 add_custom_target( alimdc-rpm
328 DEPENDS alimdc-static alimdc-specfile
329 )
330
331 add_custom_command(
332 TARGET alimdc-rpm
333 POST_BUILD 
334 COMMAND rm -rf ${ALICE_ROOT}/alimdc-root
335 COMMAND mkdir -p ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
336 COMMAND mkdir -p ${ALICE_ROOT}/alimdc-root/opt/alimdc/include
337 COMMAND cp ${ALICE_ROOT}/RAW/mdc.h ${ALICE_ROOT}/alimdc-root/opt/alimdc/include
338 COMMAND cp ${LIBPATH}/libAliMDC.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
339 COMMAND cp ${ROOTALIBDIR}/libRoot.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
340 COMMAND cp ${ROOTALIBDIR}/libfreetype.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
341 COMMAND cp ${ROOTALIBDIR}/libpcre.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
342 COMMAND rm -rf ${ALICE_ROOT}/RPMS
343 COMMAND mkdir -p ${ALICE_ROOT}/RPMS/${ALIMDCARCHDIR}/
344 COMMAND rpmbuild --verbose --define "_topdir ${ALICE_ROOT}" --define "_tmppath ${ALICE_ROOT}" -bb ${ALIMDCSPECFILE} 
345 COMMAND cp -p ${ALICE_ROOT}/RPMS/${ALIMDCARCHDIR}/alimdc-*.rpm .
346 COMMAND rm -rf ${ALICE_ROOT}/alimdc-root
347 COMMAND rm -rf ${ALICE_ROOT}/RPMS
348 COMMAND echo "***** alimdc RPM created and put in ${CMAKE_BINARY_DIR} folder *****"
349 )
350
351 add_custom_command(
352 TARGET ${RAWDIRO}
353 COMMAND mkdir-p ${RAWDIRO}
354 )
355
356
357 add_custom_target( alimdc-specfile
358 DEPENDS ${RAWDIRO}
359 )
360
361 add_custom_command( 
362 TARGET alimdc-specfile
363 POST_BUILD
364 COMMAND rm -rf ${ALIMDCSPECFILE}
365 COMMAND @echo "***** Making alimdc RPM spec-file ${ALIMDCSPECFILE} *****"
366 COMMAND @echo '\# RPM specfile for alimdc static libs' >> ${ALIMDCSPECFILE} 
367 COMMAND @echo '\# Package contains both ROOT and AliRoot' >> ${ALIMDCSPECFILE}
368 COMMAND @echo '\# static libs needed by mStreamRecorder' >> ${ALIMDCSPECFILE}
369 COMMAND @echo '\# in order to ROOT-ify the incoming raw' >> ${ALIMDCSPECFILE}
370 COMMAND @echo '\# data' >> ${ALIMDCSPECFILE}
371 COMMAND @echo '\# Example how-to build alimdc RPM:' >> ${ALIMDCSPECFILE}
372 COMMAND @echo '\# cd ${ALICE_ROOT}' >> ${ALIMDCSPECFILE}
373 COMMAND @echo '\# make alimdc-rpm' >> ${ALIMDCSPECFILE}
374 COMMAND @echo "" >> ${ALIMDCSPECFILE}
375 COMMAND @echo "Summary: AliMDC static libraries" >> ${ALIMDCSPECFILE}
376 COMMAND @echo "Name: alimdc" >> ${ALIMDCSPECFILE}
377 COMMAND @echo "Version:  ${ALIROOT_SVN_BRANCH}" >> ${ALIMDCSPECFILE}
378 COMMAND @echo "Release: ${ALIROOT_SVN_REVISION}" >> ${ALIMDCSPECFILE}
379 COMMAND @echo '\# Copyright: CERN Alice Off-line' >> ${ALIMDCSPECFILE}
380 COMMAND @echo "License: CERN Alice Off-line" >> ${ALIMDCSPECFILE}
381 COMMAND @echo "Vendor: ALICE Core Off-line Group" >> ${ALIMDCSPECFILE}
382 COMMAND @echo "URL: http://aliceinfo.cern.ch" >> ${ALIMDCSPECFILE}
383 COMMAND @echo "Group: Applications/Alice" >> ${ALIMDCSPECFILE}
384 COMMAND @echo "Prefix: /opt/%{name}" >> ${ALIMDCSPECFILE}
385 COMMAND @echo "BuildRoot: %{_tmppath}/%{name}-root" >> ${ALIMDCSPECFILE}
386 COMMAND @echo "" >> ${ALIMDCSPECFILE}
387 COMMAND @echo '\# automatic dependencies' >> ${ALIMDCSPECFILE}
388 COMMAND @echo "AutoReqProv: yes" >> ${ALIMDCSPECFILE}
389 COMMAND @echo "" >> ${ALIMDCSPECFILE}
390 COMMAND @echo '\# list here required RPM packages for runtime' >> ${ALIMDCSPECFILE}
391 COMMAND @echo "Requires: glibc" >> ${ALIMDCSPECFILE}
392 COMMAND @echo "" >> ${ALIMDCSPECFILE}
393 COMMAND @echo "Provides: alimdc" >> ${ALIMDCSPECFILE}
394 COMMAND @echo "" >> ${ALIMDCSPECFILE}
395 COMMAND @echo '\# description of the package' >> ${ALIMDCSPECFILE}
396 COMMAND @echo "%description" >> ${ALIMDCSPECFILE}
397 COMMAND @echo "Package contains both ROOT and AliRoot" >> ${ALIMDCSPECFILE}
398 COMMAND @echo "static libs needed by mStreamRecorder" >> ${ALIMDCSPECFILE}
399 COMMAND @echo "in order to ROOT-ify the incoming raw" >> ${ALIMDCSPECFILE}
400 COMMAND @echo "data. The package version correspond to" >> ${ALIMDCSPECFILE}
401 COMMAND @echo "the AliRoot one." >> ${ALIMDCSPECFILE}
402 COMMAND @echo "" >> ${ALIMDCSPECFILE}
403 COMMAND @echo '\# list of files to be installed' >> ${ALIMDCSPECFILE}
404 COMMAND @echo "%files" >> ${ALIMDCSPECFILE}
405 COMMAND @echo '%defattr (-,root,root)' >> ${ALIMDCSPECFILE}
406 COMMAND @echo "%{prefix}/lib/libAliMDC.a" >> ${ALIMDCSPECFILE}
407 COMMAND @echo "%{prefix}/lib/libRoot.a" >> ${ALIMDCSPECFILE}
408 COMMAND @echo "%{prefix}/lib/libpcre.a" >> ${ALIMDCSPECFILE}
409 COMMAND @echo "%{prefix}/lib/libfreetype.a" >> ${ALIMDCSPECFILE}
410 COMMAND @echo "%{prefix}/include/mdc.h" >> ${ALIMDCSPECFILE}
411 )
412
413
414 add_custom_target( alimdc-static
415 DEPENDS ${LIBPATH} ${BINPATH} RAW-all-static STEER-all-static )
416
417 add_custom_command( 
418 TARGET alimdc-static
419 POST_BUILD
420 COMMAND ar r ${LIBPATH}/alimdccxxo.a ${CMAKE_BINARY_DIR}/RAW/CMakeFiles/alimdc.dir/alimdc_main.cxx.o
421 COMMAND rm -rf ${LIBPATH}/libAliMDC.a
422 COMMAND ar x ${RAWDatabaseALIB}
423 COMMAND ar x ${MDCALIB}
424 COMMAND ar x ${ESDALIB}
425 COMMAND ar x ${STEERBaseALIB}
426 COMMAND ar r ${LIBPATH}/libAliMDC.a *.o
427 COMMAND ar t ${RAWDatabaseALIB} | xargs rm 
428 COMMAND ar t ${MDCALIB} | xargs rm 
429 COMMAND ar t ${ESDALIB} | xargs rm 
430 COMMAND ar t ${STEERBaseALIB} | xargs rm 
431 COMMAND ${CMAKE_CXX_COMPILER} ${LDFLAGS} -o ${BINPATH}/alimdca ${LIBPATH}/alimdccxxo.a ${LIBPATH}/libAliMDC.a ${ROOTALIBDIR}/libRoot.a ${ROOTALIBDIR}/libfreetype.a ${ROOTALIBDIR}/libpcre.a -pthread -ldl -lz
432 COMMAND @echo "Target alimdc-static made"
433 )
434
435 add_custom_command(
436 TARGET ${LIBPATH}
437 COMMAND mkdir -p ${LIBPATH}
438 )
439
440
441 #include (MakefileDA) 
442 include (InstallRequiredSystemLibraries)
443 include (CPack)
444
445 # Install data
446 # ------------------------------
447 install ( DIRECTORY data 
448           DESTINATION . )
449
450
451 #
452 # EOF
453 #
454