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