#!/usr/bin/env ruby

Orig="(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)"
Repl="(\"${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake\")"

#Orig="DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}"
#Repl="${INSTALL_TARGETS_DEFAULT_ARGS}"

CommentRx=/(#.+)/
IncRx=/include *\(\s*([^\s\)]+)/i
FindPackageRx=/find_package\s*\(\s*([^\s\)]+)/i

require 'ftools'

hits=0
includedFiles = Array.new
Dir["**/*.cmake"].each do |file|
   printf("file: %s\n", file)
   fileContents=IO.readlines(file)
   fileContents.each do |line|
     if line =~ CommentRx
       line[$1] = ""
     end
     if line =~ IncRx
       includedFiles.push($1)
       printf("includes %s\n", $1)
     end
     if line =~ FindPackageRx
       includedFiles.push("Find" + $1)
       printf("find_packages %s\n", $1)
     end
   end
end
printf("files: %d\n", includedFiles.size())
includedFiles.uniq!
includedFiles.sort!
printf("files: %d\n", includedFiles.size())
#printf("%d replacements made\n", hits)
includedFiles.each do |file|
  printf("%s\n", file)
end
