class MxxRu::Cpp::Qt_gen
Files generator for Qt class.
Main features:
-
building of moc-files using moc tool. Generation from source and header files is supported.
-
building source files from ui-files using uic-compiler. For all files generated this way moc tool executed automatically.
Generated source files automatically added into cpp_source list of target.
Local list defines is supported.
If only pointer to the target passed into contructor, default list of defines is used. If it's required to change default list, new list should be passed through a second argument:
generator( MxxRu::Cpp::QtGen.new( self, [ "QT_THREAD_SUPPORT" ] ) )
Constants
- DEFAULT_DEFINES
Default list of defines. QT_DLL, QT_THREAD_SUPPORT
- UiNames
Attributes
File extension for source files generated. Used in both moc and uic tools. Default: .cpp
File extension for header files generated. Used in uic tool. Default: .hpp
File extension for moc files generated. Used in moc tool. Default: .moc
moc tool executable Default: moc
Subfolder name where moc generated files would be located. If nil, generated files would be in the same folder where source files were. Default: nil
Files list for generating moc files from source files.
More exact: a.cpp -> a.moc.
Files list for generating moc files from header files.
More exact: a.hpp -> moc_a.cpp. moc_a.cpp file is added to cpp_source list of a target.
Files list for generating hpp, cpp and moc files from ui files.
More exact: a.ui -> a.hpp, a.cpp, moc_a.cpp. a.cpp, moc_a.cpp files are added to cpp_source of a target.
Target
, generator is created for.
uic tool executable Default: uic.
Subfolder name where results of uic invokation must be placed. If nil, generated files would be in the same folder where source ui files were.
Public Class Methods
Constructor.
# File lib/mxx_ru/cpp/qt.rb, line 118 def initialize( a_target, a_defines = DEFAULT_DEFINES ) @moc_name = "moc" @uic_name = "uic" @cpp_ext = ".cpp" @hpp_ext = ".hpp" @moc_ext = ".moc" @moc_result_subdir = nil @uic_result_subdir = nil # If uic_result_subdir not nil than we must add # uic_result_subdir into # target include_path. But must do this only one time. @uic_result_subdir_include_paths = Set.new @qt_h2moc_files = Array.new @qt_cpp2moc_files = Array.new @qt_ui_files = Array.new defines_to_set = a_defines.flatten defines_to_set.each { |d| a_target.define( d ) } @target = a_target end
Public Instance Methods
Perform files generation.
# File lib/mxx_ru/cpp/qt.rb, line 167 def build( a_target ) build_from_ui( a_target ) build_from_h( a_target ) build_from_cpp( a_target ) end
Perform generated files cleanup.
# File lib/mxx_ru/cpp/qt.rb, line 174 def clean( a_target ) clean_from_ui( a_target ) clean_from_h( a_target ) clean_from_cpp( a_target ) end
Add a file for cpp to moc generation.
# File lib/mxx_ru/cpp/qt.rb, line 148 def cpp2moc( a_file ) @qt_cpp2moc_files << @target.create_full_src_file_name( a_file ) end
Add a file for hpp to moc generation.
# File lib/mxx_ru/cpp/qt.rb, line 143 def h2moc( a_file ) @qt_h2moc_files << @target.create_full_src_file_name( a_file ) end
Add a file for ui to hpp, cpp and moc generation.
# File lib/mxx_ru/cpp/qt.rb, line 153 def ui( a_file ) full_file_name = @target.create_full_src_file_name( a_file ) @qt_ui_files << full_file_name if @uic_result_subdir uic_result_path = make_uic_result_path_for( full_file_name ) if !@uic_result_subdir_include_paths.member?( uic_result_path ) @target.include_path( uic_result_path ) @uic_result_subdir_include_paths.add( uic_result_path ) end end end
Protected Instance Methods
Setting C++ file name, ignoring current sources_root value.
# File lib/mxx_ru/cpp/qt.rb, line 335 def add_cpp_source( a_target, a_file ) old_root = a_target.sources_root( "" ) a_target.cpp_source( a_file ) a_target.sources_root( old_root ) end
Perform generation from cpp file using moc tool.
# File lib/mxx_ru/cpp/qt.rb, line 298 def build_from_cpp( a_target ) @qt_cpp2moc_files.each { |cpp_full| moc_full = moc_from_cpp( cpp_full, a_target ) if TargetState::EXISTS != TargetState.detect( moc_full, [ cpp_full ] ).state MxxRu::AbstractTarget::run( [ "#{moc_name} -o #{moc_full} " + "#{cpp_full}" ], [ moc_full ], "building moc file #{moc_full}" ) end } end
Perform generation from hpp file using moc tool.
# File lib/mxx_ru/cpp/qt.rb, line 255 def build_from_h( a_target ) @qt_h2moc_files.each { |header_full| moc_full = moc_from_h( header_full, a_target ) if TargetState::EXISTS != TargetState.detect( moc_full, [ header_full ] ).state MxxRu::AbstractTarget::run( [ "#{moc_name} -o #{moc_full} " + "#{header_full}" ], [ moc_full ], "building moc file #{moc_full}" ) end add_cpp_source( a_target, moc_full ) } end
Perform generation from ui-files.
# File lib/mxx_ru/cpp/qt.rb, line 183 def build_from_ui( a_target ) @qt_ui_files.each { |ui| files_from_ui = names_from_ui( ui, a_target ) MxxRu::Util::ensure_path_exists( File.dirname( files_from_ui.header ) ) MxxRu::Util::ensure_path_exists( File.dirname( files_from_ui.source ) ) # Full file path detection. header_file = files_from_ui.header cpp_file = files_from_ui.source @qt_h2moc_files << header_file add_cpp_source( a_target, cpp_file ) # Checking what files are changed and running generation # from them if necessary. if TargetState::EXISTS != TargetState.detect( header_file, [ ui ] ).state MxxRu::AbstractTarget::run( [ "#{@uic_name} -o #{header_file} #{ui}" ], [ header_file ], "building header file #{header_file}" ) end if TargetState::EXISTS != TargetState.detect( cpp_file, [ ui, header_file ] ).state MxxRu::AbstractTarget::run( [ "#{@uic_name} -i #{File.basename(header_file)} " + "-o #{cpp_file} #{ui}" ], [ cpp_file ], "building source file #{cpp_file}" ) end } end
Perform cleanup of files produced by generation from cpp file.
# File lib/mxx_ru/cpp/qt.rb, line 314 def clean_from_cpp( a_target ) @qt_cpp2moc_files.each { |cpp| moc = moc_from_cpp( cpp, a_target ) MxxRu::Util::delete_file( moc ) } end
Perform cleanup of files produced by generation from hpp file.
# File lib/mxx_ru/cpp/qt.rb, line 273 def clean_from_h( a_target ) @qt_h2moc_files.each { |h| moc = moc_from_h( h, a_target ) MxxRu::Util::delete_file( moc ) add_cpp_source( a_target, moc ) } end
Perform cleanup of files, generated from ui files.
# File lib/mxx_ru/cpp/qt.rb, line 219 def clean_from_ui( a_target ) @qt_ui_files.each { |ui| files_from_ui = names_from_ui( ui, a_target ) MxxRu::Util::delete_file( files_from_ui.header ) MxxRu::Util::delete_file( files_from_ui.source ) # To remove object files. @qt_h2moc_files << files_from_ui.header add_cpp_source( a_target, files_from_ui.source ) } end
Calculating path for moc results.
# File lib/mxx_ru/cpp/qt.rb, line 342 def make_moc_result_path_for( path ) if @moc_result_subdir if path.length > 0 File.join( path, @moc_result_subdir ) else @moc_result_subdir end else path end end
Calculating path for uic results.
# File lib/mxx_ru/cpp/qt.rb, line 355 def make_uic_result_path_for( file ) File.join( File.dirname( file ), @uic_result_subdir ) end
Formatting file name, which is generated from cpp file by moc tool
# File lib/mxx_ru/cpp/qt.rb, line 323 def moc_from_cpp( a_cpp_file, a_target ) path = make_moc_result_path_for( File.dirname( a_cpp_file ) ) MxxRu::Util::ensure_path_exists( path ) r = File.join( path, File.basename( MxxRu::Util::remove_file_ext( a_cpp_file ) ) + @moc_ext ) return r end
Formatting file name, which is generated from hpp file by moc tool
# File lib/mxx_ru/cpp/qt.rb, line 284 def moc_from_h( a_h_file, a_target ) path = File.dirname( a_h_file ) # If path == ".", then Qt will generate wrong include directive path = "" if path == "./" path = make_moc_result_path_for( path ) MxxRu::Util::ensure_path_exists( path ) r = File.join( path, "moc_" + File.basename( MxxRu::Util::remove_file_ext( a_h_file ) ) + @cpp_ext ) end
Getting file names, generated by uic tool.
Returns UiNames
struct object.
# File lib/mxx_ru/cpp/qt.rb, line 235 def names_from_ui( a_ui_file, a_target ) if @uic_result_subdir then uic_result_path = make_uic_result_path_for( a_ui_file ) short_ui_name = MxxRu::Util::remove_file_ext( File.basename( a_ui_file ) ) result = UiNames.new( File.join( uic_result_path, short_ui_name + @hpp_ext ), File.join( uic_result_path, short_ui_name + @cpp_ext ) ) else full_ui_name = MxxRu::Util::remove_file_ext( a_ui_file ) result = UiNames.new( full_ui_name + @hpp_ext, full_ui_name + @cpp_ext ) end return result end