a23c7dc0c0ecba56967a8912acd8eb42a16e964e
[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 FATAL_ERROR)
10
11 #--------------------------------------------------------------------------------#
12 # Set Basic CMake Configuration                                                  #
13 #--------------------------------------------------------------------------------#
14
15 project(AliRoot CXX C Fortran)
16
17 # Environment variables
18 set(ALICE_ROOT $ENV{ALICE_ROOT})
19 set(ALICE $ENV{ALICE})
20 set(ALICE_INSTALL $ENV{ALICE_INSTALL})
21 # Environment for SHUTTLE
22 set(DIMDIR $ENV{DIMDIR})
23 set(ODIR $ENV{ODIR})
24
25 if(NOT ALICE)
26   message(WARNING "Environment variable ALICE is not set")
27 endif(NOT ALICE)
28
29 if(NOT ALICE_ROOT)
30   message(FATAL_ERROR "Please set ALICE_ROOT to the AliRoot source directory")
31 endif(NOT ALICE_ROOT)
32
33 # Set AliRoot Installation directory 
34 if(NOT ALICE_INSTALL)
35   message(STATUS "AliRoot files will be installed in ${ALICE_ROOT}. You can specify a different location by setting ALICE_INSTALL environment variable")
36   set(ALICE_INSTALL ${ALICE_ROOT})
37 else()
38   message(STATUS "AliRoot files will be installed in ${ALICE_INSTALL}")
39 endif(NOT ALICE_INSTALL)
40 set(CMAKE_INSTALL_PREFIX ${ALICE_INSTALL})
41
42 get_filename_component(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}" REALPATH)
43 set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
44 set(CPACK_COMPONENTS_ALL MDC)
45
46 include(ALICE_CMake)
47
48 #--------------------------------------------------------------------------------#
49 # Find Packages                                                                  #
50 #--------------------------------------------------------------------------------#
51
52 # Subversion
53 # ------------------------------
54
55 find_package(Subversion REQUIRED)
56
57 # ROOT
58 # ------------------------------
59
60 find_package(ROOT REQUIRED)
61
62 # IRST Rule Checker 
63 # ------------------------------
64
65 find_package(RuleChecker)
66
67 # DATE
68 # ------------------------------ 
69
70 find_package(DATE)
71
72 # GEANT3
73 # ------------------------------
74
75 find_package(GEANT3)
76
77 # AMORE
78 # ------------------------------
79
80 find_package(AMORE)
81
82 # AliRoot CPack configuration                                                    
83 #-------------------------------
84
85 find_package(CPack)
86
87
88 #--------------------------------------------------------------------------------#
89 # Environment/Compiler Configuration                                             #
90 #--------------------------------------------------------------------------------#
91
92 ALICE_CheckOutOfSourceBuild()
93 ALICE_RootConfig(CMAKE_CXX_COMPILER --cxx)
94 ALICE_RootConfig(CMAKE_C_COMPILER --cc)
95 ALICE_RootConfig(CMAKE_Fortran_COMPILER --f77)
96 ALICE_ConfigurePlatform()
97 ALICE_ConfigureCompiler()
98
99
100 #--------------------------------------------------------------------------------#
101 # AliRoot Path Settings                                                          #
102 #--------------------------------------------------------------------------------#
103
104 ALICE_DevFlagsOutput()
105 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/tgt_${ALICE_TARGET}")
106 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
107 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/tgt_${ALICE_TARGET}")
108 set(CMAKE_INCLUDE_EXPORT_DIRECTORY "${PROJECT_BINARY_DIR}/include")
109 file(MAKE_DIRECTORY ${CMAKE_INCLUDE_EXPORT_DIRECTORY})
110 set(EXPORTDIRS "${ALICE_INSTALL}/include")
111 set(BINLIBDIRS "-L${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
112
113
114 #--------------------------------------------------------------------------------#
115 # AliRoot Modules                                                                #
116 #--------------------------------------------------------------------------------#
117
118 # Exclude Module from all target
119 # ------------------------------
120
121 #set(EXCLUDEMODULES THydjet SHUTTLE)
122
123
124 # Standard Modules
125 # ------------------------------
126 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 LHC STAT TTherminator CORRFW DPMJET TDPMjet PWG0 PWG1 PWG2 PWG3 PWG4 TRIGGER PYTHIA8 TAmpt OADB )
127
128 if(THydjet)
129   list(APPEND ALIROOTMODULES THydjet)
130 endif(THydjet)
131
132 if(SHUTTLE)
133   list(APPEND ALIROOTMODULES SHUTTLE)
134 endif(SHUTTLE)
135
136 # Additional Modules
137 # ------------------------------
138 list(APPEND ALIROOTMODULES TUHKMgen EPOS)
139
140 # EVE
141 # ------------------------------
142 ALICE_RootConfig(EVE --has-opengl)
143 if(NOT EVE STREQUAL "no")
144   list(APPEND ALIROOTMODULES EVE)
145 endif(NOT EVE STREQUAL "no")
146
147 # CERN Modules
148 # ------------------------------
149 set(CERNMODULES LHAPDF HIJING MICROCERN HERWIG)
150
151 # Check for Pythia 6
152 if(EXISTS ${ROOTINCDIR}/TPythia6.h)
153   set(PYTHIA6 TRUE)
154   list(APPEND CERNMODULES PYTHIA6 EVGEN)
155 elseif(NOT NOPYTHIA)
156   message(FATAL_ERROR "ROOT must have Pythia6 enabled !")
157 endif(EXISTS ${ROOTINCDIR}/TPythia6.h)
158
159 # Set Final list of modules 
160 set(MODULES ${ALIROOTMODULES} ${CERNMODULES} ALIROOT)
161
162 # Set Module directories
163 set(MODDIRS ${MODULES})
164
165 # Libraries for Linking
166 # ------------------------------
167 set(ALILIBS MUON TPC PMD TRD FMD TOF ITS PHOS ACORDE HMPID VZERO ZDC STRUCT T0 EVGEN STEER TRIGGER)
168 set(LIBS ${ROOTCLIBS} ${ROOTPLIBS} ${SYSLIBS})
169
170 # Configure ARVerion.h
171 # ------------------------------
172 if(Subversion_FOUND)
173   if(EXISTS ${PROJECT_SOURCE_DIR}/.svn/ )
174   Subversion_WC_INFO(${PROJECT_SOURCE_DIR} PROJECT)
175   set(ALIROOT_SVN_REVISION ${PROJECT_WC_REVISION})
176   set(ALIROOT_SVN_BRANCH ${PROJECT_WC_URL})
177   string(REGEX MATCH "[^/]+$" ALIROOT_SVN_BRANCH ${ALIROOT_SVN_BRANCH})
178
179   elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git/ )
180     execute_process(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND git svn info OUTPUT_VARIABLE OUTPUTVAR)
181     string(REPLACE "\n" ";" OUTPUTVAR ${OUTPUTVAR})
182     foreach(f ${OUTPUTVAR})
183       if(${f} MATCHES URL)
184         string(REGEX MATCH "[^/]+$" ALIROOT_SVN_BRANCH ${f})
185       elseif(${f} MATCHES Revision)
186         string(REGEX MATCH "[^: ]+$" ALIROOT_SVN_REVISION ${f})
187       endif(${f} MATCHES URL)   
188     endforeach()
189   endif(EXISTS ${PROJECT_SOURCE_DIR}/.svn/ )
190
191   message(STATUS "Aliroot Revision - ${ALIROOT_SVN_REVISION} Branch - ${ALIROOT_SVN_BRANCH}")
192   if(EXISTS ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
193     file(REMOVE ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
194   endif(EXISTS ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h)
195   configure_file(${PROJECT_SOURCE_DIR}/cmake/ARVersion.h.tmp ${CMAKE_INCLUDE_EXPORT_DIRECTORY}/ARVersion.h @ONLY)
196 endif(Subversion_FOUND)
197
198 #--------------------------------------------------------------------------------#
199 # Build Modules                                                                  #
200 #--------------------------------------------------------------------------------#
201
202 # Module Variables
203 # ------------------------------
204 set(ALLLIBS)
205 set(ALLEXECS)
206 set(INCLUDEFILES)
207 set(BINLIBS)
208 set(EXPORTFILES)
209
210 # Top Level Build Targets
211 # ------------------------------
212
213 add_custom_target(alilibs-static)
214 add_custom_target(include-headers)
215 add_custom_target(DA-all)
216 #  if(RULECHECKER_FOUND)
217   add_custom_target(check-all)
218   add_dependencies(check-all ${FACTFILE})
219 #  endif(RULECHECKER_FOUND)
220 add_custom_target(par-all)
221 add_custom_target(test-par-all)
222
223 # Add Modules
224 # ------------------------------
225 foreach(MODULE ${MODDIRS})
226   set(${MODULE}ALIBS)
227   configure_file(${PROJECT_SOURCE_DIR}/cmake/Module.tmp ${PROJECT_SOURCE_DIR}/${MODULE}/CMakeLists.txt @ONLY)
228   add_custom_target(${MODULE}-all ALL)
229   add_custom_target(${MODULE}-check-all)
230   add_custom_target(${MODULE}-par-all)
231   add_custom_target(test-${MODULE}-par-all)
232 #  if(RULECHECKER_FOUND)
233   add_dependencies(check-all "${MODULE}-check-all")
234 #  endif(RULECHECKER_FOUND)
235   add_custom_target(${MODULE}-all-static)
236   add_dependencies(alilibs-static "${MODULE}-static")
237   add_subdirectory(${MODULE})
238 endforeach(MODULE)
239
240 if(DATE_FOUND AND AMORE_FOUND)
241   include (CMakeDA)
242 endif(DATE_FOUND AND AMORE_FOUND)
243
244 #if(RULECHECKER_FOUND)
245     add_custom_command( OUTPUT ${FACTFILE}
246                         COMMAND ${JAVA_RUNTIME} -jar ${FACTEXTRACTOR_JAR} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
247                         DEPENDS ${_factfile_deps}
248                         WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
249 #endif(RULECHECKER_FOUND)
250
251 #--------------------------------------------------------------------------------#
252 # Additional Targets                                                             #
253 #--------------------------------------------------------------------------------#
254
255 # AliMdc RPM
256 # ------------------------------
257
258 include (InstallRequiredSystemLibraries)
259 include (CPack)
260