Skip to content

Instantly share code, notes, and snippets.

@icebreaker
Created April 19, 2010 11:08
Show Gist options
  • Select an option

  • Save icebreaker/370918 to your computer and use it in GitHub Desktop.

Select an option

Save icebreaker/370918 to your computer and use it in GitHub Desktop.
Scan and create a QT Creator project file which can be included in another project.
#!/usr/bin/env ruby
def ScanForFiles(sources, headers, pattern)
Dir[pattern].each do |f|
if FileTest.directory?(f)
ScanForFiles(sources, headers, "#{f}/*")
else
if f =~ /.h$/
headers.push(f)
else
if f =~ /.cpp$/
sources.push(f)
end
end
end
end
end
puts 'Scanning ...'
sources = []
headers = []
ScanForFiles(sources, headers, '*')
puts 'Writing QT Project ...'
file = File.new('project.pri','w')
file.write("INCLUDEPATH += $$PWD\n")
file.write("DEPENDPATH += $$PWD\n\n")
if sources.size > 0
file.write('SOURCES += ')
sources.each do |s|
if s == sources.last
file.write("#{s}\n")
else
file.write("#{s} \\\n\t")
end
end
end
if headers.size > 0
file.write('HEADERS += ')
headers.each do |h|
if h == headers.last
file.write("#{h}\n")
else
file.write("#{h} \\\n\t")
end
end
end
file.close()
puts 'Done'
gets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment