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