Create DA RPM
[u/mrichter/AliRoot.git] / cmake / CMakeALICE.cmake
1 # **************************************************************************
2 # * Copyright(c) 1998-2014, ALICE Experiment at CERN, All rights reserved. *
3 # *                                                                        *
4 # * Author: The ALICE Off-line Project.                                    *
5 # * Contributors are mentioned in the code where appropriate.              *
6 # *                                                                        *
7 # * Permission to use, copy, modify and distribute this software and its   *
8 # * documentation strictly for non-commercial purposes is hereby granted   *
9 # * without fee, provided that the above copyright notice appears in all   *
10 # * copies and that both the copyright notice and this permission notice   *
11 # * appear in the supporting documentation. The authors make no claims     *
12 # * about the suitability of this software for any purpose. It is          *
13 # * provided "as is" without express or implied warranty.                  *
14 # **************************************************************************
15
16 # General purpose functions
17
18 #########################
19 # ROOT utilities
20 #########################
21
22 # Generation of the dictionaries
23 # @DNAME  Dictionary name
24 # @LDNAME LinkDef file name, ex: LinkDef.h
25 # @DHDRS  Dictionary headers
26 # @DINCDIR Include folders that need to be passed to cint/cling
27 macro(generate_dictionary DNAME LDNAME DHDRS DINCDIRS)
28     # Creating the INCLUDE path for cint/cling
29     foreach( dir ${DINCDIRS})
30         set(INCLUDE_PATH -I${dir} ${INCLUDE_PATH})
31     endforeach()
32     
33     # Generate the dictionary
34 #    message(STATUS "Generating dictionary ${DNAME} for ${LDNAME}")
35     
36 #    message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx")
37 #    message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.h")
38 #    message(STATUS "bbb${INCLUDE_PATH}bbb")
39 #    message(STATUS "${DHDRS} ${LDNAME}")
40 #    message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}")
41     
42     # Get the definitions from the directory to be sent to CINT
43     get_directory_property(tmpdirdefs DEFINITIONS)
44     string(REPLACE " " ";" tmpdirdefs ${tmpdirdefs})
45
46     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.h
47                        COMMAND LD_LIBRARY_PATH=${ROOT_LIBDIR}:$ENV{LD_LIBRARY_PATH} ${ROOT_CINT}
48                        ARGS -f ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx -c -p 
49                        ${tmpdirdefs} ${INCLUDE_PATH} 
50                        ${DHDRS} ${LDNAME}
51                        DEPENDS ${DHDRS} ${LDNAME} ${ROOT_CINT}
52                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
53                       )
54 endmacro(generate_dictionary)
55
56 # Generate the ROOTmap files
57 # @LIBNAME - library name: libAnalysis.so -> Analysis.rootmap
58 # @LIBDEPS - library dependencies
59 # @LINKDEF - LinkDef header
60 macro(generate_rootmap LIBNAME LIBDEPS LINKDEF)
61 #    message(STATUS "LIBNAME = ${LIBNAME}")
62 #    message(STATUS "LIBDEPS = ${LIBDEPS}")
63 #    message(STATUS "LINKDEF = ${LINKDEF}")
64 #    message(STATUS "ROOT_LIBMAP=${ROOT_LIBMAP}")
65
66     set(LOCAL_DEPS)
67     foreach(file ${LIBDEPS})
68         get_filename_component(ext ${file} EXT)
69         if(ext)
70             set(LOCAL_DEPS ${LOCAL_DEPS} ${file})
71         else()
72             set(LOCAL_DEPS ${LOCAL_DEPS} lib${file}.so)
73         endif()
74     endforeach()
75
76 #    message(STATUS "Generating ROOT map for ${LIBNAME}")
77     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap
78                        COMMAND LD_LIBRARY_PATH=${ROOT_LIBDIR}:$ENV{LD_LIBRARY_PATH} ${ROOT_LIBMAP}
79                        ARGS -o ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap -l lib${LIBNAME}.so -d ${LOCAL_DEPS} -c ${LINKDEF}
80                        DEPENDS ${LIBNAME}
81                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
82                       )
83     add_custom_target(lib${LIBNAME}.rootmap ALL DEPENDS  ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap)
84     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap DESTINATION lib)
85     
86 endmacro(generate_rootmap)
87
88 #########################
89 # Static utilities
90 #########################
91
92 # Generate the static dependecies from dynamic list
93 # @ shared_list - list of shared libraries
94 # @ static_list - the name of the variable that will contain the list of static libraries
95 macro(generate_static_dependencies shared_list static_list)
96     set(static_list_tmp "")
97     foreach(shared_lib ${shared_list})
98         set(static_list_tmp ${static_list_tmp} "${shared_lib}-static")
99     endforeach()
100     
101     # create the variable with the name received by the macro
102     set(${static_list} ${static_list_tmp})
103     # set the scope to parent in order to be visible in the parent
104     set(${static_list} PARENT_SCOPE)
105 endmacro(generate_static_dependencies)
106
107 #########################
108 # DA utilities
109 #########################
110 # Extract DA information to be inserted into the rpm
111 function(getDAinfo _info _detector _daname info)
112     file(STRINGS "${_detector}${_daname}da.cxx" tmpinfo REGEX "${info}:")
113     string(REPLACE "${info}:\ " "" tmpinfo ${tmpinfo})
114     set(${_info} ${tmpinfo} PARENT_SCOPE)
115 endfunction()
116
117 # DA rpm creation
118 macro(createDArpm DETECTOR ALGORITHM)
119     getDAinfo(contact "${DETECTOR}" "${ALGORITHM}" "Contact")
120     getDAinfo(link "${DETECTOR}" "${ALGORITHM}" "Link")
121     getDAinfo(refrun "${DETECTOR}" "${ALGORITHM}" "Reference Run")
122     getDAinfo(runtype "${DETECTOR}" "${ALGORITHM}" "Run Type")
123     getDAinfo(datype "${DETECTOR}" "${ALGORITHM}" "DA Type")
124     getDAinfo(evennr "${DETECTOR}" "${ALGORITHM}" "Number of events needed")
125     getDAinfo(ifiles "${DETECTOR}" "${ALGORITHM}" "Input Files")
126     getDAinfo(ofiles "${DETECTOR}" "${ALGORITHM}" "Output Files")
127     getDAinfo(trigger "${DETECTOR}" "${ALGORITHM}" "Trigger types used")
128     set(RPM_DESCRIPTION "contact: ${contact}
129 Link:${link}
130 Reference run:${refrun}
131 Run Type:${runtype}
132 DA Type:${datype}
133 Number of events needed: ${evennr}
134 Input Files:${ifiles}
135 Output Files:${ofiles}
136 Trigger types used:${trigger}")
137
138     set(DA_EXECUTABLE "${DETECTOR}${ALGORITHM}da")
139     set(DETECTOR ${DETECTOR})
140     set(ALGORITHM ${ALGORITHM})
141     configure_file("${AliRoot_SOURCE_DIR}/cmake/da.spec.in" "${CMAKE_CURRENT_BINARY_DIR}/${ALGORITHM}-da.spec" @ONLY)
142
143     add_custom_command(TARGET ${DETECTOR}${ALGORITHM}da POST_BUILD
144                        COMMAND mkdir ARGS -p da-${ALGORITHM}-rpm/opt/daqDA-${DETECTOR}-${ALGORITHM}/
145                        COMMAND cp ARGS ${DETECTOR}${ALGORITHM}da da-${ALGORITHM}-rpm/opt/daqDA-${DETECTOR}-${ALGORITHM}/
146                        COMMAND rpmbuild ARGS --verbose --define "_topdir ${CMAKE_CURRENT_BINARY_DIR}" --define "%buildroot ${CMAKE_CURRENT_BINARY_DIR}/da-${ALGORITHM}-rpm" -bb ${ALGORITHM}-da.spec
147                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
148     )
149 endmacro()