Class: Configurator
- Inherits:
-
Object
- Object
- Configurator
- Defined in:
- ext/qml/extconf.rb
Constant Summary collapse
- PKGS =
%w{Qt5Core Qt5Gui Qt5Widgets Qt5Qml Qt5Quick libffi}- HEADERS =
%w{QObject QVariant QApplication QQmlEngine QQmlComponent QQmlContext ffi.h}- CLASSES =
%w{listmodel}
Instance Method Summary collapse
- #build_plugins ⇒ Object
- #configure_extension ⇒ Object
- #find_dependencies ⇒ Object
-
#initialize ⇒ Configurator
constructor
A new instance of Configurator.
Constructor Details
#initialize ⇒ Configurator
Returns a new instance of Configurator.
10 11 12 13 14 15 |
# File 'ext/qml/extconf.rb', line 10 def initialize find_dependencies @cppflags = [] @ldflags = [] @debug_enabled = enable_config('debug') end |
Instance Method Details
#build_plugins ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'ext/qml/extconf.rb', line 37 def build_plugins puts "building plugins..." qmake_opts = @debug_enabled ? 'CONFIG+=debug' : '' Pathname(__FILE__).+("../plugins").children.select(&:directory?).each do |dir| Dir.chdir(dir) do system("#{@qmake} #{qmake_opts}") && system('make clean') && system('make') or abort "failed to build plugin: #{dir.basename}" end end end |
#configure_extension ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'ext/qml/extconf.rb', line 47 def configure_extension RbConfig::CONFIG['CPP'].gsub!(RbConfig::CONFIG['CC'], RbConfig::CONFIG['CXX']) PKGS.each do |mod| @cppflags << `#{@pkgconfig} --cflags #{mod}`.chomp @ldflags << `#{@pkgconfig} --libs #{mod}`.chomp end qtversion = `#{@pkgconfig} --modversion Qt5Core`.chomp `#{@pkgconfig} --cflags-only-I Qt5Core`.split.map { |i| Pathname(i.gsub("-I", "")) }.each do |dir| private_dir = dir + "#{qtversion}/QtCore" @cppflags << "-I#{private_dir}" if private_dir.exist? end $CPPFLAGS += " #{@cppflags.join(" ")}" $LDFLAGS += " #{@ldflags.join(" ")}" $CPPFLAGS += " -fPIC" HEADERS.each do |h| abort "header not found: #{h}" unless have_header(h) end unless have_func('rb_thread_call_with_gvl') && have_func('rb_thread_call_without_gvl') abort "rb_thread_call_with_gvl and rb_thread_call_without_gvl not found" end $CPPFLAGS += " -DHAVE_RUBY_THREAD_H" if have_header('ruby/thread.h') $CPPFLAGS += " -std=c++11 -Wall -Wextra -pipe" if @debug_enabled $CPPFLAGS += " -O0 -ggdb3" else $CPPFLAGS += " -O3" end CLASSES.each do |header| File.write("moc_#{header}.cpp", `#{@moc} #{header}.h`) end create_makefile 'qml/qml' end |
#find_dependencies ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'ext/qml/extconf.rb', line 17 def find_dependencies @pkgconfig = with_config('pkg-config') || find_executable('pkg-config') abort 'pkg-config executable not found' unless @pkgconfig @qt_path = with_config('qt-dir') @qt_path &&= Pathname(@qt_path).realpath @ffi_path = with_config('libffi-dir') @ffi_path &&= Pathname(@ffi_path).realpath [@qt_path, @ffi_path].compact.each do |path| ENV['PKG_CONFIG_PATH'] = "#{path + 'lib/pkgconfig'}:#{ENV['PKG_CONFIG_PATH']}" end @qmake = @qt_path ? @qt_path + 'bin/qmake' : find_executable('qmake') @moc = @qt_path ? @qt_path + 'bin/moc' : find_executable('moc') abort 'qmake executable not found' unless @qmake abort 'moc executable not found' unless @moc end |