roll back of previous commit
[u/mrichter/AliRoot.git] / CMakeLists.txt
... / ...
CommitLineData
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
9cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
10
11#--------------------------------------------------------------------------------#
12# Set Basic CMake Configuration #
13#--------------------------------------------------------------------------------#
14
15project(AliRoot CXX C Fortran)
16
17# Environment variables
18set(ALICE $ENV{ALICE})
19if(NOT ALICE)
20 message(WARNING "Environment variable ALICE is not set")
21endif(NOT ALICE)
22
23set(ALICE_ROOT $ENV{ALICE_ROOT})
24if(NOT ALICE_ROOT)
25 message(FATAL_ERROR "Please set ALICE_ROOT to the AliRoot source directory")
26endif(NOT ALICE_ROOT)
27
28set(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
32if(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)
46endif()
47
48
49# Environment for SHUTTLE
50set(DIMDIR $ENV{DIMDIR})
51set(ODIR $ENV{ODIR})
52
53get_filename_component(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}" REALPATH)
54set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
55set(CPACK_COMPONENTS_ALL MDC)
56
57include(ALICE_CMake)
58
59#--------------------------------------------------------------------------------#
60# Find Packages #
61#--------------------------------------------------------------------------------#
62
63# Subversion
64# ------------------------------
65
66find_package(Subversion REQUIRED)
67
68# ROOT
69# ------------------------------
70
71find_package(ROOT REQUIRED)
72
73# IRST Rule Checker
74# ------------------------------
75
76find_package(RuleChecker)
77
78# DATE
79# ------------------------------
80
81find_package(DATE)
82
83# GEANT3
84# ------------------------------
85
86find_package(GEANT3)
87
88# AMORE
89# ------------------------------
90
91find_package(AMORE)
92
93# AliRoot CPack configuration
94#-------------------------------
95
96find_package(CPack)
97
98# ZeroMQ
99# ------------------------------
100find_package(ZeroMQ)
101
102# fastjet
103# ------------------------------
104find_package(FASTJET)
105
106#--------------------------------------------------------------------------------#
107# Environment/Compiler Configuration #
108#--------------------------------------------------------------------------------#
109
110ALICE_CheckOutOfSourceBuild()
111ALICE_RootConfig(CMAKE_CXX_COMPILER --cxx)
112ALICE_RootConfig(CMAKE_C_COMPILER --cc)
113ALICE_RootConfig(CMAKE_Fortran_COMPILER --f77)
114ALICE_ConfigurePlatform()
115ALICE_ConfigureCompiler()
116
117
118#--------------------------------------------------------------------------------#
119# AliRoot Path Settings #
120#--------------------------------------------------------------------------------#
121
122ALICE_DevFlagsOutput()
123set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/tgt_${ALICE_TARGET}")
124set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
125set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
126set(CMAKE_INCLUDE_EXPORT_DIRECTORY "${PROJECT_BINARY_DIR}/include")
127file(MAKE_DIRECTORY ${CMAKE_INCLUDE_EXPORT_DIRECTORY})
128set(EXPORTDIRS "${ALICE_INSTALL}/include")
129set(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# ------------------------------
144set(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
146if(THydjet)
147 list(APPEND ALIROOTMODULES THydjet)
148endif(THydjet)
149
150if(SHUTTLE)
151 list(APPEND ALIROOTMODULES SHUTTLE)
152endif(SHUTTLE)
153
154# Additional Modules
155# ------------------------------
156list(APPEND ALIROOTMODULES TUHKMgen EPOS)
157
158# EVE
159# ------------------------------
160ALICE_RootConfig(EVE --has-opengl)
161if(NOT EVE STREQUAL "no")
162 list(APPEND ALIROOTMODULES EVE)
163endif(NOT EVE STREQUAL "no")
164
165# CERN Modules
166# ------------------------------
167set(CERNMODULES LHAPDF HIJING MICROCERN HERWIG)
168
169# Check for Pythia 6
170if(EXISTS ${ROOTINCDIR}/TPythia6.h)
171 set(PYTHIA6 TRUE)
172 list(APPEND CERNMODULES PYTHIA6 EVGEN)
173elseif(NOT NOPYTHIA)
174 message(FATAL_ERROR "ROOT must have Pythia6 enabled !")
175endif(EXISTS ${ROOTINCDIR}/TPythia6.h)
176
177# Set Final list of modules
178set(MODULES ${ALIROOTMODULES} ${CERNMODULES} ALIROOT)
179
180# Set Module directories
181set(MODDIRS ${MODULES})
182
183# Libraries for Linking
184# ------------------------------
185set(ALILIBS MUON TPC PMD TRD FMD TOF ITS PHOS AD ACORDE HMPID VZERO ZDC STRUCT T0 EVGEN STEER TRIGGER MFT)
186set(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
196if(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)
242else()
243 message("AliRoot sources not downloaded from a Version Control System. I can't tell which revision you are using!")
244endif(EXISTS ${PROJECT_SOURCE_DIR}/.git/)
245
246configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/FromTemplate/ARVersion.h @ONLY)
247
248string (REPLACE "-" "." ALIROOT_BRANCH_SPEC "${ALIROOT_BRANCH}")
249
250#--------------------------------------------------------------------------------#
251# Build Modules #
252#--------------------------------------------------------------------------------#
253
254# Module Variables
255# ------------------------------
256set(ALLLIBS)
257set(ALLEXECS)
258set(INCLUDEFILES)
259set(BINLIBS)
260set(EXPORTFILES)
261
262# Top Level Build Targets
263# ------------------------------
264
265add_custom_target(alilibs-static)
266add_custom_target(include-headers ALL)
267add_custom_target(DA-all)
268add_custom_target(check-all)
269add_custom_target(check-hxml)
270add_custom_target(smell-all)
271add_custom_target(htmldoc)
272add_custom_target(par-all)
273add_custom_target(test-par-all)
274
275#NY file(GLOB CFILES_LIST ${CMAKE_SOURCE_DIR}/macros/*.C)
276
277add_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
286include(Vc/Vc.cmake)
287add_subdirectory(Vc)
288
289# Add Modules
290# ------------------------------
291foreach(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}")
309endforeach(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
319if(DATE_FOUND)
320 include (CMakeDA)
321endif(DATE_FOUND)
322
323if(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})
330endif(RULECHECKER_FOUND)
331
332#--------------------------------------------------------------------------------#
333# Additional Targets #
334#--------------------------------------------------------------------------------#
335
336# AliMdc RPM
337# ------------------------------
338
339execute_process(
340COMMAND root-config --libdir
341OUTPUT_VARIABLE ROOTALIBDIR)
342string(REPLACE "\n" "" ROOTALIBDIR ${ROOTALIBDIR})
343
344execute_process(
345COMMAND root-config --arch
346OUTPUT_VARIABLE ARCHITECTURE)
347
348
349set(AEXT a)
350set(LIBPATH ${CMAKE_BINARY_DIR}/lib/tgt_${ALICE_TARGET})
351set(BINPATH ${CMAKE_BINARY_DIR}/bin/tgt_${ALICE_TARGET})
352set(EXPORTDIR ${ALICE_ROOT}/include)
353set(BINLIBDIRS -L${ALICE_ROOT}/${LIBPATH})
354set(RAWDIRO ${CMAKE_BINARY_DIR}/RAW)
355set(ALIMDCSPECFILE ${RAWDIRO}/alimdc.spec)
356set(RAWDatabaseALIB ${LIBPATH}/libRAWDatabase.${AEXT})
357set(ESDALIB ${LIBPATH}/libESD.${AEXT})
358set(STEERBaseALIB ${LIBPATH}/libSTEERBase.${AEXT})
359set(MDCALIB ${LIBPATH}/libMDC.${AEXT})
360set(MODDIRO RAW/tgt_${ALICE_TARGET})
361
362
363if( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
364set(ALIMDCARCHDIR x86_64)
365elseif( ${ARCHITECTURE} MATCHES "linux" )
366set(ALIMDCARCHDIR i386)
367elseif( ${ARCHITECTURE} MATCHES "linuxia64gcc" )
368set(ALIMDCARCHDIR ia64)
369elseif(NOT DEFINED ${ARCHITECTURE})
370message("alimdc-rpm: Unknown architecture" )
371else( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
372message("alimdc-rpm: Unknown architecture" )
373endif( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
374
375
376# Module version will be written in the generated header
377configure_file ("RAW/alimdc.spec.in" "${CMAKE_CURRENT_BINARY_DIR}/RAW/alimdc.spec" @ONLY)
378
379add_custom_target( alimdc-rpm
380DEPENDS alimdc-static
381)
382
383add_custom_command(
384TARGET alimdc-rpm
385POST_BUILD
386COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root
387COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
388COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/include
389COMMAND cp ${ALICE_ROOT}/RAW/mdc.h ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/include
390COMMAND cp ${LIBPATH}/libAliMDC.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
391COMMAND cp ${ROOTALIBDIR}/libRoot.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
392COMMAND cp ${ROOTALIBDIR}/liblzma.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
393COMMAND cp ${ROOTALIBDIR}/libpcre.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
394COMMAND cp ${ROOTALIBDIR}/libfreetype.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
395COMMAND cp ${ROOTALIBDIR}/libpcre.a ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root/opt/alimdc/lib
396COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/RPMS
397COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/RPMS/${ALIMDCARCHDIR}/
398COMMAND rpmbuild --verbose --define "_topdir ${CMAKE_CURRENT_BINARY_DIR}" --define "%buildroot ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root" -bb ${ALIMDCSPECFILE}
399COMMAND cp -p ${CMAKE_CURRENT_BINARY_DIR}/RPMS/${ALIMDCARCHDIR}/alimdc-*.rpm .
400COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/alimdc-root
401COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/RPMS
402COMMAND echo "***** alimdc RPM created and put in ${CMAKE_BINARY_DIR} folder *****"
403)
404
405add_custom_command(
406TARGET ${RAWDIRO}
407COMMAND mkdir-p ${RAWDIRO}
408)
409
410
411add_custom_target( alimdc-static
412DEPENDS ${LIBPATH} ${BINPATH} RAW-all-static STEER-all-static )
413
414add_custom_command(
415TARGET alimdc-static
416POST_BUILD
417COMMAND ar r ${LIBPATH}/alimdccxxo.a ${CMAKE_BINARY_DIR}/RAW/CMakeFiles/alimdc.dir/alimdc_main.cxx.o
418COMMAND rm -rf ${LIBPATH}/libAliMDC.a
419COMMAND ar x ${RAWDatabaseALIB}
420COMMAND ar x ${MDCALIB}
421COMMAND ar x ${ESDALIB}
422COMMAND ar x ${STEERBaseALIB}
423COMMAND ar r ${LIBPATH}/libAliMDC.a *.o
424COMMAND ar t ${RAWDatabaseALIB} | xargs rm
425COMMAND ar t ${MDCALIB} | xargs rm
426COMMAND ar t ${ESDALIB} | xargs rm
427COMMAND ar t ${STEERBaseALIB} | xargs rm
428COMMAND ${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
429COMMAND @echo "Target alimdc-static made"
430)
431
432add_custom_command(
433TARGET ${LIBPATH}
434COMMAND mkdir -p ${LIBPATH}
435)
436
437
438#include (MakefileDA)
439include (InstallRequiredSystemLibraries)
440include (CPack)
441
442# Install data
443# ------------------------------
444install ( DIRECTORY data
445 DESTINATION . )
446install ( DIRECTORY OCDB
447 DESTINATION .
448 PATTERN ".svn" EXCLUDE)
449install ( DIRECTORY QAref
450 DESTINATION .
451 PATTERN ".svn" EXCLUDE)
452install ( DIRECTORY GRP
453 DESTINATION .
454 PATTERN ".svn" EXCLUDE)
455
456#
457# EOF
458#
459