]> git.uio.no Git - u/mrichter/AliRoot.git/blob - cmake/CMakeALICE.cmake
4ca1ae1d4facac7da850027d7872e03abbd62f66
[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
29     # Creating the INCLUDE path for cint/cling
30     foreach( dir ${DINCDIRS})
31         set(INCLUDE_PATH -I${dir} ${INCLUDE_PATH})
32     endforeach()
33     
34     # Generate the dictionary
35 #    message(STATUS "Generating dictionary ${DNAME} for ${LDNAME}")
36     
37 #    message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx")
38 #    message(STATUS "${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.h")
39 #    message(STATUS "bbb${INCLUDE_PATH}bbb")
40 #    message(STATUS "${DHDRS} ${LDNAME}")
41 #    message(STATUS "${CMAKE_CURRENT_SOURCE_DIR}")
42     
43     # Get the definitions from the directory to be sent to CINT
44     get_directory_property(tmpdirdefs DEFINITIONS)
45     string(REPLACE " " ";" tmpdirdefs "${tmpdirdefs}")
46
47     if (ROOT_VERSION_MAJOR LESS 6)
48     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.h
49                        COMMAND LD_LIBRARY_PATH=${ROOT_LIBDIR}:$ENV{LD_LIBRARY_PATH} ${ROOT_CINT}
50                        ARGS -f ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx -c -p 
51                        ${tmpdirdefs} ${INCLUDE_PATH} 
52                        ${DHDRS} ${LDNAME}
53                        DEPENDS ${DHDRS} ${LDNAME} ${ROOT_CINT}
54                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
55                       )
56     else (ROOT_VERSION_MAJOR LESS 6)
57     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib${DNAME}.rootmap ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx
58                        COMMAND
59                          LD_LIBRARY_PATH=${ROOT_LIBDIR}:$ENV{LD_LIBRARY_PATH} ${ROOT_CINT}
60                        ARGS
61                          -f ${CMAKE_CURRENT_BINARY_DIR}/G__${DNAME}.cxx
62                          -rmf ${CMAKE_CURRENT_BINARY_DIR}/lib${DNAME}.rootmap -rml lib${DNAME}
63                          ${tmpdirdefs} ${INCLUDE_PATH} ${DHDRS} ${LDNAME}
64                        DEPENDS
65                          ${DHDRS} ${LDNAME} ${ROOT_CINT}
66                        WORKING_DIRECTORY
67                          ${CMAKE_CURRENT_BINARY_DIR}
68                       )
69     endif (ROOT_VERSION_MAJOR LESS 6)
70
71 endmacro(generate_dictionary)
72
73 # Generate the ROOTmap files
74 # @LIBNAME - library name: libAnalysis.so -> Analysis.rootmap
75 # @LIBDEPS - library dependencies
76 # @LINKDEF - LinkDef header
77 macro(generate_rootmap LIBNAME LIBDEPS LINKDEF)
78 #    message(STATUS "LIBNAME = ${LIBNAME}")
79 #    message(STATUS "LIBDEPS = ${LIBDEPS}")
80 #    message(STATUS "LINKDEF = ${LINKDEF}")
81 #    message(STATUS "ROOT_LIBMAP=${ROOT_LIBMAP}")
82
83 if (ROOT_VERSION_MAJOR LESS 6)
84
85     set(LOCAL_DEPS)
86     foreach(file ${LIBDEPS})
87         get_filename_component(ext ${file} EXT)
88         if(ext)
89             set(LOCAL_DEPS ${LOCAL_DEPS} ${file})
90         else()
91             set(LOCAL_DEPS ${LOCAL_DEPS} lib${file})
92         endif()
93     endforeach()
94
95 #    message(STATUS "Generating ROOT map for ${LIBNAME}")
96     add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap
97                        COMMAND LD_LIBRARY_PATH=${ROOT_LIBDIR}:$ENV{LD_LIBRARY_PATH} ${ROOT_LIBMAP}
98                        ARGS -o ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap -l lib${LIBNAME} -d ${LOCAL_DEPS} -c ${LINKDEF}
99                        DEPENDS ${LIBNAME}
100                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
101                       )
102     add_custom_target(lib${LIBNAME}.rootmap ALL DEPENDS  ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap)
103     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBNAME}.rootmap DESTINATION lib)
104
105 endif (ROOT_VERSION_MAJOR LESS 6)
106
107 endmacro(generate_rootmap)
108
109 #########################
110 # Static utilities
111 #########################
112
113 # Generate the static dependecies from dynamic list
114 # @ shared_list - list of shared libraries
115 # @ static_list - the name of the variable that will contain the list of static libraries
116 macro(generate_static_dependencies shared_list static_list)
117     set(static_list_tmp "")
118     foreach(shared_lib ${shared_list})
119         set(static_list_tmp ${static_list_tmp} "${shared_lib}-static")
120     endforeach()
121     
122     # create the variable with the name received by the macro
123     set(${static_list} ${static_list_tmp})
124     # set the scope to parent in order to be visible in the parent
125     set(${static_list} PARENT_SCOPE)
126 endmacro(generate_static_dependencies)
127
128 #########################
129 # DA utilities
130 #########################
131
132 # Extract the first comment from a DA file
133 # Find the position for first /* and */ and extract the substring
134 macro(getDAdescription _detector _daname)
135     # Reading the file into a string
136     file(READ "${_detector}${_daname}da.cxx" tmpinfo)
137     
138     # Find the first occurance of /* */
139     string(FIND "${tmpinfo}" "/*" _first_position)
140     string(FIND "${tmpinfo}" "*/" _second_position)
141     
142     # Adding and removing 2 characters to remove /* */
143     math(EXPR _first_position ${_first_position}+2)
144     math(EXPR _second_position ${_second_position}-2)
145     
146     # Generating the length of the comment in order to take out the description
147     math(EXPR _desc_length ${_second_position}-${_first_position})
148     
149     if(${_desc_length} EQUAL 0 OR ${_desc_length} LESS 0)
150         message(FATAL_ERROR "{_detector}${_daname}da.cxx does not contain a description. Please add the description as the first /*comment*/ in the file")
151     else()
152         string(SUBSTRING "${tmpinfo}" ${_first_position}  ${_second_position} _da_description)
153         string(STRIP "${_da_description}" _da_description)
154         
155         # The variable can be accesed by the parent
156         set(RPM_DESCRIPTION ${_da_description})
157     endif()
158 endmacro()
159
160 # Set the compilation flags
161 macro(setDAflags)
162     # DIM
163     link_directories(${DIMDIR}/${ODIR})
164
165     #daqDA flags
166     include_directories(${daqDA})
167     link_directories(${daqDA})
168
169     # AMORE definitions
170     add_definitions(${AMORE_DEFINITIONS})
171     include_directories(${AMORE_INCLUDE_DIR})
172
173 endmacro()
174
175 # Generate a DA
176 macro(generateDA DETECTOR ALGORITHM STATIC_DEPENDENCIES)
177     setDAflags()
178
179     # Generating the DA executable
180     add_executable(${DETECTOR}${ALGORITHM}da.exe ${DETECTOR}${ALGORITHM}da.cxx) #
181
182     # DA flags and linking information
183     set(MODULE_COMPILE_FLAGS)
184     set(MODULE_LINK_FLAGS)
185
186     target_link_libraries(${DETECTOR}${ALGORITHM}da.exe ${STATIC_DEPENDENCIES} ${AMORE_AUXLIBS} daqDA ${DATE_MONLIBRARIES} ${DATE_RCPROXYLIBRARIES} Root RootExtra) # 1
187
188     # different flags
189     set(MODULE_COMPILE_FLAGS "  ${DATE_CFLAGS} ${AMORE_CFLAGS}")
190     set(MODULE_LINK_FLAGS "${DATE_LDFLAGS} ${AMORE_STATICLIBS}")
191
192     set_target_properties(${DETECTOR}${ALGORITHM}da.exe PROPERTIES COMPILE_FLAGS ${MODULE_COMPILE_FLAGS})
193     set_target_properties(${DETECTOR}${ALGORITHM}da.exe PROPERTIES LINK_FLAGS "${MODULE_LINK_FLAGS}")
194
195     # Installation
196     install(TARGETS ${DETECTOR}${ALGORITHM}da.exe RUNTIME DESTINATION bin)
197     
198     if(DARPM)
199         createDArpm("${DETECTOR}" "${ALGORITHM}")
200     endif(DARPM)
201 endmacro()
202
203 # DA rpm creation
204 macro(createDArpm DETECTOR ALGORITHM)
205     getDAdescription("${DETECTOR}" "${ALGORITHM}")
206
207     set(DA_EXECUTABLE "${DETECTOR}${ALGORITHM}da.exe")
208     set(DETECTOR "${DETECTOR}")
209     set(ALGORITHM "${ALGORITHM}")
210     set(RPM_DESCRIPTION ${RPM_DESCRIPTION})
211     
212     if(ALGORITHM STREQUAL "")
213         set(_ALGORITHM "none")
214         set(DA_PREFIX "opt/daqDA-${DETECTOR}")
215         set(DA_NAME "daqDA-${DETECTOR}")
216     else()
217         set(_ALGORITHM ${ALGORITHM})
218         set(DA_PREFIX "opt/daqDA-${DETECTOR}-${ALGORITHM}")
219         set(DA_NAME "daqDA-${DETECTOR}-${ALGORITHM}")
220     endif()
221
222     configure_file("${AliRoot_SOURCE_DIR}/cmake/da.spec.in" "${_ALGORITHM}-da.spec" @ONLY)
223
224     add_custom_command(TARGET ${DETECTOR}${ALGORITHM}da.exe POST_BUILD
225                        COMMAND mkdir ARGS -p da-${_ALGORITHM}-rpm/root/${DA_PREFIX}/
226                        COMMAND cp ARGS ${DETECTOR}${ALGORITHM}da.exe da-${_ALGORITHM}-rpm/root/${DA_PREFIX}/
227                        COMMAND rpmbuild ARGS --verbose --define "_topdir ${CMAKE_CURRENT_BINARY_DIR}/da-${_ALGORITHM}-rpm" --define "%buildroot ${CMAKE_CURRENT_BINARY_DIR}/da-${_ALGORITHM}-rpm/root" -bb ${_ALGORITHM}-da.spec
228                        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} VERBATIM
229                        COMMENT "RPM creation for ${DETECTOR}-${_ALGORITHM}"
230     )
231     
232     # make clean will remove also the rpm folder
233     # Retrive the current list of file to be deleted - set_directory_property is overwriting, not adding to the list
234     get_directory_property(_clean_files ADDITIONAL_MAKE_CLEAN_FILES)
235     set(_clean_files da-${_ALGORITHM}-rpm  ${_clean_files})
236     set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${_clean_files}")
237     
238     # install RPM into $CMAKE_INSTALL_PREFIX/darpms
239     install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/da-${_ALGORITHM}-rpm/RPMS/ DESTINATION darpms PATTERN "\\.rpm")
240 endmacro()