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