root/OpenSceneGraph/trunk/CMakeModules/UtilityMacros.cmake

Revision 9998, 7.1 kB (checked in by robert, 9 years ago)

From Philip Lowman, clean up of CMake files

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