3 # Top level CMakeList.txt file for the AliRoot Build System
5 # Author: Johny Jose (johny.jose@cern.ch)
6 # Port of previous Makefile build to cmake
9 cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
11 #--------------------------------------------------------------------------------#
12 # Set Basic CMake Configuration #
13 #--------------------------------------------------------------------------------#
15 project(AliRoot CXX C Fortran)
17 # Environment variables
18 set(ALICE_ROOT $ENV{ALICE_ROOT})
19 set(ALICE $ENV{ALICE})
20 set(ALICE_INSTALL $ENV{ALICE_INSTALL})
21 if(${ALICE_INSTALL} MATCHES ${CMAKE_BINARY_DIR})
22 message(FATAL_ERROR "Install dir should be different from build dir")
23 endif(${ALICE_INSTALL} MATCHES ${CMAKE_BINARY_DIR})
24 # Environment for SHUTTLE
25 set(DIMDIR $ENV{DIMDIR})
29 message(WARNING "Environment variable ALICE is not set")
33 message(FATAL_ERROR "Please set ALICE_ROOT to the AliRoot source directory")
36 # Set AliRoot Installation directory
38 message(STATUS "AliRoot files will be installed in ${ALICE_ROOT}. You can specify a different location by setting ALICE_INSTALL environment variable")
39 set(ALICE_INSTALL ${ALICE_ROOT})
41 message(STATUS "AliRoot files will be installed in ${ALICE_INSTALL}")
42 endif(NOT ALICE_INSTALL)
43 set(CMAKE_INSTALL_PREFIX ${ALICE_INSTALL})
45 get_filename_component(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}" REALPATH)
46 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
47 set(CPACK_COMPONENTS_ALL MDC)
51 #--------------------------------------------------------------------------------#
53 #--------------------------------------------------------------------------------#
56 # ------------------------------
58 find_package(Subversion REQUIRED)
61 # ------------------------------
63 find_package(ROOT REQUIRED)
66 # ------------------------------
68 find_package(RuleChecker)
71 # ------------------------------
76 # ------------------------------
81 # ------------------------------
85 # AliRoot CPack configuration
86 #-------------------------------
91 #--------------------------------------------------------------------------------#
92 # Environment/Compiler Configuration #
93 #--------------------------------------------------------------------------------#
95 ALICE_CheckOutOfSourceBuild()
96 ALICE_RootConfig(CMAKE_CXX_COMPILER --cxx)
97 ALICE_RootConfig(CMAKE_C_COMPILER --cc)
98 ALICE_RootConfig(CMAKE_Fortran_COMPILER --f77)
99 ALICE_ConfigurePlatform()
100 ALICE_ConfigureCompiler()
103 #--------------------------------------------------------------------------------#
104 # AliRoot Path Settings #
105 #--------------------------------------------------------------------------------#
107 ALICE_DevFlagsOutput()
108 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/tgt_${ALICE_TARGET}")
109 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
110 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
111 set(CMAKE_INCLUDE_EXPORT_DIRECTORY "${PROJECT_BINARY_DIR}/include")
112 file(MAKE_DIRECTORY ${CMAKE_INCLUDE_EXPORT_DIRECTORY})
113 set(EXPORTDIRS "${ALICE_INSTALL}/include")
114 set(BINLIBDIRS "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
117 #--------------------------------------------------------------------------------#
119 #--------------------------------------------------------------------------------#
121 # Exclude Module from all target
122 # ------------------------------
124 #set(EXCLUDEMODULES THydjet SHUTTLE)
128 # ------------------------------
129 set(ALIROOTMODULES STEER PHOS TRD TPC ZDC MUON PMD FMD TOF ITS ACORDE HMPID T0 BCM STRUCT VZERO THijing THbtp EMCAL THerwig TEPEMGEN FASTSIM TPHIC RAW MONITOR ANALYSIS JETAN HLT STAT TTherminator CORRFW DPMJET TDPMjet PWGPP PWG PWGCF PWGGA PWGHF PWGDQ PWGJE PWGLF PWGUD TRIGGER PYTHIA8 TAmpt OADB MFT TEvtGen)
132 list(APPEND ALIROOTMODULES THydjet)
136 list(APPEND ALIROOTMODULES SHUTTLE)
140 # ------------------------------
141 list(APPEND ALIROOTMODULES TUHKMgen EPOS)
144 # ------------------------------
145 ALICE_RootConfig(EVE --has-opengl)
146 if(NOT EVE STREQUAL "no")
147 list(APPEND ALIROOTMODULES EVE)
148 endif(NOT EVE STREQUAL "no")
151 # ------------------------------
152 set(CERNMODULES LHAPDF HIJING MICROCERN HERWIG)
155 if(EXISTS ${ROOTINCDIR}/TPythia6.h)
157 list(APPEND CERNMODULES PYTHIA6 EVGEN)
159 message(FATAL_ERROR "ROOT must have Pythia6 enabled !")
160 endif(EXISTS ${ROOTINCDIR}/TPythia6.h)
162 # Set Final list of modules
163 set(MODULES ${ALIROOTMODULES} ${CERNMODULES} ALIROOT)
165 # Set Module directories
166 set(MODDIRS ${MODULES})
168 # Libraries for Linking
169 # ------------------------------
170 set(ALILIBS MUON TPC PMD TRD FMD TOF ITS PHOS ACORDE HMPID VZERO ZDC STRUCT T0 EVGEN STEER TRIGGER MFT)
171 set(LIBS ${ROOTCLIBS} ${ROOTPLIBS} ${SYSLIBS})
173 # Configure ARVerion.h
174 # ------------------------------
176 if(EXISTS ${PROJECT_SOURCE_DIR}/.svn/ )
177 Subversion_WC_INFO(${PROJECT_SOURCE_DIR} PROJECT)
178 set(ALIROOT_SVN_REVISION ${PROJECT_WC_REVISION})
179 set(ALIROOT_SVN_BRANCH ${PROJECT_WC_URL})
180 string(REGEX MATCH "[^/]+$" ALIROOT_SVN_BRANCH ${ALIROOT_SVN_BRANCH})
182 elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git/ )
183 execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND git svn info OUTPUT_VARIABLE OUTPUTVAR)
184 string(REPLACE "\n" ";" OUTPUTVAR ${OUTPUTVAR})
185 foreach(f ${OUTPUTVAR})
187 string(REGEX MATCH "[^/]+$" ALIROOT_SVN_BRANCH ${f})
188 elseif(${f} MATCHES Revision)
189 string(REGEX MATCH "[^: ]+$" ALIROOT_SVN_REVISION ${f})
190 endif(${f} MATCHES URL)
192 endif(EXISTS ${PROJECT_SOURCE_DIR}/.svn/ )
194 message(STATUS "Aliroot Revision - ${ALIROOT_SVN_REVISION} Branch - ${ALIROOT_SVN_BRANCH}")
195 if(EXISTS ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
196 file(REMOVE ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
197 endif(EXISTS ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
198 configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h @ONLY)
199 endif(Subversion_FOUND)
200 string (REPLACE "-" "." ALIROOT_SVN_BRANCH_SPEC "${ALIROOT_SVN_BRANCH}")
202 #--------------------------------------------------------------------------------#
204 #--------------------------------------------------------------------------------#
207 # ------------------------------
214 # Top Level Build Targets
215 # ------------------------------
217 add_custom_target(alilibs-static)
218 add_custom_target(include-headers ALL)
219 add_custom_target(DA-all)
220 add_custom_target(check-all)
221 add_custom_target(check-hxml)
222 add_custom_target(smell-all)
223 add_custom_target(htmldoc)
224 add_custom_target(par-all)
225 add_custom_target(test-par-all)
227 #NY file(GLOB CFILES_LIST ${CMAKE_SOURCE_DIR}/macros/*.C)
229 add_custom_command(TARGET htmldoc
231 COMMAND mkdir -p html
232 COMMAND rm -rf html/roothtml
233 COMMAND rm -f html/picts
235 aliroot -q -b \"mkhtml.C(0,1)\"
236 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
238 # Include Vc, which provides the static libVc and the relevant CMake macros
243 # ------------------------------
244 foreach(MODULE ${MODDIRS})
246 #RS configure_file(${PROJECT_SOURCE_DIR}/cmake/Module.tmp ${PROJECT_SOURCE_DIR}/${MODULE}/CMakeLists.txt @ONLY)
247 add_custom_target(${MODULE}-all ALL)
248 add_custom_target(${MODULE}-par-all)
249 add_custom_target(test-${MODULE}-par-all)
250 add_custom_target(${MODULE}-all-static)
251 add_dependencies(alilibs-static "${MODULE}-static")
252 add_subdirectory(${MODULE})
254 #NY set(dir "${CMAKE_SOURCE_DIR}/${MODULE}")
255 #NY if (EXISTS "${dir}")
256 #NY file(GLOB CFILES_MOD ${dir}/*.C)
257 #NY list(LENGTH CFILES_MOD len)
258 #NY if (${len} GREATER 0)
259 #NY list(APPEND CFILES_LIST "${CFILES_MOD}")
260 #NY endif (${len} GREATER 0)
261 #NY endif(EXISTS "${dir}")
264 #NY foreach(cfile ${CFILES_LIST})
265 #NY add_custom_command(TARGET htmldoc
267 #NY COMMAND cd html &&
268 #NY aliroot -b -q \"mkhtml.C(\"${cfile}\")\" > /dev/null
269 #NY WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
270 #NY endforeach(cfile)
276 if(RULECHECKER_FOUND)
277 add_custom_target(factfile DEPENDS ${FACTFILE})
278 add_custom_command( OUTPUT ${FACTFILE}
279 COMMAND ${CMAKE_COMMAND} -E echo "Re-generating factfile"
280 COMMAND ${JAVA_RUNTIME} -Xmx1024M -jar ${FACTEXTRACTOR_JAR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
281 DEPENDS check-hxml ${CMAKE_BINARY_DIR}/check-hxml-touchfile ${_factfile_deps}
282 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
283 endif(RULECHECKER_FOUND)
285 #--------------------------------------------------------------------------------#
286 # Additional Targets #
287 #--------------------------------------------------------------------------------#
290 # ------------------------------
293 COMMAND root-config --libdir
294 OUTPUT_VARIABLE ROOTALIBDIR)
295 string(REPLACE "\n" "" ROOTALIBDIR ${ROOTALIBDIR})
298 COMMAND root-config --arch
299 OUTPUT_VARIABLE ARCHITECTURE)
303 set(LIBPATH ${CMAKE_BINARY_DIR}/lib/tgt_${ALICE_TARGET})
304 set(BINPATH ${CMAKE_BINARY_DIR}/bin/tgt_${ALICE_TARGET})
305 set(EXPORTDIR ${ALICE_ROOT}/include)
306 set(BINLIBDIRS -L${ALICE_ROOT}/${LIBPATH})
307 set(RAWDIRO ${CMAKE_BINARY_DIR}/RAW)
308 set(ALIMDCSPECFILE ${RAWDIRO}/alimdc.spec)
309 set(RAWDatabaseALIB ${LIBPATH}/libRAWDatabase.${AEXT})
310 set(ESDALIB ${LIBPATH}/libESD.${AEXT})
311 set(STEERBaseALIB ${LIBPATH}/libSTEERBase.${AEXT})
312 set(MDCALIB ${LIBPATH}/libMDC.${AEXT})
313 set(MODDIRO RAW/tgt_${ALICE_TARGET})
316 if( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
317 set(ALIMDCARCHDIR x86_64)
318 elseif( ${ARCHITECTURE} MATCHES "linux" )
319 set(ALIMDCARCHDIR i386)
320 elseif( ${ARCHITECTURE} MATCHES "linuxia64gcc" )
321 set(ALIMDCARCHDIR ia64)
322 elseif(NOT DEFINED ${ARCHITECTURE})
323 message("alimdc-rpm: Unknown architecture" )
324 else( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
325 message("alimdc-rpm: Unknown architecture" )
326 endif( ${ARCHITECTURE} MATCHES "linuxx8664gcc" )
329 add_custom_target( alimdc-rpm
330 DEPENDS alimdc-static alimdc-specfile
336 COMMAND rm -rf ${ALICE_ROOT}/alimdc-root
337 COMMAND mkdir -p ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
338 COMMAND mkdir -p ${ALICE_ROOT}/alimdc-root/opt/alimdc/include
339 COMMAND cp ${ALICE_ROOT}/RAW/mdc.h ${ALICE_ROOT}/alimdc-root/opt/alimdc/include
340 COMMAND cp ${LIBPATH}/libAliMDC.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
341 COMMAND cp ${ROOTALIBDIR}/libRoot.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
342 COMMAND cp ${ROOTALIBDIR}/liblzma.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
343 COMMAND cp ${ROOTALIBDIR}/libpcre.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
344 COMMAND cp ${ROOTALIBDIR}/libfreetype.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
345 COMMAND cp ${ROOTALIBDIR}/libpcre.a ${ALICE_ROOT}/alimdc-root/opt/alimdc/lib
346 COMMAND rm -rf ${ALICE_ROOT}/RPMS
347 COMMAND mkdir -p ${ALICE_ROOT}/RPMS/${ALIMDCARCHDIR}/
348 COMMAND rpmbuild --verbose --define "_topdir ${ALICE_ROOT}" --define "_tmppath ${ALICE_ROOT}" -bb ${ALIMDCSPECFILE}
349 COMMAND cp -p ${ALICE_ROOT}/RPMS/${ALIMDCARCHDIR}/alimdc-*.rpm .
350 COMMAND rm -rf ${ALICE_ROOT}/alimdc-root
351 COMMAND rm -rf ${ALICE_ROOT}/RPMS
352 COMMAND echo "***** alimdc RPM created and put in ${CMAKE_BINARY_DIR} folder *****"
357 COMMAND mkdir-p ${RAWDIRO}
361 add_custom_target( alimdc-specfile
366 TARGET alimdc-specfile
368 COMMAND rm -rf ${ALIMDCSPECFILE}
369 COMMAND @echo "***** Making alimdc RPM spec-file ${ALIMDCSPECFILE} *****"
370 COMMAND @echo '\# RPM specfile for alimdc static libs' >> ${ALIMDCSPECFILE}
371 COMMAND @echo '\# Package contains both ROOT and AliRoot' >> ${ALIMDCSPECFILE}
372 COMMAND @echo '\# static libs needed by mStreamRecorder' >> ${ALIMDCSPECFILE}
373 COMMAND @echo '\# in order to ROOT-ify the incoming raw' >> ${ALIMDCSPECFILE}
374 COMMAND @echo '\# data' >> ${ALIMDCSPECFILE}
375 COMMAND @echo '\# Example how-to build alimdc RPM:' >> ${ALIMDCSPECFILE}
376 COMMAND @echo '\# cd ${ALICE_ROOT}' >> ${ALIMDCSPECFILE}
377 COMMAND @echo '\# make alimdc-rpm' >> ${ALIMDCSPECFILE}
378 COMMAND @echo "" >> ${ALIMDCSPECFILE}
379 COMMAND @echo "Summary: AliMDC static libraries" >> ${ALIMDCSPECFILE}
380 COMMAND @echo "Name: alimdc" >> ${ALIMDCSPECFILE}
381 COMMAND @echo "Version: ${ALIROOT_SVN_BRANCH_SPEC}" >> ${ALIMDCSPECFILE}
382 COMMAND @echo "Release: ${ALIROOT_SVN_REVISION}" >> ${ALIMDCSPECFILE}
383 COMMAND @echo '\# Copyright: CERN Alice Off-line' >> ${ALIMDCSPECFILE}
384 COMMAND @echo "License: CERN Alice Off-line" >> ${ALIMDCSPECFILE}
385 COMMAND @echo "Vendor: ALICE Core Off-line Group" >> ${ALIMDCSPECFILE}
386 COMMAND @echo "URL: http://aliceinfo.cern.ch" >> ${ALIMDCSPECFILE}
387 COMMAND @echo "Group: Applications/Alice" >> ${ALIMDCSPECFILE}
388 COMMAND @echo "Prefix: /opt/%{name}" >> ${ALIMDCSPECFILE}
389 COMMAND @echo "BuildRoot: %{_tmppath}/%{name}-root" >> ${ALIMDCSPECFILE}
390 COMMAND @echo "" >> ${ALIMDCSPECFILE}
391 COMMAND @echo '\# automatic dependencies' >> ${ALIMDCSPECFILE}
392 COMMAND @echo "AutoReqProv: yes" >> ${ALIMDCSPECFILE}
393 COMMAND @echo "" >> ${ALIMDCSPECFILE}
394 COMMAND @echo '\# list here required RPM packages for runtime' >> ${ALIMDCSPECFILE}
395 COMMAND @echo "Requires: glibc" >> ${ALIMDCSPECFILE}
396 COMMAND @echo "" >> ${ALIMDCSPECFILE}
397 COMMAND @echo "Provides: alimdc" >> ${ALIMDCSPECFILE}
398 COMMAND @echo "" >> ${ALIMDCSPECFILE}
399 COMMAND @echo '\# description of the package' >> ${ALIMDCSPECFILE}
400 COMMAND @echo "%description" >> ${ALIMDCSPECFILE}
401 COMMAND @echo "Package contains both ROOT and AliRoot" >> ${ALIMDCSPECFILE}
402 COMMAND @echo "static libs needed by mStreamRecorder" >> ${ALIMDCSPECFILE}
403 COMMAND @echo "in order to ROOT-ify the incoming raw" >> ${ALIMDCSPECFILE}
404 COMMAND @echo "data. The package version correspond to" >> ${ALIMDCSPECFILE}
405 COMMAND @echo "the AliRoot one." >> ${ALIMDCSPECFILE}
406 COMMAND @echo "" >> ${ALIMDCSPECFILE}
407 COMMAND @echo '\# list of files to be installed' >> ${ALIMDCSPECFILE}
408 COMMAND @echo "%files" >> ${ALIMDCSPECFILE}
409 COMMAND @echo '%defattr (-,root,root)' >> ${ALIMDCSPECFILE}
410 COMMAND @echo "%{prefix}/lib/libAliMDC.a" >> ${ALIMDCSPECFILE}
411 COMMAND @echo "%{prefix}/lib/libRoot.a" >> ${ALIMDCSPECFILE}
412 COMMAND @echo "%{prefix}/lib/libpcre.a" >> ${ALIMDCSPECFILE}
413 COMMAND @echo "%{prefix}/lib/liblzma.a" >> ${ALIMDCSPECFILE}
414 COMMAND @echo "%{prefix}/lib/libfreetype.a" >> ${ALIMDCSPECFILE}
415 COMMAND @echo "%{prefix}/include/mdc.h" >> ${ALIMDCSPECFILE}
419 add_custom_target( alimdc-static
420 DEPENDS ${LIBPATH} ${BINPATH} RAW-all-static STEER-all-static )
425 COMMAND ar r ${LIBPATH}/alimdccxxo.a ${CMAKE_BINARY_DIR}/RAW/CMakeFiles/alimdc.dir/alimdc_main.cxx.o
426 COMMAND rm -rf ${LIBPATH}/libAliMDC.a
427 COMMAND ar x ${RAWDatabaseALIB}
428 COMMAND ar x ${MDCALIB}
429 COMMAND ar x ${ESDALIB}
430 COMMAND ar x ${STEERBaseALIB}
431 COMMAND ar r ${LIBPATH}/libAliMDC.a *.o
432 COMMAND ar t ${RAWDatabaseALIB} | xargs rm
433 COMMAND ar t ${MDCALIB} | xargs rm
434 COMMAND ar t ${ESDALIB} | xargs rm
435 COMMAND ar t ${STEERBaseALIB} | xargs rm
436 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 -ldl -lz
437 COMMAND @echo "Target alimdc-static made"
442 COMMAND mkdir -p ${LIBPATH}
446 #include (MakefileDA)
447 include (InstallRequiredSystemLibraries)
451 # ------------------------------
452 install ( DIRECTORY data
454 install ( DIRECTORY OCDB
456 PATTERN ".svn" EXCLUDE)
457 install ( DIRECTORY QAref
459 PATTERN ".svn" EXCLUDE)