Functions.cmake 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. FUNCTION(AUTO_SOURCES RETURN_VALUE PATTERN SOURCE_SUBDIRS)
  19. IF ("${SOURCE_SUBDIRS}" STREQUAL "RECURSE")
  20. SET(PATH ".")
  21. IF (${ARGC} EQUAL 4)
  22. LIST(GET ARGV 3 PATH)
  23. ENDIF ()
  24. ENDIF()
  25. IF ("${SOURCE_SUBDIRS}" STREQUAL "RECURSE")
  26. UNSET(${RETURN_VALUE})
  27. FILE(GLOB SUBDIR_FILES "${PATH}/${PATTERN}")
  28. LIST(APPEND ${RETURN_VALUE} ${SUBDIR_FILES})
  29. FILE(GLOB SUBDIRS RELATIVE ${PATH} ${PATH}/*)
  30. FOREACH(DIR ${SUBDIRS})
  31. IF (IS_DIRECTORY ${PATH}/${DIR})
  32. IF (NOT "${DIR}" STREQUAL "CMAKEFILES")
  33. FILE(GLOB_RECURSE SUBDIR_FILES "${PATH}/${DIR}/${PATTERN}")
  34. LIST(APPEND ${RETURN_VALUE} ${SUBDIR_FILES})
  35. ENDIF()
  36. ENDIF()
  37. ENDFOREACH()
  38. ELSE ()
  39. FILE(GLOB ${RETURN_VALUE} "${PATTERN}")
  40. FOREACH (PATH ${SOURCE_SUBDIRS})
  41. FILE(GLOB SUBDIR_FILES "${PATH}/${PATTERN}")
  42. LIST(APPEND ${RETURN_VALUE} ${SUBDIR_FILES})
  43. ENDFOREACH(PATH ${SOURCE_SUBDIRS})
  44. ENDIF ()
  45. IF (${FILTER_OUT})
  46. LIST(REMOVE_ITEM ${RETURN_VALUE} ${FILTER_OUT})
  47. ENDIF()
  48. SET(${RETURN_VALUE} ${${RETURN_VALUE}} PARENT_SCOPE)
  49. ENDFUNCTION(AUTO_SOURCES)
  50. FUNCTION(CONTAINS_STRING FILE SEARCH RETURN_VALUE)
  51. FILE(STRINGS ${FILE} FILE_CONTENTS REGEX ".*${SEARCH}.*")
  52. IF (FILE_CONTENTS)
  53. SET(${RETURN_VALUE} TRUE PARENT_SCOPE)
  54. ENDIF()
  55. ENDFUNCTION(CONTAINS_STRING)