root/OpenSceneGraph/trunk/CMakeModules/UtilityMacros.cmake @ 6561

Revision 6561, 6.3 kB (checked in by robert, 11 years ago)

Fixed tabbing

Line 
1
2INCLUDE(ListHandle)
3
4
5  MACRO(FILTER_OUT FILTERS INPUTS OUTPUT)
6       # Mimicks Gnu Make's $(filter-out) which removes elements
7       # from a list that match the pattern.
8       # Arguments:
9       #  FILTERS - list of patterns that need to be removed
10       #  INPUTS  - list of inputs that will be worked on
11       #  OUTPUT  - the filtered list to be returned
12       #
13       # Example:
14       #  SET(MYLIST this that and the other)
15       #  SET(FILTS this that)
16       #
17       #  FILTER_OUT("${FILTS}" "${MYLIST}" OUT)
18       #  MESSAGE("OUTPUT = ${OUT}")
19       #
20       # The output -
21       #   OUTPUT = and;the;other
22       #
23       SET(FOUT "")
24       FOREACH(INP ${INPUTS})
25           SET(FILTERED 0)
26           FOREACH(FILT ${FILTERS})
27               IF(${FILTERED} EQUAL 0)
28                   IF("${FILT}" STREQUAL "${INP}")
29                       SET(FILTERED 1)
30                   ENDIF("${FILT}" STREQUAL "${INP}")
31               ENDIF(${FILTERED} EQUAL 0)
32           ENDFOREACH(FILT ${FILTERS})
33           IF(${FILTERED} EQUAL 0)
34               SET(FOUT ${FOUT} ${INP})
35           ENDIF(${FILTERED} EQUAL 0)
36       ENDFOREACH(INP ${INPUTS})
37       SET(${OUTPUT} ${FOUT})
38   ENDMACRO(FILTER_OUT FILTERS INPUTS OUTPUT)
39
40
41   MACRO(GET_HEADERS_EXTENSIONLESS DIR GLOB_PATTERN OUTPUT)
42            FILE(GLOB TMP "${DIR}/${GLOB_PATTERN}" )
43      #FOREACH(F ${TMP})
44            #    MESSAGE(STATUS "header-->${F}<--")
45      #ENDFOREACH(F ${TMP})
46            FILTER_OUT("${DIR}/CVS" "${TMP}" TMP)
47            FILTER_OUT("${DIR}/cvs" "${TMP}" ${OUTPUT})
48            FILTER_OUT("${DIR}/.svn" "${TMP}" ${OUTPUT})
49   ENDMACRO(GET_HEADERS_EXTENSIONLESS DIR GLOB_PATTERN OUTPUT)
50   
51MACRO(ADD_DIRS_TO_ENV_VAR _VARNAME )
52 FOREACH(_ADD_PATH ${ARGN})
53    FILE(TO_NATIVE_PATH ${_ADD_PATH} _ADD_NATIVE)
54    #SET(_CURR_ENV_PATH $ENV{PATH})
55    #LIST(SET _CURR_ENV_PATH ${_ADD_PATH})
56    #SET(ENV{PATH} ${_CURR_ENV_PATH})${_FILE}
57    IF(WIN32)
58        SET(ENV{${_VARNAME}} "$ENV{${_VARNAME}};${_ADD_NATIVE}")
59    ELSE(WIN32)
60        SET(ENV{${_VARNAME}} "$ENV{${_VARNAME}}:${_ADD_NATIVE}")
61    ENDIF(WIN32)
62    #MESSAGE(" env ${_VARNAME} --->$ENV{${_VARNAME}}<---")
63 ENDFOREACH(_ADD_PATH)
64ENDMACRO(ADD_DIRS_TO_ENV_VAR _VARNAME )
65
66#---------------------------------------------------
67# MACRO CORRECT_PATH VAR PATH
68# corrects slashes in PATH to be cmake conformous ( / )
69# and puts result in VAR
70#---------------------------------------------------
71
72MACRO(CORRECT_PATH VAR PATH)
73    SET(${VAR} ${PATH})
74IF(WIN32)   
75    STRING(REGEX REPLACE "/" "\\\\" ${VAR} "${PATH}")
76ENDIF(WIN32)   
77ENDMACRO(CORRECT_PATH)
78
79MACRO(TARGET_LOCATIONS_SET_FILE FILE)
80 SET(ACCUM_FILE_TARGETS ${FILE})
81 FILE(WRITE ${ACCUM_FILE_TARGETS} "")
82ENDMACRO(TARGET_LOCATIONS_SET_FILE FILE)
83
84MACRO(TARGET_LOCATIONS_ACCUM TARGET_NAME)
85 IF(ACCUM_FILE_TARGETS)
86  IF(EXISTS ${ACCUM_FILE_TARGETS})
87    GET_TARGET_PROPERTY(_FILE_LOCATION ${TARGET_NAME} LOCATION)
88    FILE(APPEND ${ACCUM_FILE_TARGETS} "${_FILE_LOCATION};")
89    #SET(_TARGETS_LIST ${_TARGETS_LIST} "${_FILE_LOCATION}" CACHE INTERNAL "lista dll")
90    #MESSAGE("adding target -->${TARGET_NAME}<-- file -->${_FILE_LOCATION}<-- to list -->${_TARGETS_LIST}<--")
91    #SET(ACCUM_FILE_TARGETS ${ACCUM_FILE_TARGETS} ${_FILE_LOCATION})
92  ENDIF(EXISTS ${ACCUM_FILE_TARGETS})
93 ENDIF(ACCUM_FILE_TARGETS)
94ENDMACRO(TARGET_LOCATIONS_ACCUM TARGET_NAME)
95
96MACRO(TARGET_LOCATIONS_GET_LIST _VAR)
97 IF(ACCUM_FILE_TARGETS)
98  IF(EXISTS ${ACCUM_FILE_TARGETS})
99      FILE(READ ${ACCUM_FILE_TARGETS} ${_VAR})   
100  ENDIF(EXISTS ${ACCUM_FILE_TARGETS})
101 ENDIF(ACCUM_FILE_TARGETS)
102ENDMACRO(TARGET_LOCATIONS_GET_LIST _VAR)
103
104
105MACRO(FIND_DEPENDENCY DEPNAME INCLUDEFILE LIBRARY SEARCHPATHLIST)
106
107MESSAGE(STATUS "searching ${DEPNAME} -->${INCLUDEFILE}<-->${LIBRARY}<-->${SEARCHPATHLIST}<--")
108
109SET(MY_PATH_INCLUDE )
110SET(MY_PATH_LIB )
111SET(MY_PATH_BIN )
112
113FOREACH( MYPATH ${SEARCHPATHLIST} )
114    SET(MY_PATH_INCLUDE ${MY_PATH_INCLUDE} ${MYPATH}/include)
115    SET(MY_PATH_LIB ${MY_PATH_LIB} ${MYPATH}/lib)
116    SET(MY_PATH_BIN ${MY_PATH_BIN} ${MYPATH}/bin)
117ENDFOREACH( MYPATH ${SEARCHPATHLIST} )
118
119SET(MYLIBRARY "${LIBRARY}")
120SEPARATE_ARGUMENTS(MYLIBRARY)
121
122#MESSAGE( " include paths: -->${MY_PATH_INCLUDE}<--")
123
124#MESSAGE( " ${DEPNAME}_INCLUDE_DIR --> ${${DEPNAME}_INCLUDE_DIR}<--")
125   
126FIND_PATH("${DEPNAME}_INCLUDE_DIR" ${INCLUDEFILE}
127  ${MY_PATH_INCLUDE}
128)
129MARK_AS_ADVANCED("${DEPNAME}_INCLUDE_DIR")
130#MESSAGE( " ${DEPNAME}_INCLUDE_DIR --> ${${DEPNAME}_INCLUDE_DIR}<--")
131
132FIND_LIBRARY("${DEPNAME}_LIBRARY"
133    NAMES ${MYLIBRARY}
134  PATHS ${MY_PATH_LIB}
135)
136IF(${DEPNAME}_LIBRARY)
137    GET_FILENAME_COMPONENT(MYLIBNAME ${${DEPNAME}_LIBRARY} NAME_WE)
138    GET_FILENAME_COMPONENT(MYBINPATH ${${DEPNAME}_LIBRARY} PATH)
139    GET_FILENAME_COMPONENT(MYBINPATH ${MYBINPATH} PATH)
140    SET(MYBINPATH "${MYBINPATH}/bin")
141    IF(EXISTS ${MYBINPATH})
142        SET(MYFOUND 0)
143        FOREACH(MYPATH ${MY_ACCUM_BINARY_DEP})
144            IF(MYPATH MATCHES ${MYBINPATH})
145                SET(MYFOUND 1)
146                #MESSAGE("found -->${MYPATH}<-->${MYBINPATH}<--")
147            ENDIF(MYPATH MATCHES ${MYBINPATH})
148        ENDFOREACH(MYPATH )
149        IF(MYFOUND EQUAL 0)
150            SET(MY_ACCUM_BINARY_DEP ${MY_ACCUM_BINARY_DEP} ${MYBINPATH})
151        ENDIF(MYFOUND EQUAL 0)
152    ENDIF(EXISTS ${MYBINPATH})
153    #MESSAGE("${DEPNAME}_BINDEP searching -->${MYLIBNAME}${CMAKE_SHARED_MODULE_SUFFIX}<--in-->${MY_PATH_BIN}<--")
154#    FIND_FILE("${DEPNAME}_BINDEP"
155#        ${MYLIBNAME}${CMAKE_SHARED_MODULE_SUFFIX}
156#      PATHS ${MY_PATH_BIN}
157#    )
158#    FIND_LIBRARY("${DEPNAME}_BINDEP"
159#        NAMES ${MYLIBRARY}
160#      PATHS ${MY_PATH_BIN}
161#    )
162ENDIF(${DEPNAME}_LIBRARY)
163MARK_AS_ADVANCED("${DEPNAME}_LIBRARY")
164#MESSAGE( " ${DEPNAME}_LIBRARY --> ${${DEPNAME}_LIBRARY}<--")
165IF(${DEPNAME}_INCLUDE_DIR)
166  IF(${DEPNAME}_LIBRARY)
167    SET( ${DEPNAME}_FOUND "YES" )
168    SET( ${DEPNAME}_LIBRARIES ${${DEPNAME}_LIBRARY} )
169  ENDIF(${DEPNAME}_LIBRARY)
170ENDIF(${DEPNAME}_INCLUDE_DIR)
171ENDMACRO(FIND_DEPENDENCY DEPNAME INCLUDEFILE LIBRARY SEARCHPATHLIST)
172
173#SET(MACRO_MESSAGE_DEBUG TRUE)
174MACRO(MACRO_MESSAGE MYTEXT)
175    IF(MACRO_MESSAGE_DEBUG)
176        MESSAGE("in file -->${CMAKE_CURRENT_LIST_FILE}<-- line -->${CMAKE_CURRENT_LIST_LINE}<-- message  ${MYTEXT}")
177    ELSE(MACRO_MESSAGE_DEBUG)
178        MESSAGE(STATUS "in file -->${CMAKE_CURRENT_LIST_FILE}<-- line -->${CMAKE_CURRENT_LIST_LINE}<-- message  ${MYTEXT}")
179    ENDIF(MACRO_MESSAGE_DEBUG)
180ENDMACRO(MACRO_MESSAGE MYTEXT)
Note: See TracBrowser for help on using the browser.