glob.cmake
Go to the documentation of this file.
1 # ============================================================================
2 # Copyright (c) 2011-2012 University of Pennsylvania
3 # Copyright (c) 2013-2016 Andreas Schuh
4 # All rights reserved.
5 #
6 # See COPYING file for license information or visit
7 # https://cmake-basis.github.io/download.html#license
8 # ============================================================================
9 
10 ##############################################################################
11 # @file glob.cmake
12 # @brief Glob source files and optionally compare to previous glob result.
13 ##############################################################################
14 
15 include ("${CMAKE_CURRENT_LIST_DIR}/CommonTools.cmake")
16 
17 if (NOT EXPRESSIONS)
18  message (FATAL_ERROR "Missing EXPRESSIONS argument!")
19 endif ()
20 if (NOT SOURCES_FILE)
21  message (FATAL_ERROR "Missing SOURCES_FILE argument!")
22 endif ()
23 
24 set (SOURCES)
25 foreach (EXPRESSION IN LISTS EXPRESSIONS)
26  if (EXPRESSION MATCHES "[*][*]")
27  string (REPLACE "**" "*" EXPRESSION "${EXPRESSION}")
28  file (GLOB_RECURSE _SOURCES "${EXPRESSION}")
29  list (APPEND SOURCES ${_SOURCES})
30  elseif (EXPRESSION MATCHES "[*?]|\\[[0-9]+-[0-9]+\\]")
31  file (GLOB _SOURCES "${EXPRESSION}")
32  list (APPEND SOURCES ${_SOURCES})
33  else ()
34  list (APPEND SOURCES "${EXPRESSION}")
35  endif ()
36 endforeach ()
37 if (SOURCES)
38  list (REMOVE_DUPLICATES SOURCES)
39 endif ()
40 
41 set (_SOURCES)
42 foreach (SOURCE IN LISTS SOURCES)
43  if (SOURCE MATCHES "^\\$<") # preserve generator expressions
44  list (APPEND _SOURCES "${SOURCE}")
45  else ()
46  get_filename_component (SOURCE_NAME "${SOURCE}" NAME)
47  if (NOT SOURCE MATCHES "(^|/).(svn|git)/" AND NOT SOURCE_NAME MATCHES "^\\.")
48  list (APPEND _SOURCES "${SOURCE}")
49  endif ()
50  endif ()
51 endforeach ()
52 set (SOURCES ${_SOURCES})
53 unset (_SOURCES)
54 
55 if (INIT)
56  basis_write_list ("${SOURCES_FILE}" INITIAL_SOURCES ${SOURCES})
57 else ()
58  include ("${SOURCES_FILE}")
59  if (NOT "${SOURCES}" STREQUAL "${INITIAL_SOURCES}")
60  # touching this file which is included by basis_add_glob_target()
61  # re-triggers CMake upon the next build
62  execute_process (COMMAND "${CMAKE_COMMAND}" -E touch "${SOURCES_FILE}")
63  message (FATAL_ERROR "${ERRORMSG}")
64  endif ()
65 endif ()
cmake SOURCES
Definition: glob.cmake:52
if(oldcoutbuf)