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