Guest User

Untitled

a guest
Oct 23rd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 2.34 KB | None | 0 0
  1. # Function which uses the Slice translator to discover the files that a particular Slice
  2. # file depends on, and the files the translator would generate from that Slice file. The
  3. # TARGETS argument specifies the name of a variable that will receive the list of generated
  4. # files; the SOURCES argument specifies the name of a variable that will receive the list
  5. # of dependency files.
  6. #
  7. function(__astscf_slice_get_targets_and_sources COLLECTION COLLECTION_DIR SLICE COMPILER_ARGS TARGETS SOURCES)
  8.   message(STATUS "Determining dependencies for ${SLICE} from ${COLLECTION}")
  9.   execute_process(
  10.     COMMAND ${SLICE_COMPILER} ${COMPILER_ARGS} --depend ${COLLECTION_DIR}/${SLICE}
  11.     OUTPUT_VARIABLE raw_dependencies
  12.     ERROR_VARIABLE slice_errors)
  13.   if(slice_errors)
  14.     message(FATAL_ERROR "Slice compiler produced errors:\n ${slice_errors}")
  15.   endif()
  16.  
  17.   if(raw_dependencies)
  18.     # get rid of folded newlines
  19.     string(REPLACE "\\\n" "" raw_dependencies "${raw_dependencies}")
  20.     # turn newlines into item separators
  21.     string(REPLACE "\n" ";" raw_dependencies "${raw_dependencies}")
  22.  
  23.     foreach(dep ${raw_dependencies})
  24.       # each dep is of the form:
  25.       #target1 target2 [...] target_n: source1 source2 [...] source_n
  26.  
  27.       # parse targets
  28.       string(REGEX MATCHALL "^[^:]+" dep_targets "${dep}")
  29.       string(REGEX MATCHALL "[^ ]+" dep_targets "${dep_targets}")
  30.       list(APPEND targets ${dep_targets})
  31.  
  32.       # parse sources
  33.       string(REGEX MATCHALL  "^[^:]+" targstart "${dep}")
  34.       string(REGEX REPLACE "^${targstart}:" "" dep_sources "${dep}")
  35.       # replace the escaped spaces, leave the space separater.
  36.       string(REPLACE "\\ " "%20%" dep_sources "${dep_sources}")
  37.       string(REGEX MATCHALL "[^ ]+" dep_sources "${dep_sources}")
  38.       list(APPEND expsources ${dep_sources})
  39.     endforeach()
  40.   endif()
  41.   foreach(source ${expsources})
  42.     # put the spaces back in.
  43.     string(REPLACE "%20%" " " source ${source})
  44.     list(APPEND sources ${source})
  45.   endforeach()
  46.  
  47.   if(targets)
  48.     get_filename_component(slice_basename "${SLICE}" NAME_WE)
  49.     list(APPEND targets "${slice_basename}.h")
  50.     list(REMOVE_DUPLICATES targets)
  51.     list(SORT targets)
  52.     set(${TARGETS} ${targets} PARENT_SCOPE)
  53.   endif()
  54.  
  55.   if(sources)
  56.     list(SORT sources)
  57.     set(${SOURCES} ${sources} PARENT_SCOPE)
  58.   endif()
  59. endfunction()
Add Comment
Please, Sign In to add comment