update EMCal EP v2
[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!
58f88c5c 410 ALICE_Format(DINC "-I${PROJECT_SOURCE_DIR}/" ""
d9298a37 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})
7c12019f 454 include_directories(${CMAKE_SOURCE_DIR})
6db31708 455
456 add_library(${PACKAGE} SHARED ${PCS} ${PFS} ${PS} ${PDS})
13f96c00 457 set_target_properties(${PACKAGE} PROPERTIES SUFFIX .so)
6db31708 458
459
460 if(PELIBS OR SHLIB)
461 target_link_libraries(${PACKAGE} ${PELIBSDIR} ${PELIBS} ${SHLIB})
462 endif(PELIBS OR SHLIB)
463
464 add_dependencies(${MODULE}-all ${PACKAGE})
465
529f129e 466 add_library(${PACKAGE}-static STATIC EXCLUDE_FROM_ALL ${PCS} ${PFS} ${PS} ${PDS})
467 set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME ${PACKAGE})
6db31708 468 if(PELIBS OR ALLIB)
529f129e 469 target_link_libraries(${PACKAGE}-static ${PELIBSDIR} ${PELIBS} ${ALLIB})
6db31708 470 endif(PELIBS OR ALLIB)
471
529f129e 472 add_dependencies(${MODULE}-all-static ${PACKAGE}-static)
6db31708 473 if(ALIPROFILE STREQUAL "YES")
474 add_dependencies(${MODULE}-all ${MODULE}-static)
475 endif(ALIPROFILE STREQUAL "YES")
476
477 list(FIND EXCLUDEMODULES ${MODULE} RESULT)
478 if(NOT RESULT STREQUAL "-1")
479 message(STATUS "${MODULE} will not be built by default. Type make ${MODULE}-all to build.")
480 set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
481 endif(NOT RESULT STREQUAL "-1")
482
e93f6949 483 set_target_properties(${PACKAGE} PROPERTIES INSTALL_NAME_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
484
6db31708 485endmacro(ALICE_BuildLibrary)
486
487macro(ALICE_BuildExecutable)
488
6db31708 489 set(CMAKE_CXX_FLAGS "${PEDEFINE} ${PCXXFLAGS} ${EXEFLAGS}")
490 set(CMAKE_C_FLAGS "${PEDEFINE} ${PCFLAGS} ${EXEFLAGS}")
491 set(CMAKE_Fortran_FLAGS "${PEDEFINE} ${PFFLAGS} ${EXEFLAGS}")
492 set(CMAKE_SHARED_LINKER_FLAGS ${PSOFLAGS})
493 set(CMAKE_MODULE_LINKER_FLAGS ${PLDFLAGS})
d9298a37 494 set(CMAKE_EXE_LINKER_FLAGS ${PLDFLAGS})
495 ALICE_DevFlagsOutput()
6db31708 496
497 separate_arguments(PINC)
498 separate_arguments(EINCLUDE)
499 separate_arguments(PELIBSDIR)
500 separate_arguments(PBLIBS)
501 separate_arguments(PELIBS)
502 separate_arguments(SHLIB)
e93f6949 503
6db31708 504 ALICE_Format(PELIBSDIR "-L" "" "${PELIBSDIR}")
505 ALICE_CheckLibraries(PBLIBS "${PBLIBS}")
6db31708 506
507 ALICE_CorrectPaths(EINCLUDE "${EINCLUDE}")
508 ALICE_CorrectPaths(PINC "${PINC}")
509
510 include_directories(SYSTEM ${ROOTINCDIR})
511 include_directories(${PINC})
512 include_directories(${EINCLUDE})
513 include_directories(${CMAKE_INCLUDE_EXPORT_DIRECTORY})
514
515 if(ALIPROFILE STREQUAL "YES")
516 add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
517 if(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
518 target_link_libraries(${PACKAGE} ${ARLIBS} ${SHLIBS} ${PBLIBS} ${EXEFLAGS})
519 endif(ARLIBS OR SHLIBS OR PBLIBS OR EXEFLAGS)
520 add_dependencies(${MODULE}-all ${PACKAGE})
521 else()
522 add_executable(${PACKAGE} ${PFS} ${PCS} ${PS} ${PDS})
523 if(PELIBS OR PBLIBS OR EXEFLAGS)
524 target_link_libraries(${PACKAGE} ${BINLIBDIRS} ${PELIBSDIR} ${PELIBS} ${PBLIBS} ${EXEFLAGS})
525 endif(PELIBS OR PBLIBS OR EXEFLAGS)
526 add_dependencies(${MODULE}-all ${PACKAGE})
527 endif(ALIPROFILE STREQUAL "YES")
528
7531a2ac 529# AliMDC
530# ------------------------------
0742852a 531 if(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
7531a2ac 532
0742852a 533 add_executable(${PACKAGE}-static ${PFS} ${PCS} ${PS} ${PDS})
7531a2ac 534 set_target_properties(${PACKAGE}-static PROPERTIES OUTPUT_NAME alimdca)
535 add_custom_target( libAliMDC
536 COMMAND rm -rf ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a
537 COMMAND rm -rf junkmdc
538 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 539 WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
dad683d0 540 add_custom_target( root-static-libs
541 COMMAND make static
542 WORKING_DIRECTORY ${ROOTSYS} )
543
7531a2ac 544 add_dependencies(libAliMDC RAWDatabase-static STEERBase-static MDC-static ESD-static)
dad683d0 545 add_dependencies(${PACKAGE}-static libAliMDC root-static-libs)
7531a2ac 546 target_link_libraries(${PACKAGE}-static ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libAliMDC.a ${ROOTLIBDIR}/libRoot.a ${ROOTLIBDIR}/libfreetype.a ${ROOTLIBDIR}/libpcre.a -pthread -ldl -lcurses)
7531a2ac 547
24b052aa 548 install(TARGETS ${PACKAGE}-static RUNTIME DESTINATION bin/tgt_${ALICE_TARGET} COMPONENT MDC)
549 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 550 install(FILES ${PROJECT_SOURCE_DIR}/RAW/mdc.h DESTINATION include COMPONENT MDC)
551 set(CPACK_RPM_PACKAGE_SUMMARY "AliMDC static libraries")
552 set(CPACK_RPM_PACKAGE_NAME "alimdc")
553 set(CPACK_RPM_PACKAGE_VERSION "${ALIMDCVERSION}")
554 set(CPACK_RPM_PACKAGE_RELEASE "${ALIMDCRELEASE}")
e66e598e 555 set(CPACK_RPM_PACKAGE_LICENSE "License: CERN ALICE Off-line Group")
0742852a 556 set(CPACK_RPM_PACKAGE_VENDOR "ALICE Core Off-line Group")
557 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "AliMDC static libraries")
558 set(CPACK_RPM_PACKAGE_GROUP "Applications/Alice")
559 set(CPACK_RPM_PACKAGE_REQUIRES "glibc")
560 set(CPACK_PACKAGE_VERSION "1.0.0")
561 set(CPACK_PACKAGE_VERSION_MAJOR "1")
562 set(CPACK_PACKAGE_VERSION_MINOR "0")
563 set(CPACK_PACKAGE_VERSION_PATCH "0")
564 set(CPACK_PACKAGE_INSTALL_DIRECTORY "/opt/")
565 add_component_package(MDC alimdc-rpm)
566
567 endif(PACKAGE STREQUAL "alimdc" AND GENERATEPACKAGES)
7531a2ac 568
6db31708 569 list(FIND EXCLUDEMODULES ${MODULE} RESULT)
570 if(NOT RESULT STREQUAL "-1")
571 set_property(TARGET ${PACKAGE} PROPERTY EXCLUDE_FROM_ALL TRUE)
572 endif(NOT RESULT STREQUAL "-1")
573
574endmacro(ALICE_BuildExecutable)
575
576macro(ALICE_CopyHeaders)
577
e93f6949 578 if(EXPORT )
6db31708 579 set(HEADERS ${EXPORT})
e93f6949 580 set(_headersdep)
581 foreach(header ${HEADERS})
31e2a8d5 582 get_filename_component( header_name ${header} NAME )
583 add_custom_command(OUTPUT ${PEXPORTDEST}/${header_name}
584 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/${MODULE}/${header} ${PEXPORTDEST}/${header_name}
ae388d3b 585 DEPENDS ${CMAKE_SOURCE_DIR}/${MODULE}/${header})
31e2a8d5 586 list(APPEND _headersdep ${PEXPORTDEST}/${header_name})
6db31708 587 install(FILES ${header} DESTINATION include)
e93f6949 588 endforeach(header)
589 add_custom_target(${PACKAGE}-headers DEPENDS ${_headersdep})
590 add_dependencies(${PACKAGE} ${PACKAGE}-headers)
591 endif(EXPORT)
6db31708 592
593endmacro(ALICE_CopyHeaders)
594
595macro(ALICE_GenerateLinkDef)
0e67c40f 596 set(PCLASSES)
6db31708 597 foreach (class ${PCINTCLASSES})
598 get_filename_component(classname ${class} NAME)
2854d28f 599 # set(PCLASSES ${PCLASSES} "\\n#pragma link C++ class ${classname}+;")
600 set(PCLASSES ${PCLASSES} "${classname}")
6db31708 601 endforeach(class)
0e67c40f 602
603 add_custom_command(OUTPUT ${PDAL}
2854d28f 604 COMMAND sh ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh ${PCLASSES} > ${PDAL}
605 DEPENDS ${PCINTHDRS} ${CMAKE_SOURCE_DIR}/cmake/GenerateLinkDef.sh)
6db31708 606endmacro(ALICE_GenerateLinkDef)
0742852a 607
6a9e2760 608macro(ALICE_BuildPAR)
741bbd87 609
741bbd87 610 if(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
8948a174 611 set(PARSRCS)
3a8dbb31 612 foreach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
613 get_filename_component(srcdir ${file} PATH)
8948a174 614 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par
615 COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${srcdir}
616 COMMAND cp -pR ${file} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}
3a8dbb31 617 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
8948a174 618 list(APPEND PARSRCS ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/${file}-par)
3a8dbb31 619 endforeach(file ${SRCS} ${HDRS} ${FSRCS} ${DHDR})
8948a174 620
d9298a37 621 # message(STATUS "saveEINCLUDE=${saveEINCLUDE}")
8948a174 622 add_custom_target(${PACKAGE}.par
d9298a37 623 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
624 COMMAND cp -pR `root-config --etcdir`/Makefile.arch ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/Makefile.arch
8948a174 625 COMMAND cp -pR PROOF-INF.${PACKAGE} ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}/PROOF-INF
84d4333f 626# COMMAND cp -pR lib${PACKAGE}.pkg ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
8948a174 627 COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_CURRENT_BINARY_DIR} tar --exclude=.svn -czhf ${CMAKE_BINARY_DIR}/${PACKAGE}.par ${PACKAGE}
628 COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE}
629 COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --red --bold "${PACKAGE}.par has been created in ${CMAKE_BINARY_DIR}"
630 DEPENDS ${PARSRCS}
631 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} )
632
3a8dbb31 633
958d9d26 634 add_dependencies(${PACKAGE}.par ${SRCS} ${FSRCS} ${HDRS} ${DHDR})
6a9e2760 635 add_dependencies(par-all ${PACKAGE}.par)
3a8dbb31 636 add_dependencies(${MODULE}-par-all ${PACKAGE}.par)
637
638 add_custom_target(test-${PACKAGE}.par
639 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}."
640 COMMAND ${CMAKE_COMMAND} -E make_directory par-tmp
641 COMMAND ${CMAKE_COMMAND} -E chdir par-tmp tar xfz ../${PACKAGE}.par && ${CMAKE_COMMAND} -E chdir par-tmp/${PACKAGE} PROOF-INF/BUILD.sh
642 COMMAND ${CMAKE_COMMAND} -E remove_directory par-tmp
643 COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --green --bold "${PACKAGE}.par testing succeeded"
644 WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
645
958d9d26 646 add_dependencies(test-${PACKAGE}.par ${PACKAGE}.par)
3a8dbb31 647 add_dependencies(test-par-all test-${PACKAGE}.par)
648 add_dependencies(test-${MODULE}-par-all test-${PACKAGE}.par)
649
741bbd87 650 endif(EXISTS ${CMAKE_SOURCE_DIR}/${MODULE}/PROOF-INF.${PACKAGE})
651 # endif(EXISTS ${ALICE_ROOT}/${MODULE}/PROOF-INF.${PACKAGE})
652
6a9e2760 653endmacro(ALICE_BuildPAR)
0742852a 654