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