3 ###########################################
7 ###########################################
9 ###############################################################
11 # Exchange file extention of LIST from
12 # FILE_EXT1 to FILE_EXT2 and assign the
13 # newly created list to OUTVAR. The input
14 # list LIST is not changed at all
15 # Ex: CHANGE_FILE_EXTENSION(*.cxx *.h TRD_HEADERS "${TRD_SRCS}")
17 ################################################################
19 MACRO (CHANGE_FILE_EXTENSION FILE_EXT1 FILE_EXT2 OUTVAR LIST)
23 IF (${FILE_EXT1} MATCHES "^[*][.]+.*$")
24 STRING(REGEX REPLACE "^[*]+([.].*)$" "\\1" FILE_EXT1_NEW ${FILE_EXT1})
25 ENDIF (${FILE_EXT1} MATCHES "^[*][.]+.*$")
27 IF (${FILE_EXT2} MATCHES "^[*][.]+.*$")
28 STRING(REGEX REPLACE "^[*]+([.].*)" "\\1" FILE_EXT2_NEW ${FILE_EXT2})
29 ENDIF (${FILE_EXT2} MATCHES "^[*][.]+.*$")
31 foreach (_current_FILE ${LIST})
33 # GET_FILENAME_COMPONENT(name_wo_path ${_current_FILE}
37 STRING(REGEX REPLACE "^(.*)${FILE_EXT1_NEW}$" "\\1${FILE_EXT2_NEW}" test ${_current_FILE})
38 SET (BLA ${BLA} ${test})
40 endforeach (_current_FILE ${LIST})
42 SET (${OUTVAR} ${BLA})
46 ENDMACRO (CHANGE_FILE_EXTENSION)
48 ######################################################
50 # Macro get string with a colon seperated string of
51 # pathes or any other colon sperated list.
52 # First the string is seperated and the entries are
54 # Loop over the list and searches for the occurence
55 # of keywords which are provided as a list.
56 # If the keyword occurs this path (entry) is
57 # deleted from the list. Returns the list of pathes
58 # (entries) wich survives the loop.
60 # PATH: colon separated string of pathes or other
62 # LIST_OF_KEYWORDS: list of the keywords which
63 # should be excluded in the output
64 # OUTVAR: name of the variable which should be filled
65 # with the resulting output list
67 ######################################################
69 MACRO (CLEAN_PATH_LIST PATH LIST_OF_KEYWORDS OUTVAR)
73 STRING(REGEX MATCHALL "[^:]+" PATH1 ${PATH})
75 FOREACH(_current_PATH ${PATH1})
77 SET(KEYWORD_FOUND FALSE)
79 FOREACH(_current_KEYWORD ${LIST_OF_KEYWORDS})
81 IF (${_current_PATH} MATCHES "${_current_KEYWORD}")
82 SET(KEYWORD_FOUND TRUE)
83 ENDIF (${_current_PATH} MATCHES "${_current_KEYWORD}")
85 ENDFOREACH(_current_KEYWORD ${LIST_OF_KEYWORDS})
87 IF (NOT KEYWORD_FOUND)
88 SET(BLA ${BLA} ${_current_PATH})
89 ENDIF (NOT KEYWORD_FOUND)
91 ENDFOREACH(_current_PATH ${PATH1})
93 UNIQUE(${OUTVAR} "${BLA}")
95 ENDMACRO (CLEAN_PATH_LIST)
97 ##########################################################
99 # The macro checks if the user wants to build the project
100 # in the source directory and if so stop the execution
101 # of cmake with an error message.
103 ##########################################################
105 MACRO (CHECK_OUT_OF_SOURCE_BUILD)
107 STRING(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" insource)
109 FILE(REMOVE_RECURSE ${CMAKE_SOURCE_DIR}/Testing)
110 FILE(REMOVE ${CMAKE_SOURCE_DIR}/DartConfiguration.tcl)
111 MESSAGE(FATAL_ERROR "FAIRROOT should be installed as an out of source build, to keep the source directory clean. Please create a extra build directory and run the command 'cmake path_to_source_dir' in this newly created directory. You have also to delete the directory CMakeFiles and the file CMakeCache.txt in the source directory. Otherwise cmake will complain even if you run it from an out-of-source directory.")
114 ENDMACRO (CHECK_OUT_OF_SOURCE_BUILD)
116 MACRO(UNIQUE var_name list)
118 #######################################################################
119 # Make the given list have only one instance of each unique element and
120 # store it in var_name.
121 #######################################################################
125 STRING(REGEX REPLACE "[+]" "\\\\+" l1 ${l})
126 IF(NOT "${unique_tmp}" MATCHES "(^|;)${l1}(;|$)")
127 SET(unique_tmp ${unique_tmp} ${l})
128 ENDIF(NOT "${unique_tmp}" MATCHES "(^|;)${l1}(;|$)")
130 SET(${var_name} ${unique_tmp})
133 MACRO(CHECK_CMAKE_VERSION)
135 #################################################################
136 #Check if CMake has at least version 2.4.3
137 # This has to be done before anything else, because some commands
138 # are not known in older versions.
139 #################################################################
141 EXEC_PROGRAM( cmake ARGS "--version" OUTPUT_VARIABLE CMAKE_VERSION )
142 IF (${CMAKE_MAJOR_VERSION} LESS 2 )
143 MESSAGE("You are using CMake version ${CMAKE_VERSION} .")
144 MESSAGE( FATAL_ERROR "This Cmake version is to old. At leasts version 2.4.3 is needed.")
145 ENDIF (${CMAKE_MAJOR_VERSION} LESS 2 )
146 IF (${CMAKE_MINOR_VERSION} LESS 4 )
147 MESSAGE("You are using CMake version ${CMAKE_VERSION} .")
148 MESSAGE( FATAL_ERROR "This Cmake version is to old. At leasts version 2.4.3 is needed.")
149 ENDIF (${CMAKE_MINOR_VERSION} LESS 4 )
150 IF (${CMAKE_PATCH_VERSION} LESS 3 )
151 MESSAGE("You are using CMake version ${CMAKE_VERSION} .")
152 MESSAGE( FATAL_ERROR "This Cmake version is to old. At leasts version 2.4.3 is needed.")
153 ENDIF (${CMAKE_PATCH_VERSION} LESS 3 )
155 ENDMACRO(CHECK_CMAKE_VERSION)
159 #################################################################
160 # Check if /misc/cbmsoft/config exist, because than we are at GSI
161 # If we are not at GSI some of the macros may not work.
162 #################################################################
164 SET(GSI GSI-NOTFOUND)
165 FIND_PATH(GSI NAMES config PATHS
170 EXEC_PROGRAM(uname ARGS "-m" OUTPUT_VARIABLE Machine)
171 # SET(Machine ${CMAKE_SYSTEM_PROCESSOR})
172 #${CMAKE_SYSTEM_PROCESSOR} is not set correctly on 64bit
173 #Debian Etch, so use workaround
176 MESSAGE("-- You're using the GSI installation of the external packages.")
187 IF(DEFINED ENV{PATH})
188 CLEAN_PATH_LIST("$ENV{PATH}" "${KEYWORDS}" PATH)
189 #MESSAGE ("PATH: ${PATH}")
190 #set(ENV{PATH} ${PATH})
191 ENDIF(DEFINED ENV{PATH})
194 # Create a clean LD_LIBRARY_PATH without any pathes to libraries set
196 IF(DEFINED ENV{LD_LIBRARY_PATH})
197 SET(KEYWORDS ${KEYWORDS} ${CMAKE_BINARY_DIR})
198 CLEAN_PATH_LIST("$ENV{LD_LIBRARY_PATH}" "${KEYWORDS}" LD_LIBRARY_PATH)
199 #MESSAGE("LD_LIBRARY_PATH: ${LD_LIBRARY_PATH}")
200 ENDIF(DEFINED ENV{LD_LIBRARY_PATH})
202 # Check if you're on an 32 or 64 bit environment
203 IF(${Machine} MATCHES "i686" OR
204 ${Machine} MATCHES "i386" )
205 MESSAGE("-- This is an 32 bit machine")
206 SET(GSI_SIMPATH /misc/cbmsoft/Debian3.1/new/)
207 ELSE(${Machine} MATCHES "i686" OR
208 ${Machine} MATCHES "i386" )
209 IF(${Machine} MATCHES "x86_64")
210 MESSAGE("-- This is an 64 bit machine")
211 SET(GSI_SIMPATH /misc/cbmsoft/Debian64/new/)
212 ELSE(${Machine} MATCHES "x86_64")
213 MESSAGE(FATAL_ERROR "This is a UNIX machine wich is neither 32 nor 64 bit. Don't know what to do, so break. ")
214 ENDIF(${Machine} MATCHES "x86_64")
215 ENDIF(${Machine} MATCHES "i686" OR
216 ${Machine} MATCHES "i386" )
219 MESSAGE("-- You're not using the GSI installation of the external packages.")
220 MESSAGE("-- If any problems occur this can be due to the fact that the macros")
221 MESSAGE("-- were mostly tested at GSI. If you find any problems please contact")
222 MESSAGE("-- f.uhlig@gsi.de")
223 STRING(REGEX MATCHALL "[^:]+" PATH $ENV{PATH})
224 #MESSAGE("PATH: ${PATH}")
229 MACRO(CHECK_EXTERNAL_PACKAGES_INSTALLATION)
231 #############################################################
232 # Check if cmake can find the root of the simulation packages
233 # check if the installation is as at GSI
234 # This is needed later on to check for the required packages
235 # Should be done in a better way that you find the packages
236 # independent of the way where they are installed
237 #############################################################
239 SET(SIMPATH SIMPATH-NOTFOUND)
240 SET(SIMPATH1 SIMPATH1-NOTFOUND)
241 SET(SIMPATH2 SIMPATH2-NOTFOUND)
242 SET(SIMPATH3 SIMPATH3-NOTFOUND)
243 SET(SIMPATH4 SIMPATH4-NOTFOUND)
245 FIND_PATH(SIMPATH1 NAMES transport PATHS
250 FIND_PATH(SIMPATH2 NAMES tools PATHS
255 FIND_PATH(SIMPATH3 NAMES cern PATHS
260 FIND_PATH(SIMPATH4 NAMES generators PATHS
266 IF(SIMPATH1 AND SIMPATH2 AND SIMPATH3 AND SIMPATH4)
267 SET(SIMPATH ${SIMPATH1})
268 ENDIF(SIMPATH1 AND SIMPATH2 AND SIMPATH3 AND SIMPATH4)
271 IF (${SIMPATH} MATCHES "SIMPATH-NOTFOUND")
272 MESSAGE( FATAL_ERROR "Could not find the root of the simulation software. Please define SIMPATH as the path to the root of your instalation of simulation software.")
273 ELSE (${SIMPATH} MATCHES "SIMPATH-NOTFOUND")
274 MESSAGE( STATUS "Found root of the simulation software at ${SIMPATH}")
275 SET( ENV{SIMPATH} ${SIMPATH})
276 SET(ROOTSYS ${SIMPATH}/tools/root)
277 SET( ENV{ROOTSYS} ${SIMPATH}/tools/root)
278 ENDIF (${SIMPATH} MATCHES "SIMPATH-NOTFOUND")
280 ENDMACRO(CHECK_EXTERNAL_PACKAGES_INSTALLATION)
282 ###################################################
283 # Creates a variable which stores the intersection
285 ####################################################
287 MACRO(INTERSECTION var_name list1 list2)
288 # Store the intersection between the two given lists in var_name.
289 SET(intersect_tmp "")
291 IF("${list2}" MATCHES "(^|;)${l}(;|$)")
292 SET(intersect_tmp ${intersect_tmp} ${l})
293 ENDIF("${list2}" MATCHES "(^|;)${l}(;|$)")
295 SET(${var_name} ${intersect_tmp})
296 ENDMACRO(INTERSECTION)
298 MACRO(REMOVE_FROM_LIST var_name list1 list2)
299 # Remove elements in list2 from list1 and store the result in var_name.
302 IF(NOT "${list2}" MATCHES "(^|;)${l}(;|$)")
303 SET(filter_tmp ${filter_tmp} ${l})
304 ENDIF(NOT "${list2}" MATCHES "(^|;)${l}(;|$)")
306 SET(${var_name} ${filter_tmp})
307 ENDMACRO(REMOVE_FROM_LIST)