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