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