Setting run number in CDB manager added. GRP now read from default cdb storage instea...
[u/mrichter/AliRoot.git] / CMakeLists.txt
1 # -*- mode: cmake -*-/usr/share/applications/thunderbird.desktop 
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.8 FATAL_ERROR)
10
11 #--------------------------------------------------------------------------------#
12 # Set Basic CMake Configuration                                                  #
13 #--------------------------------------------------------------------------------#
14
15 project(AliRoot CXX C Fortran)
16
17 # Environment variables
18 set(ALICE $ENV{ALICE})
19 if(NOT ALICE)
20   message(WARNING "Environment variable ALICE is not set")
21 endif(NOT ALICE)
22
23 set(ALICE_ROOT $ENV{ALICE_ROOT})
24 if(NOT ALICE_ROOT)
25   message(FATAL_ERROR "Please set ALICE_ROOT to the AliRoot source directory")
26 endif(NOT ALICE_ROOT)
27
28 set(ALICE_INSTALL $ENV{ALICE_INSTALL})
29 # Set AliRoot Installation directory 
30 # If CMAKE_INSTALL_PREFIX was not set, then we set it to ALICE_INSTALL. 
31 # If ALICE_INSTALL was not defined, then it will default to the source directory
32 if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
33     if(ALICE_INSTALL)
34         message(STATUS "AliRoot files will be installed in ${ALICE_INSTALL}")
35     else()
36         message(STATUS "AliRoot files will be installed in ${ALICE_ROOT}. You
37         can specify a different location by passing -DCMAKE_INSTALL_PREFIX or
38         by setting ALICE_INSTALL environment variable")
39         set(ALICE_INSTALL ${ALICE_ROOT})
40         if(${ALICE_INSTALL} STREQUAL ${CMAKE_BINARY_DIR})
41             message(FATAL_ERROR "The install directory must differ from the
42             build directory")
43         endif()
44     endif()
45     set(CMAKE_INSTALL_PREFIX ${ALICE_INSTALL} CACHE STRING "Install dir" FORCE)
46 endif()
47
48
49 # Environment for SHUTTLE
50 set(DIMDIR $ENV{DIMDIR})
51 set(ODIR $ENV{ODIR})
52
53 get_filename_component(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}" REALPATH)
54 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
55 set(CPACK_COMPONENTS_ALL MDC)
56
57 include(ALICE_CMake)
58
59 #--------------------------------------------------------------------------------#
60 # Find Packages                                                                  #
61 #--------------------------------------------------------------------------------#
62
63 # Subversion
64 # ------------------------------
65
66 find_package(Subversion REQUIRED)
67
68 # ROOT
69 # ------------------------------
70
71 find_package(ROOT REQUIRED)
72
73 # IRST Rule Checker 
74 # ------------------------------
75
76 find_package(RuleChecker)
77
78 # DATE
79 # ------------------------------ 
80
81 find_package(DATE)
82
83 # GEANT3
84 # ------------------------------
85
86 find_package(GEANT3)
87
88 # AMORE
89 # ------------------------------
90
91 find_package(AMORE)
92
93 # AliRoot CPack configuration                                                    
94 #-------------------------------
95
96 find_package(CPack)
97
98 # ZeroMQ
99 # ------------------------------
100 find_package(ZeroMQ)
101
102 # fastjet
103 # ------------------------------
104 find_package(FASTJET)
105
106 #--------------------------------------------------------------------------------#
107 # Environment/Compiler Configuration                                             #
108 #--------------------------------------------------------------------------------#
109
110 ALICE_CheckOutOfSourceBuild()
111 ALICE_RootConfig(CMAKE_CXX_COMPILER --cxx)
112 ALICE_RootConfig(CMAKE_C_COMPILER --cc)
113 ALICE_RootConfig(CMAKE_Fortran_COMPILER --f77)
114 ALICE_ConfigurePlatform()
115 ALICE_ConfigureCompiler()
116
117
118 #--------------------------------------------------------------------------------#
119 # AliRoot Path Settings                                                          #
120 #--------------------------------------------------------------------------------#
121
122 ALICE_DevFlagsOutput()
123 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/tgt_${ALICE_TARGET}")
124 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
125 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
126 set(CMAKE_INCLUDE_EXPORT_DIRECTORY "${PROJECT_BINARY_DIR}/include")
127 file(MAKE_DIRECTORY ${CMAKE_INCLUDE_EXPORT_DIRECTORY})
128 set(EXPORTDIRS "${ALICE_INSTALL}/include")
129 set(BINLIBDIRS "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
130
131
132 #--------------------------------------------------------------------------------#
133 # AliRoot Modules                                                                #
134 #--------------------------------------------------------------------------------#
135
136 # Exclude Module from all target
137 # ------------------------------
138
139 #set(EXCLUDEMODULES THydjet SHUTTLE)
140
141
142 # Standard Modules
143 # ------------------------------
144 set(ALIROOTMODULES STEER PHOS TRD TPC ZDC MUON PMD FMD TOF ITS AD ACORDE HMPID T0 BCM STRUCT VZERO THijing THbtp EMCAL THerwig TEPEMGEN FASTSIM TPHIC RAW MONITOR ANALYSIS JETAN HLT STAT TTherminator CORRFW DPMJET TDPMjet STARLIGHT PWGPP PWG PWGCF PWGGA PWGHF PWGDQ PWGJE PWGLF PWGUD TRIGGER PYTHIA8 TAmpt OADB MFT TEvtGen FIT)
145
146 if(THydjet)
147   list(APPEND ALIROOTMODULES THydjet)
148 endif(THydjet)
149
150 if(SHUTTLE)
151   list(APPEND ALIROOTMODULES SHUTTLE)
152 endif(SHUTTLE)
153
154 # Additional Modules
155 # ------------------------------
156 list(APPEND ALIROOTMODULES TUHKMgen EPOS)
157
158 # EVE
159 # ------------------------------
160 ALICE_RootConfig(EVE --has-opengl)
161 if(NOT EVE STREQUAL "no")
162   list(APPEND ALIROOTMODULES EVE)
163 endif(NOT EVE STREQUAL "no")
164
165 # CERN Modules
166 # ------------------------------
167 set(CERNMODULES LHAPDF HIJING MICROCERN HERWIG)
168
169 # Check for Pythia 6
170 if(EXISTS ${ROOTINCDIR}/TPythia6.h)
171   set(PYTHIA6 TRUE)
172   list(APPEND CERNMODULES PYTHIA6 EVGEN)
173 elseif(NOT NOPYTHIA)
174   message(FATAL_ERROR "ROOT must have Pythia6 enabled !")
175 endif(EXISTS ${ROOTINCDIR}/TPythia6.h)
176
177 # Set Final list of modules 
178 set(MODULES ${ALIROOTMODULES} ${CERNMODULES} ALIROOT)
179
180 # Set Module directories
181 set(MODDIRS ${MODULES})
182
183 # Libraries for Linking
184 # ------------------------------
185 set(ALILIBS MUON TPC PMD TRD FMD TOF ITS PHOS AD ACORDE HMPID VZERO ZDC STRUCT T0 EVGEN STEER TRIGGER MFT)
186 set(LIBS ${ROOTCLIBS} ${ROOTPLIBS} ${SYSLIBS})
187
188 # Configure ARVerion.h
189 # ------------------------------
190 # If the sources were taken from Git
191 # Sets 3 git variables
192 #  - GIT_REFSPEC - complete name of the current reference
193 #  - ALIROOT_BRANCH - name of the branch or tag extracted from the current reference
194 #  - GIT_SHA1 - current hash in the long format
195 #  - GIT_SHORT_SHA1 - current hash in the short format
196 if(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
197  include(GetGitRevisionDescription)
198  
199  find_package(Git)
200  
201  if(GIT_FOUND)
202   get_git_head_revision(GIT_REFSPEC GIT_SHA1)
203
204   # GIT_REFSPEC is empty for detached mode = tags in detached mode or checkout to specific hash
205  
206
207   # returns the closest reference to the current hash
208   # name of the current tag or heads/branch in the case of branches
209   git_describe(ALIROOT_GIT_TAG "--all" "--abbrev=0")
210
211   STRING(REGEX REPLACE "^(.+/)(.+)/(.*)$" "\\2" BRANCH_TYPE "${GIT_REFSPEC}" )
212
213   # the revision is not set in the case of a branch, it means we are doing development
214   # and the revision will trigger a reconfiguration
215   if(BRANCH_TYPE STREQUAL "heads")
216    set(ALIROOT_REVISION "ThisIsaBranchNoRevisionProvided")
217    STRING(REGEX REPLACE "^(.+/)(.+/)(.*)$" "\\3" SHORT_BRANCH "${GIT_REFSPEC}" )
218   else()
219    set(SHORT_BRANCH ${ALIROOT_GIT_TAG})
220    set(ALIROOT_REVISION ${GIT_SHA1})
221   endif()
222
223   set(ALIROOT_BRANCH ${SHORT_BRANCH})
224   
225   # generate the short version of the revision hash
226   execute_process(COMMAND git rev-parse --short ${GIT_SHA1} 
227                           WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 
228                           OUTPUT_STRIP_TRAILING_WHITESPACE 
229                           RESULT_VARIABLE res
230                           OUTPUT_VARIABLE GIT_SHORT_SHA1)
231
232   # if the rev-parse fails we set the short sha to the long initial one
233   if(NOT res EQUAL 0)
234     set(GIT_SHORT_SHA1 ${GIT_SHA1})
235   endif()
236   
237   message(STATUS "Aliroot branch/tag: \"${ALIROOT_BRANCH}\" - Revision:  \"${GIT_SHORT_SHA1}\" ")
238
239  else()
240   message("Git not installed. I can't tell you which revision you are using!")
241   endif(GIT_FOUND)
242 else()
243  message("AliRoot sources not downloaded from a Version Control System. I can't tell which revision you are using!")
244 endif(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
245
246 configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/FromTemplate/ARVersion.h @ONLY)
247
248 string (REPLACE "-" "." ALIROOT_BRANCH_SPEC "${ALIROOT_BRANCH}")
249
250 #--------------------------------------------------------------------------------#
251 # Build Modules                                                                  #
252 #--------------------------------------------------------------------------------#
253
254 # Module Variables
255 # ------------------------------
256 set(ALLLIBS)
257 set(ALLEXECS)
258 set(INCLUDEFILES)
259 set(BINLIBS)
260 set(EXPORTFILES)
261
262 # Top Level Build Targets
263 # ------------------------------
264
265 add_custom_target(alilibs-static)
266 add_custom_target(include-headers ALL)
267 add_custom_target(DA-all)
268 add_custom_target(check-all) 
269 add_custom_target(check-hxml)
270 add_custom_target(smell-all) 
271 add_custom_target(htmldoc) 
272 add_custom_target(par-all)
273 add_custom_target(test-par-all)
274
275 #NY file(GLOB CFILES_LIST ${CMAKE_SOURCE_DIR}/macros/*.C)
276
277 add_custom_command(TARGET htmldoc
278                    PRE_BUILD
279                    COMMAND mkdir -p html
280                    COMMAND rm -rf html/roothtml
281                    COMMAND rm -f html/picts
282                    COMMAND cd html && aliroot -q -b mkhtml.C\\\(0,1\\\)
283                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
284
285 # Include Vc, which provides the static libVc and the relevant CMake macros
286 include(Vc/Vc.cmake)
287 add_subdirectory(Vc)
288
289 # Add Modules   
290 # ------------------------------
291 foreach(MODULE ${MODDIRS})
292   set(${MODULE}ALIBS)
293 #RS  configure_file(${PROJECT_SOURCE_DIR}/cmake/Module.tmp ${PROJECT_SOURCE_DIR}/${MODULE}/CMakeLists.txt @ONLY)
294   add_custom_target(${MODULE}-all ALL)
295   add_custom_target(${MODULE}-par-all)
296   add_custom_target(test-${MODULE}-par-all)
297   add_custom_target(${MODULE}-all-static)
298   add_dependencies(alilibs-static "${MODULE}-static")
299   add_subdirectory(${MODULE})
300   
301 #NY  set(dir "${CMAKE_SOURCE_DIR}/${MODULE}")
302 #NY  if (EXISTS "${dir}")
303 #NY      file(GLOB CFILES_MOD ${dir}/*.C)
304 #NY      list(LENGTH CFILES_MOD len)
305 #NY      if (${len} GREATER 0)
306 #NY        list(APPEND CFILES_LIST "${CFILES_MOD}")
307 #NY      endif (${len} GREATER 0)
308 #NY  endif(EXISTS "${dir}")
309 endforeach(MODULE)
310
311 #NY foreach(cfile ${CFILES_LIST})
312 #NY     add_custom_command(TARGET htmldoc
313 #NY                    PRE_BUILD
314 #NY                    COMMAND cd html && 
315 #NY                            aliroot -b -q \"mkhtml.C(\"${cfile}\")\" > /dev/null
316 #NY                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
317 #NY endforeach(cfile)
318
319 if(DATE_FOUND)
320   include (CMakeDA)
321 endif(DATE_FOUND)
322
323 if(RULECHECKER_FOUND)
324     add_custom_target(factfile DEPENDS ${FACTFILE})
325     add_custom_command( OUTPUT ${FACTFILE}
326                         COMMAND ${CMAKE_COMMAND} -E echo "Re-generating factfile"
327                         COMMAND ${JAVA_RUNTIME}  -Xmx1024M -jar ${FACTEXTRACTOR_JAR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}                    
328                         DEPENDS check-hxml ${CMAKE_BINARY_DIR}/check-hxml-touchfile ${_factfile_deps} 
329                         WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
330 endif(RULECHECKER_FOUND)
331
332 #--------------------------------------------------------------------------------#
333 # Additional Targets                                                             #
334 #--------------------------------------------------------------------------------#
335
336 # AliMdc RPM
337 # ------------------------------
338
339 execute_process(
340 COMMAND root-config --libdir 
341 OUTPUT_VARIABLE ROOTALIBDIR)
342 string(REPLACE "\n" "" ROOTALIBDIR ${ROOTALIBDIR}) 
343
344 execute_process(
345 COMMAND root-config --arch 
346 OUTPUT_VARIABLE ARCHITECTURE)
347
348
349 set(AEXT a)
350 set(LIBPATH ${CMAKE_BINARY_DIR}/lib/tgt_${ALICE_TARGET})
351 set(BINPATH ${CMAKE_BINARY_DIR}/bin/tgt_${ALICE_TARGET})
352 set(EXPORTDIR ${ALICE_ROOT}/include)
353 set(BINLIBDIRS -L${ALICE_ROOT}/${LIBPATH})
354 set(RAWDIRO ${CMAKE_BINARY_DIR}/RAW)
355 set(ALIMDCSPECFILE ${RAWDIRO}/alimdc.spec)
356 set(RAWDatabaseALIB ${LIBPATH}/libRAWDatabase.${AEXT})
357 set(ESDALIB ${LIBPATH}/libESD.${AEXT})
358 set(STEERBaseALIB ${LIBPATH}/libSTEERBase.${AEXT})
359 set(MDCALIB ${LIBPATH}/libMDC.${AEXT})
360 set(MODDIRO RAW/tgt_${ALICE_TARGET})
361
362
363 if( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
364 set(ALIMDCARCHDIR x86_64)
365 elseif( ${ARCHITECTURE} MATCHES "linux" )
366 set(ALIMDCARCHDIR i386)
367 elseif( ${ARCHITECTURE} MATCHES "linuxia64gcc" )
368 set(ALIMDCARCHDIR ia64)
369 elseif(NOT DEFINED ${ARCHITECTURE})
370 message("alimdc-rpm: Unknown architecture" )
371 else( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
372 message("alimdc-rpm: Unknown architecture" )
373 endif( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
374
375
376 # Module version will be written in the generated header
377 configure_file ("RAW/alimdc.spec.in" "${CMAKE_CURRENT_BINARY_DIR}/RAW/alimdc.spec" @ONLY)
378
379 add_custom_target( alimdc-rpm
380 DEPENDS alimdc-static
381 )
382
383 add_custom_command(
384 TARGET alimdc-rpm
385 POST_BUILD 
386 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root
387 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
388 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/include
389 COMMAND cp ${ALICE_ROOT}/RAW/mdc.h ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/include
390 COMMAND cp ${LIBPATH}/libAliMDC.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
391 COMMAND cp ${ROOTALIBDIR}/libRoot.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
392 COMMAND cp ${ROOTALIBDIR}/liblzma.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
393 COMMAND cp ${ROOTALIBDIR}/libpcre.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
394 COMMAND cp ${ROOTALIBDIR}/libfreetype.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
395 COMMAND cp ${ROOTALIBDIR}/libpcre.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
396 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/RPMS
397 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/RPMS/${ALIMDCARCHDIR}/
398 COMMAND rpmbuild --verbose --define "_topdir ${CMAKE_CURRENT_BINARY_DIR}" --define "%buildroot ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root" -bb ${ALIMDCSPECFILE} 
399 COMMAND cp -p ${CMAKE_CURRENT_BINARY_DIR}/RPMS/${ALIMDCARCHDIR}/alimdc-*.rpm .
400 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root
401 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/RPMS
402 COMMAND echo "***** alimdc RPM created and put in ${CMAKE_BINARY_DIR} folder *****"
403 )
404
405 add_custom_command(
406 TARGET ${RAWDIRO}
407 COMMAND mkdir-p ${RAWDIRO}
408 )
409
410
411 add_custom_target( alimdc-static
412 DEPENDS ${LIBPATH} ${BINPATH} RAW-all-static STEER-all-static )
413
414 add_custom_command( 
415 TARGET alimdc-static
416 POST_BUILD
417 COMMAND ar r ${LIBPATH}/alimdccxxo.a ${CMAKE_BINARY_DIR}/RAW/CMakeFiles/alimdc.dir/alimdc_main.cxx.o
418 COMMAND rm -rf ${LIBPATH}/libAliMDC.a
419 COMMAND ar x ${RAWDatabaseALIB}
420 COMMAND ar x ${MDCALIB}
421 COMMAND ar x ${ESDALIB}
422 COMMAND ar x ${STEERBaseALIB}
423 COMMAND ar r ${LIBPATH}/libAliMDC.a *.o
424 COMMAND ar t ${RAWDatabaseALIB} | xargs rm 
425 COMMAND ar t ${MDCALIB} | xargs rm 
426 COMMAND ar t ${ESDALIB} | xargs rm 
427 COMMAND ar t ${STEERBaseALIB} | xargs rm 
428 COMMAND ${CMAKE_CXX_COMPILER} ${LDFLAGS} -o ${BINPATH}/alimdca ${LIBPATH}/alimdccxxo.a ${LIBPATH}/libAliMDC.a ${ROOTALIBDIR}/libRoot.a ${ROOTALIBDIR}/libfreetype.a ${ROOTALIBDIR}/libpcre.a ${ROOTALIBDIR}/liblzma.a -pthread -lssl -ldl -lz
429 COMMAND @echo "Target alimdc-static made"
430 )
431
432 add_custom_command(
433 TARGET ${LIBPATH}
434 COMMAND mkdir -p ${LIBPATH}
435 )
436
437
438 #include (MakefileDA) 
439 include (InstallRequiredSystemLibraries)
440 include (CPack)
441
442 # Install data
443 # ------------------------------
444 install ( DIRECTORY data 
445           DESTINATION . )
446 install ( DIRECTORY OCDB 
447           DESTINATION . 
448           PATTERN ".svn" EXCLUDE)
449 install ( DIRECTORY QAref 
450           DESTINATION . 
451           PATTERN ".svn" EXCLUDE)
452 install ( DIRECTORY GRP 
453           DESTINATION . 
454           PATTERN ".svn" EXCLUDE)
455
456 #
457 # EOF
458 #
459