Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Function which uses the Slice translator to discover the files that a particular Slice
- # file depends on, and the files the translator would generate from that Slice file. The
- # TARGETS argument specifies the name of a variable that will receive the list of generated
- # files; the SOURCES argument specifies the name of a variable that will receive the list
- # of dependency files.
- #
- function(__astscf_slice_get_targets_and_sources COLLECTION COLLECTION_DIR SLICE COMPILER_ARGS TARGETS SOURCES)
- message(STATUS "Determining dependencies for ${SLICE} from ${COLLECTION}")
- execute_process(
- COMMAND ${SLICE_COMPILER} ${COMPILER_ARGS} --depend ${COLLECTION_DIR}/${SLICE}
- OUTPUT_VARIABLE raw_dependencies
- ERROR_VARIABLE slice_errors)
- if(slice_errors)
- message(FATAL_ERROR "Slice compiler produced errors:\n ${slice_errors}")
- endif()
- if(raw_dependencies)
- # get rid of folded newlines
- string(REPLACE "\\\n" "" raw_dependencies "${raw_dependencies}")
- # turn newlines into item separators
- string(REPLACE "\n" ";" raw_dependencies "${raw_dependencies}")
- foreach(dep ${raw_dependencies})
- # each dep is of the form:
- #target1 target2 [...] target_n: source1 source2 [...] source_n
- # parse targets
- string(REGEX MATCHALL "^[^:]+" dep_targets "${dep}")
- string(REGEX MATCHALL "[^ ]+" dep_targets "${dep_targets}")
- list(APPEND targets ${dep_targets})
- # parse sources
- string(REGEX MATCHALL "^[^:]+" targstart "${dep}")
- string(REGEX REPLACE "^${targstart}:" "" dep_sources "${dep}")
- # replace the escaped spaces, leave the space separater.
- string(REPLACE "\\ " "%20%" dep_sources "${dep_sources}")
- string(REGEX MATCHALL "[^ ]+" dep_sources "${dep_sources}")
- list(APPEND expsources ${dep_sources})
- endforeach()
- endif()
- foreach(source ${expsources})
- # put the spaces back in.
- string(REPLACE "%20%" " " source ${source})
- list(APPEND sources ${source})
- endforeach()
- if(targets)
- get_filename_component(slice_basename "${SLICE}" NAME_WE)
- list(APPEND targets "${slice_basename}.h")
- list(REMOVE_DUPLICATES targets)
- list(SORT targets)
- set(${TARGETS} ${targets} PARENT_SCOPE)
- endif()
- if(sources)
- list(SORT sources)
- set(${SOURCES} ${sources} PARENT_SCOPE)
- endif()
- endfunction()
Add Comment
Please, Sign In to add comment