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