including switch to set on/off iso-track core removal, cleaning and bug fix
[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 $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 than we set it to ALICE_INSTALL. 
31 # If ALICE_INSTALL was not defined than it will default to 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 STORAGE 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 if(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
192  include(GetGitRevisionDescription)
193  
194  find_package(Git)
195  
196  if(GIT_FOUND)
197   get_git_head_revision(GIT_REFSPEC GIT_SHA1)
198
199   # GIT_REFSPEC is empty for detached mode = tags in detached mode or checkout to specific hash
200  
201
202   # returns the closest reference to the current hash
203   # name of the current tag or heads/branch in the case of branches
204   git_describe(ALIROOT_GIT_TAG "--all" "--abbrev=0")
205
206   STRING(REGEX REPLACE "^(.+/)(.+)/(.*)$" "\\2" BRANCH_TYPE "${GIT_REFSPEC}" )
207
208   # the revision is not set in the case of a branch, it means we are doing development
209   # and the revision will trigger a reconfiguration
210   if(BRANCH_TYPE STREQUAL "heads")
211    set(ALIROOT_REVISION "ThisIsaBranchNoRevisionProvided")
212    STRING(REGEX REPLACE "^(.+/)(.+/)(.*)$" "\\3" SHORT_BRANCH "${GIT_REFSPEC}" )
213   else()
214    set(SHORT_BRANCH ${ALIROOT_GIT_TAG})
215    set(ALIROOT_REVISION ${GIT_SHA1})
216   endif()
217
218   set(ALIROOT_BRANCH ${SHORT_BRANCH})
219   message(STATUS "Aliroot branch/tag: \"${ALIROOT_BRANCH}\" - Revision:  \"${GIT_SHA1}\" ")
220
221  else()
222   message("Git not installed. I can't tell you which revision you are using!")
223   endif(GIT_FOUND)
224 else()
225  message("AliRoot sources not downloaded from a Version Control System. I can't tell which revision you are using!")
226 endif(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
227
228 configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/FromTemplate/ARVersion.h @ONLY)
229
230 string (REPLACE "-" "." ALIROOT_BRANCH_SPEC "${ALIROOT_BRANCH}")
231
232 #--------------------------------------------------------------------------------#
233 # Build Modules                                                                  #
234 #--------------------------------------------------------------------------------#
235
236 # Module Variables
237 # ------------------------------
238 set(ALLLIBS)
239 set(ALLEXECS)
240 set(INCLUDEFILES)
241 set(BINLIBS)
242 set(EXPORTFILES)
243
244 # Top Level Build Targets
245 # ------------------------------
246
247 add_custom_target(alilibs-static)
248 add_custom_target(include-headers ALL)
249 add_custom_target(DA-all)
250 add_custom_target(check-all) 
251 add_custom_target(check-hxml)
252 add_custom_target(smell-all) 
253 add_custom_target(htmldoc) 
254 add_custom_target(par-all)
255 add_custom_target(test-par-all)
256
257 #NY file(GLOB CFILES_LIST ${CMAKE_SOURCE_DIR}/macros/*.C)
258
259 add_custom_command(TARGET htmldoc
260                    PRE_BUILD
261                    COMMAND mkdir -p html
262                    COMMAND rm -rf html/roothtml
263                    COMMAND rm -f html/picts
264                    COMMAND cd html && aliroot -q -b mkhtml.C\\\(0,1\\\)
265                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
266
267 # Include Vc, which provides the static libVc and the relevant CMake macros
268 include(Vc/Vc.cmake)
269 add_subdirectory(Vc)
270
271 # Add Modules   
272 # ------------------------------
273 foreach(MODULE ${MODDIRS})
274   set(${MODULE}ALIBS)
275 #RS  configure_file(${PROJECT_SOURCE_DIR}/cmake/Module.tmp ${PROJECT_SOURCE_DIR}/${MODULE}/CMakeLists.txt @ONLY)
276   add_custom_target(${MODULE}-all ALL)
277   add_custom_target(${MODULE}-par-all)
278   add_custom_target(test-${MODULE}-par-all)
279   add_custom_target(${MODULE}-all-static)
280   add_dependencies(alilibs-static "${MODULE}-static")
281   add_subdirectory(${MODULE})
282   
283 #NY  set(dir "${CMAKE_SOURCE_DIR}/${MODULE}")
284 #NY  if (EXISTS "${dir}")
285 #NY      file(GLOB CFILES_MOD ${dir}/*.C)
286 #NY      list(LENGTH CFILES_MOD len)
287 #NY      if (${len} GREATER 0)
288 #NY        list(APPEND CFILES_LIST "${CFILES_MOD}")
289 #NY      endif (${len} GREATER 0)
290 #NY  endif(EXISTS "${dir}")
291 endforeach(MODULE)
292
293 #NY foreach(cfile ${CFILES_LIST})
294 #NY     add_custom_command(TARGET htmldoc
295 #NY                    PRE_BUILD
296 #NY                    COMMAND cd html && 
297 #NY                            aliroot -b -q \"mkhtml.C(\"${cfile}\")\" > /dev/null
298 #NY                    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
299 #NY endforeach(cfile)
300
301 if(DATE_FOUND)
302   include (CMakeDA)
303 endif(DATE_FOUND)
304
305 if(RULECHECKER_FOUND)
306     add_custom_target(factfile DEPENDS ${FACTFILE})
307     add_custom_command( OUTPUT ${FACTFILE}
308                         COMMAND ${CMAKE_COMMAND} -E echo "Re-generating factfile"
309                         COMMAND ${JAVA_RUNTIME}  -Xmx1024M -jar ${FACTEXTRACTOR_JAR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}                    
310                         DEPENDS check-hxml ${CMAKE_BINARY_DIR}/check-hxml-touchfile ${_factfile_deps} 
311                         WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
312 endif(RULECHECKER_FOUND)
313
314 #--------------------------------------------------------------------------------#
315 # Additional Targets                                                             #
316 #--------------------------------------------------------------------------------#
317
318 # AliMdc RPM
319 # ------------------------------
320
321 execute_process(
322 COMMAND root-config --libdir 
323 OUTPUT_VARIABLE ROOTALIBDIR)
324 string(REPLACE "\n" "" ROOTALIBDIR ${ROOTALIBDIR}) 
325
326 execute_process(
327 COMMAND root-config --arch 
328 OUTPUT_VARIABLE ARCHITECTURE)
329
330
331 set(AEXT a)
332 set(LIBPATH ${CMAKE_BINARY_DIR}/lib/tgt_${ALICE_TARGET})
333 set(BINPATH ${CMAKE_BINARY_DIR}/bin/tgt_${ALICE_TARGET})
334 set(EXPORTDIR ${ALICE_ROOT}/include)
335 set(BINLIBDIRS -L${ALICE_ROOT}/${LIBPATH})
336 set(RAWDIRO ${CMAKE_BINARY_DIR}/RAW)
337 set(ALIMDCSPECFILE ${RAWDIRO}/alimdc.spec)
338 set(RAWDatabaseALIB ${LIBPATH}/libRAWDatabase.${AEXT})
339 set(ESDALIB ${LIBPATH}/libESD.${AEXT})
340 set(STEERBaseALIB ${LIBPATH}/libSTEERBase.${AEXT})
341 set(MDCALIB ${LIBPATH}/libMDC.${AEXT})
342 set(MODDIRO RAW/tgt_${ALICE_TARGET})
343
344
345 if( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
346 set(ALIMDCARCHDIR x86_64)
347 elseif( ${ARCHITECTURE} MATCHES "linux" )
348 set(ALIMDCARCHDIR i386)
349 elseif( ${ARCHITECTURE} MATCHES "linuxia64gcc" )
350 set(ALIMDCARCHDIR ia64)
351 elseif(NOT DEFINED ${ARCHITECTURE})
352 message("alimdc-rpm: Unknown architecture" )
353 else( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
354 message("alimdc-rpm: Unknown architecture" )
355 endif( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
356
357
358 # Module version will be written in the generated header
359 configure_file ("RAW/alimdc.spec.in" "${CMAKE_CURRENT_BINARY_DIR}/RAW/alimdc.spec" @ONLY)
360
361 add_custom_target( alimdc-rpm
362 DEPENDS alimdc-static
363 )
364
365 add_custom_command(
366 TARGET alimdc-rpm
367 POST_BUILD 
368 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root
369 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
370 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/include
371 COMMAND cp ${ALICE_ROOT}/RAW/mdc.h ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/include
372 COMMAND cp ${LIBPATH}/libAliMDC.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
373 COMMAND cp ${ROOTALIBDIR}/libRoot.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
374 COMMAND cp ${ROOTALIBDIR}/liblzma.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
375 COMMAND cp ${ROOTALIBDIR}/libpcre.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
376 COMMAND cp ${ROOTALIBDIR}/libfreetype.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
377 COMMAND cp ${ROOTALIBDIR}/libpcre.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
378 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/RPMS
379 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/RPMS/${ALIMDCARCHDIR}/
380 COMMAND rpmbuild --verbose --define "_topdir ${CMAKE_CURRENT_BINARY_DIR}" --define "%buildroot ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root" -bb ${ALIMDCSPECFILE} 
381 COMMAND cp -p ${CMAKE_CURRENT_BINARY_DIR}/RPMS/${ALIMDCARCHDIR}/alimdc-*.rpm .
382 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root
383 COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/RPMS
384 COMMAND echo "***** alimdc RPM created and put in ${CMAKE_BINARY_DIR} folder *****"
385 )
386
387 add_custom_command(
388 TARGET ${RAWDIRO}
389 COMMAND mkdir-p ${RAWDIRO}
390 )
391
392
393 add_custom_target( alimdc-static
394 DEPENDS ${LIBPATH} ${BINPATH} RAW-all-static STEER-all-static )
395
396 add_custom_command( 
397 TARGET alimdc-static
398 POST_BUILD
399 COMMAND ar r ${LIBPATH}/alimdccxxo.a ${CMAKE_BINARY_DIR}/RAW/CMakeFiles/alimdc.dir/alimdc_main.cxx.o
400 COMMAND rm -rf ${LIBPATH}/libAliMDC.a
401 COMMAND ar x ${RAWDatabaseALIB}
402 COMMAND ar x ${MDCALIB}
403 COMMAND ar x ${ESDALIB}
404 COMMAND ar x ${STEERBaseALIB}
405 COMMAND ar r ${LIBPATH}/libAliMDC.a *.o
406 COMMAND ar t ${RAWDatabaseALIB} | xargs rm 
407 COMMAND ar t ${MDCALIB} | xargs rm 
408 COMMAND ar t ${ESDALIB} | xargs rm 
409 COMMAND ar t ${STEERBaseALIB} | xargs rm 
410 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
411 COMMAND @echo "Target alimdc-static made"
412 )
413
414 add_custom_command(
415 TARGET ${LIBPATH}
416 COMMAND mkdir -p ${LIBPATH}
417 )
418
419
420 #include (MakefileDA) 
421 include (InstallRequiredSystemLibraries)
422 include (CPack)
423
424 # Install data
425 # ------------------------------
426 install ( DIRECTORY data 
427           DESTINATION . )
428 install ( DIRECTORY OCDB 
429           DESTINATION . 
430           PATTERN ".svn" EXCLUDE)
431 install ( DIRECTORY QAref 
432           DESTINATION . 
433           PATTERN ".svn" EXCLUDE)
434 install ( DIRECTORY GRP 
435           DESTINATION . 
436           PATTERN ".svn" EXCLUDE)
437
438 #
439 # EOF
440 #
441