bugfix for multiplicty option in MC mode (the impact parameter range should not be...
[u/mrichter/AliRoot.git] / cmake / ALICE_CMake.cmake
CommitLineData
62e74968 1# -*- mode: cmake -*-
2
6db31708 3# AliRoot Build System Utility Macro and Function definitions
4#
5# Author: Johny Jose (johny.jose@cern.ch)
6# Port of previous Makefile build to cmake
7
6b06712c 8cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)
6db31708 9
10macro(ALICE_DevFlagsOutput)
11
12 if(ALICEDEV STREQUAL "YES")
13 message(STATUS "FFLAGS : ${FFLAGS}")
14 message(STATUS "CXXFLAGS : ${CXXFLAGS}")
15 message(STATUS "CFLAGS : ${CFLAGS}")
16 message(STATUS "SOFLAGS : ${SOFLAGS}")
17 message(STATUS "LDFLAGS : ${LDFLAGS}")
18 message(STATUS "SHLIB : ${SHLIB}")
19 message(STATUS "SYSLIBS : ${SYSLIBS}")
20 message(STATUS "CINTFLAGS : ${CINTFLAGS}")
d9298a37 21 message(STATUS "CMAKE_Fortran_FLAGS : ${CMAKE_Fortran_FLAGS}")
22 message(STATUS "CMAKE_CXX_FLAGS : ${CMAKE_CXX_FLAGS}")
23 message(STATUS "CMAKE_C_FLAGS : ${CMAKE_C_FLAGS}")
24 message(STATUS "CMAKE_SHARED_LINKER_FLAGS : ${CMAKE_SHARED_LINKER_FLAGS}")
25 message(STATUS "CMAKE_MODULE_LINKER_FLAGS : ${CMAKE_MODULE_LINKER_FLAGS}")
26 message(STATUS "CMAKE_EXE_LINKER_FLAGS : ${CMAKE_EXE_LINKER_FLAGS}")
6db31708 27 endif(ALICEDEV STREQUAL "YES")
28
29endmacro(ALICE_DevFlagsOutput)
30
31function(ALICE_CleanOutput _output input)
32
60154b69 33 string(REGEX REPLACE "\n" " " clean "${input}")
6db31708 34 set(${_output} ${clean} PARENT_SCOPE)
35
36endfunction(ALICE_CleanOutput)
37
38function(ALICE_CorrectPaths _output value )
39
40 set(corrected)
41 foreach(path ${value})
42 set(external)
60154b69 43 string(REGEX MATCH "^/" external "${path}")
6db31708 44 if(NOT external)
45 list(APPEND corrected "${CMAKE_SOURCE_DIR}/${path}" )
46 else()
60154b69 47 list(APPEND corrected "${path}")
6db31708 48 endif(NOT external)
49 endforeach(path)
50 set(${_output} ${corrected} PARENT_SCOPE)
51
52endfunction(ALICE_CorrectPaths)
53
54function(ALICE_Format _output prefix suffix input)
55
56# DevNotes - input should be put in quotes or the complete list does not get passed to the function
57 set(format)
58 foreach(arg ${input})
59 set(item ${arg})
60 if(prefix)
60154b69 61 string(REGEX MATCH "^${prefix}" pre "${arg}")
6db31708 62 endif(prefix)
63 if(suffix)
60154b69 64 string(REGEX MATCH "${suffix}$" suf "${arg}")
6db31708 65 endif(suffix)
66 if(NOT pre)
67 set(item "${prefix}${item}")
68 endif(NOT pre)
69 if(NOT suf)
70 set(item "${item}${suffix}")
71 endif(NOT suf)
72 list(APPEND format ${item})
73 endforeach(arg)
74 set(${_output} ${format} PARENT_SCOPE)
75
76endfunction(ALICE_Format)
77
78function(ALICE_CheckLibraries _output input)
79
80 set(format)
81 foreach(arg ${input})
82 set(item ${arg})
60154b69 83 string(REGEX MATCH "^(/|-)" preformatted "${item}")
6db31708 84 if(NOT preformatted)
85 set(item "-l${item}")
86 endif(NOT preformatted)
87 list(APPEND format ${item})
88 endforeach(arg)
89 set(${_output} ${format} PARENT_SCOPE)
90
91endfunction(ALICE_CheckLibraries)
92
93function(ALICE_RootConfig _output parameters)
94
95 if(ROOT_CONFIG)
96 execute_process(COMMAND ${ROOT_CONFIG} ${parameters} OUTPUT_VARIABLE result ERROR_VARIABLE error OUTPUT_STRIP_TRAILING_WHITESPACE )
97 if(error)
98 message(FATAL_ERROR "root-config ERROR : ${error}")
99 endif(error)
100 ALICE_CleanOutput(result "${result}")
101 set(${_output} "${result}" PARENT_SCOPE)
102 else()
103 message(FATAL_ERROR "root-config not found")
104 endif(ROOT_CONFIG)
105
106endfunction(ALICE_RootConfig)
107
108macro(ALICE_CheckOutOfSourceBuild)
109
110 #Check if previous in-source build failed
111 if(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt OR EXISTS ${CMAKE_SOURCE_DIR}/CMakeFiles)
112 message(FATAL_ERROR "CMakeCache.txt or CMakeFiles exists in source directory! Please remove them before running cmake $ALICE_ROOT")
113 endif(EXISTS ${CMAKE_SOURCE_DIR}/CMakeCache.txt OR EXISTS ${CMAKE_SOURCE_DIR}/CMakeFiles)
114
115 #Get Real Paths of the source and binary directories
116 get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
117 get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
118
119 #Check for in-source builds
120 if(${srcdir} STREQUAL ${bindir})
121 message(FATAL_ERROR "AliRoot cannot be built in-source! Please run cmake $ALICE_ROOT outside the source directory")
122 endif(${srcdir} STREQUAL ${bindir})
123
124endmacro(ALICE_CheckOutOfSourceBuild)
125
126macro(ALICE_ConfigureCompiler)
127
6db31708 128 if(ALIPROFILE STREQUAL "YES")
129 set(ALICE_TARGET ${ALICE_TARGET}PROF)
130 set(FFLAGS "-pg ${FFLAGS}")
131 set(CXXFLAGS "-pg ${CXXFLAGS}")
132 set(CFLAGS "-pg ${CFLAGS}")
133 set(SOFLAGS "-pg ${SOFLAGS}")
134 set(LDFLAGS "-pg ${LDFLAGS}")
135 endif(ALIPROFILE STREQUAL "YES")
136
137 ALICE_RootConfig(RCFLAGS --auxcflags)
138 ALICE_RootConfig(RLFLAGS --ldflags)
139
140 set(CXXFLAGS "${CXXFLAGS} ${RCFLAGS}")
eeeb1bd3 141 string(REPLACE "-std=c++11" " " RCFLAGS "${RCFLAGS}")
6db31708 142 set(CFLAGS "${CFLAGS} ${RCFLAGS}")
143 set(SOFLAGS "${SOFLAGS} ${RLFLAGS}")
144 set(LDFLAGS "${LDFLAGS} ${RLFLAGS}")
145
146 if(NOT ALICXXWARN STREQUAL "NO")
147 set(CXXFLAGS "${CXXFLAGS} ${CXXWARN}")
148 endif(NOT ALICXXWARN STREQUAL "NO")
149
150 set(CXXFLAGS "${DATEFLAGS} ${CXXFLAGS}")
151 set(CFLAGS "${DATEFLAGS} ${CFLAGS}")
152 set(CINTFLAGS "${DATEFLAGS}")
153
154endmacro(ALICE_ConfigureCompiler)
155
156macro(ALICE_ConfigurePlatform)
157
158 ALICE_GetTarget()
159 include("CMake${ALICE_TARGET}")
160
161endmacro(ALICE_ConfigurePlatform)
162
163macro(ALICE_GetTarget)
164
165 #Set ALICE_TARGET if it has not been set yet
166 if(NOT ALICE_TARGET)
167 set(ALICE_TARGET $ENV{ALICE_TARGET})
168 #If ALICE_TARGET is not defined assign default values
169 if(NOT ALICE_TARGET)
170 message(WARNING "Environment variable ALICE_TARGET is not set ! Setting to default value.")
171 ALICE_RootConfig(ALICE_TARGET --arch)
172 message("ALICE_TARGET set to ${ALICE_TARGET}")
173 endif(NOT ALICE_TARGET)
174 endif(NOT ALICE_TARGET)
175
176endmacro(ALICE_GetTarget)
177
178macro(ALICE_ResetPackage)
179
180 set(MODDIR ${MODULE})
181 set(MODDIRI ${PROJECT_SOURCE_DIR}/${MODULE})
182
183 set(SRCS)
184 set(HDRS)
185 set(FSRCS)
186 set(DHDR)
187 set(CSRCS)
188 set(CHDRS)
189 set(EINCLUDE)
190 set(EDEFINE)
191 set(ELIBS)
192 set(ELIBSDIR)
193 set(PACKFFLAGS)
194 set(PACKCXXFLAGS)
195 set(PACKCFLAGS)
196 set(PACKDYFLAGS)
197 set(PACKSOFLAGS)
198 set(PACKLDFLAGS)
199 set(PACKBLIBS)
200 set(EXPORT)
201 set(EHDRS)
202 set(CINTHDRS)
203 set(CINTAUTOLINK)
204 set(ARLIBS)
205 set(SHLIBS)
206
207 #HLT Variables
208 set(MODULE_HDRS)
209 set(MODULE_SRCS)
210 set(MODULE_DHDR)
211 set(CLASS_HDRS)
212 set(LIBRARY_DEP)
213 set(HLTDEFS)
214 set(HLTSOFLAGS)
215
216
217 set(PSRCS)
218 set(PHDRS)
219 set(PFSRCS)
220 set(PDHDR)
221 set(PCSRCS)
222 set(PCHDRS)
223 set(PEINCLUDE)
224 set(PEDEFINE)
225 set(PELIBS)
226 set(PELIBSDIR)
227 set(PPACKFFLAGS)
228 set(PPACKCXXFLAGS)
229 set(PPACKCFLAGS)
230 set(PPACKDYFLAGS)
231 set(PPACKSOFLAGS)
232 set(PPACKLDFLAGS)
233 set(PPACKBLIBS)
234 set(PEXPORT)
235 set(PEHDRS)
236 set(PCINTHDRS)
237 set(PCINTAUTOLINK)
238 set(PARLIBS)
239 set(PSHLIBS)
240 set(PDS)
241
d9298a37 242 set(saveEINCLUDE)
243
6db31708 244endmacro(ALICE_ResetPackage)
245
246function(ALICE_SetPackageVariable _var ext setvalue unsetvalue )
247
248#DevNotes - setvalue and unsetcalue should both be put in quotes or cmake throws an error if they have undefined values
249 if(setvalue)
250 set(${_var} ${setvalue} PARENT_SCOPE)
251 set(${PACKAGE}${ext} ${setvalue} PARENT_SCOPE)
252 else()
253 set(${_var} ${unsetvalue} PARENT_SCOPE)
254 set(${PACKAGE}${ext} ${unsetvalue} PARENT_SCOPE)
255 endif(setvalue)
256
257endfunction(ALICE_SetPackageVariable)
258
259macro(ALICE_BuildPackage)
d9298a37 260 # message(STATUS " ${PACKAGE}")
6db31708 261
262 list(APPEND EINCLUDE STEER)
d9298a37 263 # Needed for PAR files - we need to do this before path
264 # expansion so that the PAR files do not contain references to
265 # specific directories but depend solely on ALICE_ROOT
266 string(REPLACE ";" " " saveEINCLUDE "${EINCLUDE}")
267 # set(saveEINCLUDE "${EINCLUDE}")
268 # message(STATUS "saveEINCLUDE=${saveEINCLUDE} EINCLUDE=${EINCLUDE}")
6db31708 269
270 ALICE_SetPackageVariable(PFFLAGS "FFLAGS" "${PACKFFLAGS}" "${FFLAGS}")
271 ALICE_SetPackageVariable(PCFLAGS "CFLAGS" "${PACKCFLAGS}" "${CFLAGS}")
272 ALICE_SetPackageVariable(PCXXFLAGS "CXXFLAGS" "${PACKCXXFLAGS}" "${CXXFLAGS}")
273 ALICE_SetPackageVariable(PSOFLAGS "SOFLAGS" "${PACKSOFLAGS}" "${SOFLAGS}")
274 ALICE_SetPackageVariable(PLDFLAGS "LDFLAGS" "${PACKLDFLAGS}" "${LDFLAGS}")
275 ALICE_SetPackageVariable(PDCXXFLAGS "DCXXFLAGS" "${PACKDCXXFLAGS}" "${CXXFLAGSNO}")
276 ALICE_SetPackageVariable(PBLIBS "BLIBS" "${PACKBLIBS}" "${LIBS}")
277
278 set(WITHDICT)
279 if(DHDR OR CINTAUTOLINK)
280 set(WITHDICT TRUE)
281 endif(DHDR OR CINTAUTOLINK)
282
283 ALICE_SetPackageVariable(PEDEFINE "EDEFINE" "${EDEFINE}" "${EDEFINE}")
284 ALICE_SetPackageVariable(PEXPORT "EXPORT" "${EXPORT}" "${EXPORT}")
6a1caa6b 285# message(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
6db31708 286 ALICE_SetPackageVariable(PEXPORTDEST "EXPORTDEST" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}" "${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
287 ALICE_SetPackageVariable(PINC "INC" "${EINCLUDE};${MODULE}" "${EINCLUDE};${MODULE}")
288 ALICE_SetPackageVariable(PELIBS "ELIBS" "${ELIBS}" "${ELIBS}")
289 ALICE_SetPackageVariable(PELIBSDIR "ELIBSDIR" "${ELIBSDIR}" "${ELIBSDIR}")
290
291 ALICE_SetPackageVariable(PCS "CS" "${CSRCS}" "${CSRCS}")
292 ALICE_SetPackageVariable(PCH "CH" "${CHDRS}" "${CHDRS}")
293
294 ALICE_SetPackageVariable(PFS "FS" "${FSRCS}" "${FSRCS}")
295
296 ALICE_SetPackageVariable(PS "S" "${SRCS}" "${SRCS}")
297 ALICE_SetPackageVariable(PH "H" "${HDRS} ${EHDRS}" "${HDRS} ${EHDRS}")
298 ALICE_SetPackageVariable(PCINTHDRS "CINTHDRS" "${CINTHDRS}" "${PH}")
299
300 string( REPLACE ".h" "" PCINTCLASSES "${PCINTHDRS}")
301 set ( ${PACKAGE}CINTCLASSES ${PCINTCLASSES})
302
303 ALICE_SetPackageVariable(PDH "DH" "${DHDR}" "")
304
305 if(CINTAUTOLINK)
306 ALICE_SetPackageVariable(PDAL "DAL" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h" "${CMAKE_CURRENT_BINARY_DIR}/G__${PACKAGE}AutoLinkDef.h")
307 ALICE_SetPackageVariable(PDH "DH" "${PDAL}" "${PDAL}")
308 ALICE_GenerateLinkDef()
309 endif(CINTAUTOLINK)
310
311 if(lib)
45526b5e 312 list(APPEND PMLIBS ${PACKAGE})
6db31708 313 list(APPEND ALLLIBS ${PACKAGE})
529f129e 314 list(APPEND PMALIBS ${PACKAGE}-static)
315 list(APPEND ALLALIBS ${PACKAGE}-static)
6db31708 316 list(APPEND BINLIBS ${PACKAGE})
d9298a37 317 # Do not link against other libraries when creating a library
318 # set(PELIBS)
6db31708 319 else()
320 list(APPEND ALLEXECS ${PACKAGE})
321 endif(lib)
45526b5e 322 set(${MODULE}ALIBS "${PMALIBS}" PARENT_SCOPE)
323 set(${MODULE}LIBS "${PMLIBS}" PARENT_SCOPE)
324 set(${MODULE}INC "${EINCLUDE}" PARENT_SCOPE)
6db31708 325 list(APPEND INCLUDEFILES ${PEXPORTDEST})
6db31708 326 if(WITHDICT)
d9298a37 327 # Replace dots in file name with underscores, or rootcint will
328 # write invalid code (namespace names with dots in them)
329 string(REPLACE "." "_" ESC_PACKAGE ${PACKAGE})
330 ALICE_SetPackageVariable(PDS "DS" "G__${ESC_PACKAGE}.cxx" "G__${ESC_PACKAGE}.cxx")
6db31708 331 ALICE_GenerateDictionary()
332 else()
333 if(lib)
334 message(STATUS "No dictionary generated for ${PACKAGE}")
335 endif(lib)
336 endif(WITHDICT)
6db31708 337 if(PS OR PCS OR PFS)
338 if(lib)
339 ALICE_BuildLibrary()
340 elseif(bin)
341 ALICE_BuildExecutable()
342 endif(lib)
343 endif(PS OR PCS OR PFS)
e93f6949 344 ALICE_CopyHeaders()
6a9e2760 345 ALICE_BuildPAR()
6db31708 346
347endmacro(ALICE_BuildPackage)
348
349
350macro(ALICE_BuildModule)
d9298a37 351 # message(STATUS "${MODULE}")
352 execute_process(COMMAND ${CMAKE_COMMAND} -E echo_append "-- ${MODULE}:")
2c1a9c2e 353 add_definitions(-D_MODULE_="${MODULE}")
6db31708 354 foreach(PACKAGEFILE ${PACKAGES})
355 set(lib)
356 set(bin)
60154b69 357 string(REGEX MATCH "CMakelib" lib "${PACKAGEFILE}")
358 string(REGEX MATCH "CMakebin" bin "${PACKAGEFILE}")
6db31708 359 get_filename_component(PACKAGE ${PACKAGEFILE} NAME)
60154b69 360 string(REGEX REPLACE "^CMake(lib|bin)(.*)\\.pkg" "\\2" PACKAGE "${PACKAGE}")
d9298a37 361 execute_process(COMMAND ${CMAKE_COMMAND} -E echo_append " ${PACKAGE}")
6db31708 362 if(ALICEDEV)
363 message("Adding package ${PACKAGE} in ${MODULE}")
364 endif(ALICEDEV)
365 ALICE_ResetPackage()
366 include(${PACKAGEFILE})
367 ALICE_BuildPackage()
368
369 get_property(EXCLUDEPACKAGE TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL)
370 if(NOT EXCLUDEPACKAGE)
371 install(TARGETS ${PACKAGE}
24b052aa 372 RUNTIME DESTINATION bin/tgt_${ALICE_TARGET}
373 LIBRARY DESTINATION lib/tgt_${ALICE_TARGET}
374 ARCHIVE DESTINATION bin/tgt_${ALICE_TARGET})
6db31708 375 endif(NOT EXCLUDEPACKAGE)
376 endforeach(PACKAGEFILE)
e93f6949 377 ALICE_CheckModule()
d9298a37 378 execute_process(COMMAND ${CMAKE_COMMAND} -E echo " done")
6db31708 379endmacro(ALICE_BuildModule)
380
381macro(ALICE_GenerateDictionary)
382
383 if(ALICEDEV STREQUAL "YES")
384 message("Generating Dictionary rule for ${PACKAGE}")
385 message("${ROOTCINT} -f ${PDS} -c ${PEDEFINE} ${CINTFLAGS} ${PINC} ${PCINTHDRS} ${PDH}")
386 endif(ALICEDEV STREQUAL "YES")
387
388 # Split up all arguments
389
390 set(DEDEFINE ${PEDEFINE})
391 set(DCINTFLAGS ${CINTFLAGS})
392 set(DINC ${PINC})
393 set(DCINTHDRS ${PCINTHDRS})
394 set(DDH ${PDH})
395 separate_arguments(DEDEFINE)
396 separate_arguments(DCINTFLAGS)
397 separate_arguments(DINC)
398 separate_arguments(DCINTHDRS)
399 separate_arguments(DDH)
400 # Format neccesary arguments
d9298a37 401 set(ROOT6_ALPHA "5.99.1")
402 string(REGEX REPLACE "/0*" "." ROOT_DOTVERSION ${ROOT_VERSION})
403 if(ROOT_DOTVERSION VERSION_GREATER ROOT6_ALPHA)
404 # For current ROOT6-alpha - without proper PCM support - we need to
405 # give the _full_ path for all include paths, so that libCling can
406 # later attach those to the internal include path of the interpreter
407 # and so that the interpreter can parse the header files.
408 #
409 # THIS SHOULD BE A TEMPORARY HACK!
410 ALICE_Format(DINC "-I{PROJECT_SOURCE_DIR}/" ""
411 "${DINC};${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
412 else()
6db31708 413 ALICE_Format(DINC "-I" "" "${DINC};${CMAKE_INCLUDE_EXPORT_DIRECTORY}")
d9298a37 414 endif(ROOT_DOTVERSION VERSION_GREATER ROOT6_ALPHA)
6db31708 415 set_source_files_properties(${PDS} PROPERTIES GENERATED TRUE)
be33cb74 416 set_source_files_properties(${PDS} PROPERTIES COMPILE_FLAGS "-w")
6db31708 417 add_custom_command(OUTPUT ${PDS}
418 COMMAND cd ${PROJECT_SOURCE_DIR} && ${ROOTCINT} -f ${CMAKE_CURRENT_BINARY_DIR}/${PDS} -c -D_MODULE=\\\"${MODULE}\\\" ${DEDEFINE} ${DCINTFLAGS} ${DINC} ${DCINTHDRS} ${DDH}
419 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
420 DEPENDS ${DCINTHDRS} ${DDH}
421 )
422 add_custom_target(G${PACKAGE})
423 add_dependencies(G${PACKAGE} ${PDS})
424
425endmacro(ALICE_GenerateDictionary)
426
427macro(ALICE_BuildLibrary)
428
6db31708 429 set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS}")
430 set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS}")
ceab6e7b 431 set(CMAKE_Fortran_FLAGS "${PEDEFINE} ${PFFLAGS}")
6db31708 432 set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS})
433 set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
d9298a37 434 ALICE_DevFlagsOutput()
6db31708 435
436
437 separate_arguments(PINC)
438 separate_arguments(EINCLUDE)
439 separate_arguments(PELIBSDIR)
440 separate_arguments(PBLIBS)
441 separate_arguments(PELIBS)
442 separate_arguments(SHLIB)
443
444 ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
445 ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
6db31708 446
447 ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
448 ALICE_CorrectPaths(PINC "${PINC}")
449
450 include_directories(SYSTEM ${ROOTINCDIR})
451 include_directories(${PINC})
452 include_directories(${EINCLUDE})
453 include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
454
455 add_library(${PACKAGE} SHARED ${PCS} ${PFS} ${PS} ${PDS})
13f96c00 456 set_target_properties(${PACKAGE} PROPERTIES SUFFIX .so)
6db31708 457
458
459 if(PELIBS OR SHLIB)
460 target_link_libraries(${PACKAGE} ${PELIBSDIR} ${PELIBS} ${SHLIB})
461 endif(PELIBS OR SHLIB)
462
463 add_dependencies(${MODULE}-all ${PACKAGE})
464
529f129e 465 add_library(${PACKAGE}-static STATIC EXCLUDE_FROM_ALL ${PCS} ${PFS} ${PS} ${PDS})
466 set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME ${PACKAGE})
6db31708 467 if(PELIBS OR ALLIB)
529f129e 468 target_link_libraries(${PACKAGE}-static ${PELIBSDIR} ${PELIBS} ${ALLIB})
6db31708 469 endif(PELIBS OR ALLIB)
470
529f129e 471 add_dependencies(${MODULE}-all-static ${PACKAGE}-static)
6db31708 472 if(ALIPROFILE STREQUAL "YES")
473 add_dependencies(${MODULE}-all ${MODULE}-static)
474 endif(ALIPROFILE STREQUAL "YES")
475
476 list(FIND EXCLUDEMODULES ${MODULE} RESULT)
477 if(NOT RESULT STREQUAL "-1")
478 message(STATUS "${MODULE} will not be built by default. Type make ${MODULE}-all to build.")
479 set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
480 endif(NOT RESULT STREQUAL "-1")
481
e93f6949 482 set_target_properties(${PACKAGE} PROPERTIES INSTALL_NAME_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
483
6db31708 484endmacro(ALICE_BuildLibrary)
485
486macro(ALICE_BuildExecutable)
487
6db31708 488 set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS} ${EXEFLAGS}")
489 set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS} ${EXEFLAGS}")
490 set(CMAKE_Fortran_FLAGS "${PEDEFINE} ${PFFLAGS} ${EXEFLAGS}")
491 set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS})
492 set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
d9298a37 493 set(CMAKE_EXE_LINKER_FLAGS ${PLDFLAGS})
494 ALICE_DevFlagsOutput()
6db31708 495
496 separate_arguments(PINC)
497 separate_arguments(EINCLUDE)
498 separate_arguments(PELIBSDIR)
499 separate_arguments(PBLIBS)
500 separate_arguments(PELIBS)
501 separate_arguments(SHLIB)
e93f6949 502
6db31708 503 ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
504 ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
6db31708 505
506 ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
507 ALICE_CorrectPaths(PINC "${PINC}")
508
509 include_directories(SYSTEM ${ROOTINCDIR})
510 include_directories(${PINC})
511 include_directories(${EINCLUDE})
512 include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
513
514 if(ALIPROFILE STREQUAL "YES")
515 add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
516 if(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
517 target_link_libraries(${PACKAGE} ${ARLIBS} ${SHLIBS} ${PBLIBS} ${EXEFLAGS})
518 endif(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
519 add_dependencies(${MODULE}-all ${PACKAGE})
520 else()
521 add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
522 if(PELIBS OR PBLIBS OR EXEFLAGS)
523 target_link_libraries(${PACKAGE} ${BINLIBDIRS} ${PELIBSDIR} ${PELIBS} ${PBLIBS} ${EXEFLAGS})
524 endif(PELIBS OR PBLIBS OR EXEFLAGS)
525 add_dependencies(${MODULE}-all ${PACKAGE})
526 endif(ALIPROFILE STREQUAL "YES")
527
7531a2ac 528# AliMDC
529# ------------------------------
0742852a 530 if(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
7531a2ac 531
0742852a 532 add_executable(${PACKAGE}-static ${PFS} ${PCS} ${PS} ${PDS})
7531a2ac 533 set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME alimdca)
534 add_custom_target( libAliMDC
535 COMMAND rm -rf ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a
536 COMMAND rm -rf junkmdc
537 COMMAND mkdir junkmdc && cd junkmdc && ar x ../libRAWDatabase.a && ar x ../libMDC.a && ar x ../libESD.a && ar x ../libSTEERBase.a && ar r ../libAliMDC.a *.o && cd .. && rm -rf junkmdc
7531a2ac 538 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
dad683d0 539 add_custom_target( root-static-libs
540 COMMAND make static
541 WORKING_DIRECTORY ${ROOTSYS} )
542
7531a2ac 543 add_dependencies(libAliMDC RAWDatabase-static STEERBase-static MDC-static ESD-static)
dad683d0 544 add_dependencies(${PACKAGE}-static libAliMDC root-static-libs)
7531a2ac 545 target_link_libraries(${PACKAGE}-static ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${ROOTLIBDIR}/libRoot.a ${ROOTLIBDIR}/libfreetype.a ${ROOTLIBDIR}/libpcre.a -pthread -ldl -lcurses)
7531a2ac 546
24b052aa 547 install(TARGETS ${PACKAGE}-static RUNTIME DESTINATION bin/tgt_${ALICE_TARGET} COMPONENT MDC)
548 install(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${ROOTLIBDIR}/libRoot.a ${ROOTLIBDIR}/libfreetype.a ${ROOTLIBDIR}/libpcre.a DESTINATION lib/tgt_${ALICE_TARGET} COMPONENT MDC)
0742852a 549 install(FILES ${PROJECT_SOURCE_DIR}/RAW/mdc.h DESTINATION include COMPONENT MDC)
550 set(CPACK_RPM_PACKAGE_SUMMARY "AliMDC static libraries")
551 set(CPACK_RPM_PACKAGE_NAME "alimdc")
552 set(CPACK_RPM_PACKAGE_VERSION "${ALIMDCVERSION}")
553 set(CPACK_RPM_PACKAGE_RELEASE "${ALIMDCRELEASE}")
e66e598e 554 set(CPACK_RPM_PACKAGE_LICENSE "License: CERN ALICE Off-line Group")
0742852a 555 set(CPACK_RPM_PACKAGE_VENDOR "ALICE Core Off-line Group")
556 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AliMDC static libraries")
557 set(CPACK_RPM_PACKAGE_GROUP "Applications/Alice")
558 set(CPACK_RPM_PACKAGE_REQUIRES "glibc")
559 set(CPACK_PACKAGE_VERSION "1.0.0")
560 set(CPACK_PACKAGE_VERSION_MAJOR "1")
561 set(CPACK_PACKAGE_VERSION_MINOR "0")
562 set(CPACK_PACKAGE_VERSION_PATCH "0")
563 set(CPACK_PACKAGE_INSTALL_DIRECTORY "/opt/")
564 add_component_package(MDC alimdc-rpm)
565
566 endif(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
7531a2ac 567
6db31708 568 list(FIND EXCLUDEMODULES ${MODULE} RESULT)
569 if(NOT RESULT STREQUAL "-1")
570 set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
571 endif(NOT RESULT STREQUAL "-1")
572
573endmacro(ALICE_BuildExecutable)
574
575macro(ALICE_CopyHeaders)
576
e93f6949 577 if(EXPORT )
6db31708 578 set(HEADERS ${EXPORT})
e93f6949 579 set(_headersdep)
580 foreach(header ${HEADERS})
31e2a8d5 581 get_filename_component( header_name ${header} NAME )
582 add_custom_command(OUTPUT ${PEXPORTDEST}/${header_name}
583 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/${MODULE}/${header} ${PEXPORTDEST}/${header_name}
ae388d3b 584 DEPENDS ${CMAKE_SOURCE_DIR}/${MODULE}/${header})
31e2a8d5 585 list(APPEND _headersdep ${PEXPORTDEST}/${header_name})
6db31708 586 install(FILES ${header} DESTINATION include)
e93f6949 587 endforeach(header)
588 add_custom_target(${PACKAGE}-headers DEPENDS ${_headersdep})
589 add_dependencies(${PACKAGE} ${PACKAGE}-headers)
590 endif(EXPORT)
6db31708 591
592endmacro(ALICE_CopyHeaders)
593
594macro(ALICE_GenerateLinkDef)
0e67c40f 595 set(PCLASSES)
6db31708 596 foreach (class ${PCINTCLASSES})
597 get_filename_component(classname ${class} NAME)
2854d28f 598 # set(PCLASSES ${PCLASSES} "\\n#pragma link C++ class ${classname}+;")
599 set(PCLASSES ${PCLASSES} "${classname}")
6db31708 600 endforeach(class)
0e67c40f 601
602 add_custom_command(OUTPUT ${PDAL}
2854d28f 603 COMMAND sh ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh ${PCLASSES} > ${PDAL}
604 DEPENDS ${PCINTHDRS} ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh)
6db31708 605endmacro(ALICE_GenerateLinkDef)
0742852a 606
6a9e2760 607macro(ALICE_BuildPAR)
741bbd87 608
741bbd87 609 if(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
8948a174 610 set(PARSRCS)
3a8dbb31 611 foreach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
612 get_filename_component(srcdir ${file} PATH)
8948a174 613 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par
614 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${srcdir}
615 COMMAND cp -pR ${file} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}
3a8dbb31 616 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
8948a174 617 list(APPEND PARSRCS ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par)
3a8dbb31 618 endforeach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
8948a174 619
d9298a37 620 # message(STATUS "saveEINCLUDE=${saveEINCLUDE}")
8948a174 621 add_custom_target(${PACKAGE}.par
d9298a37 622 COMMAND sed -e 's,include ..ROOTSYS./\\\(etc\\|test\\\)/Makefile.arch,include Makefile.arch,\; s/PACKAGE = .*/PACKAGE = ${PACKAGE}/\; s,SRCS *=.*,SRCS = ${SRCS},\;' < Makefile | sed -e 's,HDRS *=.*,HDRS = ${HDRS},\; s,FSRCS *=.*,FSRCS = ${FSRCS},\; s,DHDR *=.*,DHDR = ${DHDR},\; s,EINCLUDE *:=.*,EINCLUDE := ${saveEINCLUDE},' > ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/Makefile
623 COMMAND cp -pR `root-config --etcdir`/Makefile.arch ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/Makefile.arch
8948a174 624 COMMAND cp -pR PROOF-INF.${PACKAGE} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/PROOF-INF
84d4333f 625# COMMAND cp -pR lib${PACKAGE}.pkg ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
8948a174 626 COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} tar --exclude=.svn -czhf ${CMAKE_BINARY_DIR}/${PACKAGE}.par ${PACKAGE}
627 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
628 COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red --bold "${PACKAGE}.par has been created in ${CMAKE_BINARY_DIR}"
629 DEPENDS ${PARSRCS}
630 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
631
3a8dbb31 632
958d9d26 633 add_dependencies(${PACKAGE}.par ${SRCS} ${FSRCS} ${HDRS} ${DHDR})
6a9e2760 634 add_dependencies(par-all ${PACKAGE}.par)
3a8dbb31 635 add_dependencies(${MODULE}-par-all ${PACKAGE}.par)
636
637 add_custom_target(test-${PACKAGE}.par
638 COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red --bold "The file ${PACKAGE}.par is now being tested, in case of an error check in par-tmp/${PACKAGE}."
639 COMMAND ${CMAKE_COMMAND} -E make_directory par-tmp
640 COMMAND ${CMAKE_COMMAND} -E chdir par-tmp tar xfz ../${PACKAGE}.par && ${CMAKE_COMMAND} -E chdir par-tmp/${PACKAGE} PROOF-INF/BUILD.sh
641 COMMAND ${CMAKE_COMMAND} -E remove_directory par-tmp
642 COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green --bold "${PACKAGE}.par testing succeeded"
643 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
644
958d9d26 645 add_dependencies(test-${PACKAGE}.par ${PACKAGE}.par)
3a8dbb31 646 add_dependencies(test-par-all test-${PACKAGE}.par)
647 add_dependencies(test-${MODULE}-par-all test-${PACKAGE}.par)
648
741bbd87 649 endif(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
650 # endif(EXISTS ${ALICE_ROOT}/${MODULE}/PROOF-INF.${PACKAGE})
651
6a9e2760 652endmacro(ALICE_BuildPAR)
0742852a 653