Module: MxxRu::Cpp

Defined in:
lib/mxx_ru/cpp/qt.rb,
lib/mxx_ru/cpp/mode.rb,
lib/mxx_ru/cpp/target.rb,
lib/mxx_ru/cpp/toolset.rb,
lib/mxx_ru/cpp/analyzer.rb,
lib/mxx_ru/cpp/composite.rb,
lib/mxx_ru/cpp/rucodegen.rb,
lib/mxx_ru/cpp/qt4details.rb,
lib/mxx_ru/cpp/source_file.rb,
lib/mxx_ru/cpp/toolsets/vc7.rb,
lib/mxx_ru/cpp/toolsets/vc8.rb,
lib/mxx_ru/cpp/toolsets/vc9.rb,
lib/mxx_ru/cpp/obj_placement.rb,
lib/mxx_ru/cpp/toolsets/vc10.rb,
lib/mxx_ru/cpp/toolsets/vc11.rb,
lib/mxx_ru/cpp/toolsets/vc12.rb,
lib/mxx_ru/cpp/toolsets/vc14.rb,
lib/mxx_ru/cpp/detect_toolset.rb,
lib/mxx_ru/cpp/lib_collection.rb,
lib/mxx_ru/cpp/toolsets/c89_nsk.rb,
lib/mxx_ru/cpp/toolsets/icc_win.rb,
lib/mxx_ru/cpp/qt4_via_pkg_config.rb,
lib/mxx_ru/cpp/toolsets/gcc_linux.rb,
lib/mxx_ru/cpp/toolsets/gcc_mingw.rb,
lib/mxx_ru/cpp/toolsets/vc_family.rb,
lib/mxx_ru/cpp/toolsets/gcc_cygwin.rb,
lib/mxx_ru/cpp/toolsets/gcc_darwin.rb,
lib/mxx_ru/cpp/toolsets/gcc_family.rb,
lib/mxx_ru/cpp/toolsets/vc8_family.rb,
lib/mxx_ru/cpp/toolsets/bcc_win32_5.rb,
lib/mxx_ru/cpp/toolsets/c89_etk_nsk.rb,
lib/mxx_ru/cpp/toolsets/clang_linux.rb,
lib/mxx_ru/cpp/toolsets/clang_family.rb,
lib/mxx_ru/cpp/toolsets/clang_freebsd.rb,
lib/mxx_ru/cpp/toolsets/c89_nsk_family.rb,
lib/mxx_ru/cpp/toolsets/gcc_unix_family.rb,
lib/mxx_ru/cpp/toolsets/bcc_win32_family.rb,
lib/mxx_ru/cpp/toolsets/gcc_sparc_solaris.rb,
lib/mxx_ru/cpp/obj_placements/custom_subdir.rb

Defined Under Namespace

Modules: Analyzer, Qt4Modules, Toolsets Classes: CompositeTarget, CompositeTargetType, CppSourceFile, CustomSubdirObjPlacement, DllInfo, DllRequirements, DllTarget, DllTargetType, ExeInfo, ExeTarget, ExeTargetType, GlobalSingleValueOption, LibCollectionTarget, LibCollectionTargetType, LibInfo, LibOrDllTarget, LibTarget, LibTargetType, LinkerLists, MacOSBundleTarget, MacOSBundleTargetType, Mode, MswinRcFile, MswinResInfo, ObjInfo, ObjPlacement, Qt4, QtGen, RuCodeGen, RuntimeSubdirObjPlacement, SourceSubdirObjPlacement, SpreadableOption, Target, TargetType, TargetWithFullPath, Toolset

Constant Summary collapse

Qt_gen =

For compatibility with previous versions

QtGen
MXXCPPARG_RELEASE =

Arguments passed into Ruby interpreter, intended to control MxxRu::Cpp.

"--mxx-cpp-release"
MXXCPPARG_DEBUG =
"--mxx-cpp-debug"
MXXCPPARG_ONLY_ONE =
"--mxx-cpp-1"
MXXCPPARG_NO_DEPENDS_ANALYZER =
"--mxx-cpp-no-depends-analyzer"
MXXCPPARG_EXTRACT_OPTIONS =
"--mxx-cpp-extract-options"
RUNTIME_DEFAULT =

Default mode. Nor debug information nor optimization options are set.

"default"
RUNTIME_RELEASE =

Release mode. Optimization is turned on.

"release"
RUNTIME_DEBUG =

Debug mode. Debug information is generated.

"debug"
RTTI_DEFAULT =

Default RTTI mode. No RTTI options are passed to compiler.

"default"
RTTI_ENABLED =

RTTI mode should be enabled.

"enabled"
RTTI_DISABLED =

RTTI mode should be disabled.

"disabled"
RTL_DEFAULT =

Default compiler libraries are used.

"default"
RTL_SHARED =

Use shared runtime library.

"shared"
RTL_STATIC =

Use static runtime library.

"static"
THREADING_DEFAULT =

Default compiler threading mode.

"default"
THREADING_MULTI =

Multithreading is used.

"multi"
THREADING_SINGLE =

Multithreading is not used.

"single"
SCREEN_CONSOLE =

Console application.

"console"
SCREEN_WINDOW =

Windowed application.

"window"
OPTIM_SIZE =

Optimization by size.

"size"
OPTIM_SPEED =

Optimization by speed.

"speed"
Global_single_value_option =

For compatibility with previous versions.

GlobalSingleValueOption
Spreadable_option =

For compatibility with previous versions.

SpreadableOption
Target_type =

For compatibility with previous versions.

TargetType
Exe_target_type =

For compatibility with previous versions.

ExeTargetType
Lib_target_type =

For compatibility with previous versions.

LibTargetType
Dll_target_type =

For compatibility with previous versions.

DllTargetType
Macos_bundle_target_type =

For compatibility with previous versions.

MacOSBundleTargetType
Lib_or_dll_target =

For compatibility with previous versions.

LibOrDllTarget
Lib_target =

For compatibility with previous versions.

LibTarget
Dll_target =

For compatibility with previous versions.

DllTarget
Macos_bundle_target =

For compatibility with previous versions.

MacOSBundleTarget
Exe_target =

For compatibility with previous versions.

ExeTarget
Obj_info =

For compatibility with previous versions.

ObjInfo
Target_with_full_path =

For compatibility with previous versions.

TargetWithFullPath
Mswin_res_info =

For compatibility with previous versions.

MswinResInfo
Lib_info =

For compatibility with previous versions.

LibInfo
Exe_info =

For compatibility with previous versions.

ExeInfo
Dll_info =

For compatibility with previous versions.

DllInfo
Linker_lists =

For compatibility with previous versions.

LinkerLists
Dll_requirements =

For compatibility with previous versions.

DllRequirements
CPP_STD_DEFAULT =

Default C++ standard variant. The compiler defaults must be used.

Since v.1.6.3

0
CPP_STD03 =

C++03 standard.

Since v.1.6.3

1
CPP_STD11 =

C++11 standard.

Since v.1.6.3

2
CPP_STD14 =

C++14 standard.

Since v.1.6.3

3
Composite_target_type =

For compatibility with previous versions.

CompositeTargetType
Composite_target =

For compatibility with previous versions.

CompositeTarget
Cpp_source_file =

For compatibility with previous versions.

CppSourceFile
Mswin_rc_file =

For compatibility with previous versions.

MswinRcFile
Obj_placement =

For compatibility with previous versions.

ObjPlacement
Source_subdir_obj_placement =

For compatibility with previous versions.

SourceSubdirObjPlacement
Runtime_subdir_obj_placement =

For compatibility with older versions.

RuntimeSubdirObjPlacement
ENV_VAR =
"MXX_RU_CPP_TOOLSET"
Custom_subdir_obj_placement =

For compatibility with old naming convention.

CustomSubdirObjPlacement
@@current_toolset =

Current toolset.

nil

Class Method Summary collapse

Class Method Details

.composite_target(prj_alias = nil, &block) ⇒ Object

Simple method to define composite target.

Example:

MxxRu::Cpp::composite_target( MxxRu::BUILD_ROOT ) {
  required_prj 'some_project.rb'
  required_prj 'some_another_project.rb'
}


100
101
102
103
# File 'lib/mxx_ru/cpp/composite.rb', line 100

def Cpp.composite_target( prj_alias = nil, &block )
  prj_alias = MxxRu::Util::prj_alias_form_caller( caller ) unless prj_alias
  MxxRu::setup_target CompositeTarget.new( prj_alias, &block )
end

.default_obj_placementObject

Creation of obj_placement object, which should be used by default.



323
324
325
# File 'lib/mxx_ru/cpp/obj_placement.rb', line 323

def Cpp.default_obj_placement
  return SourceSubdirObjPlacement.new
end

.detect_toolsetObject

Detect current toolset based on values of environment variables

Following algorithm is used: Getting the value of MXX_RU_CPP_TOOLSET envonment variable. It should be in a following format:

<file> [tag=value [tag=value [...]]

<file> value is used in require directive.

After loading of file defined, toolset method should return a pointer to toolset object.

If toolset object was created, pairs of tag=value are parsed and saved to the toolset created using a setup_tag method.



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
# File 'lib/mxx_ru/cpp/detect_toolset.rb', line 50

def Cpp.detect_toolset
  begin
    env = get_or_detect_toolset_variable_content

    # Exctracting file name, responsible for toolset object creation.
    toolset_file_name_regexp = /^(\S+)(.*)$/
    file_name_match = toolset_file_name_regexp.match( env )
    if nil == file_name_match
      raise MxxRu::InvalidValueEx.new(
        "Invalid format of environment variable '#{env_var}'. " +
        "Expected format: #{env_var}=<file>[ <tag>=<value>[ " +
        "<tag>=<value>[ ...]]]" )
    end

    file_name = file_name_match[ 1 ]
    unparsed_tags = file_name_match[ 2 ]

    # Loading the file
    # Try to loading specified file first, if it fails try to
    # loading file with 'mxx_ru/cpp/toolsets' added...
    try_load_toolset_file file_name

    if nil == toolset()
      raise MxxRu::InvalidValueEx.new(
        "C/C++ Toolset is not set by file '#{file_name}'" )
    end

    # Setting up toolset tags
    setup_toolset_tags( toolset(), unparsed_tags )

  rescue MxxRu::Ex => ex
    $stderr.print "<<<[#{ex.class.name}]\t#{ex}>>>\n"
    exit( -1 )
  end
end

.generate_simple_target_method(target_type) ⇒ Object

Generator for generating method for simple way of describing targets.



1544
1545
1546
1547
1548
1549
1550
1551
1552
# File 'lib/mxx_ru/cpp/target.rb', line 1544

def Cpp.generate_simple_target_method( target_type )
  target_class_name = target_type.to_s.capitalize
  class_eval %Q{
    def Cpp.#{target_type}( prj_alias = nil, &block )
      prj_alias = MxxRu::Util::prj_alias_form_caller( caller ) unless prj_alias
      MxxRu::setup_target #{target_class_name}.new( prj_alias, &block )
    end
  }
end

.get_or_detect_toolset_variable_contentObject

Gets or detects value for MXX_RU_CPP_TOOLSET.

Since v.1.5.1



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/mxx_ru/cpp/detect_toolset.rb', line 120

def Cpp.get_or_detect_toolset_variable_content
  env = ENV[ ENV_VAR ]
  if env.nil?
    $stderr.puts "Environment variable #{ENV_VAR} not found. " +
        "Try to detect toolset by HOST_OS and/or PATH..."
    env = try_detect_toolset_myself
    if env
      $stderr.puts "Detection successed. Toolset is: #{env}"
    else
      $stderr.puts "Detection failed."
      raise MxxRu::InvalidValueEx.new(
        "Environment variable '#{ENV_VAR}' not found (not set " +
        "or empty" )
    end
  end

  env
end

.lib_collection_target(prj_alias = nil, &block) ⇒ Object

Simple method to define libraries collection target.

Example:

MxxRu::Cpp::lib_collection_target {
  required_prj 'some_project.rb'
  required_prj 'some_another_project.rb'
}

Since v.1.4.0



89
90
91
92
# File 'lib/mxx_ru/cpp/lib_collection.rb', line 89

def Cpp.lib_collection_target( prj_alias = nil, &block )
  prj_alias = MxxRu::Util::prj_alias_form_caller( caller ) unless prj_alias
  MxxRu::setup_target LibCollectionTarget.new( prj_alias, &block )
end

.setup_toolset(toolset) ⇒ Object

Set current toolset.



1291
1292
1293
1294
1295
1296
1297
# File 'lib/mxx_ru/cpp/toolset.rb', line 1291

def Cpp.setup_toolset( toolset )
  raise MxxRu::InvalidCastEx.new(
    'Expected MxxRu::Cpp::Toolset' ) if
      !( toolset.kind_of?( MxxRu::Cpp::Toolset ) )

  @@current_toolset = toolset
end

.setup_toolset_tags(a_toolset, a_unparsed_tags) ⇒ Object

a_toolset

Toolset, tags are set for

a_unparsed_tags

A string, formatted that way: <tag>=<value>[ <tag>=<value> [<tag>=<value> …]]



89
90
91
92
93
94
95
96
# File 'lib/mxx_ru/cpp/detect_toolset.rb', line 89

def Cpp.setup_toolset_tags( a_toolset,
  a_unparsed_tags )

  a_unparsed_tags.scan( /(\S+)=(\S+)/ ) { |t, v|
    a_toolset.setup_tag( t, v )
  }

end

.toolsetObject

Get current toolset.



1300
1301
1302
# File 'lib/mxx_ru/cpp/toolset.rb', line 1300

def Cpp.toolset
  return @@current_toolset
end

.try_detect_toolset_myselfObject

Try to detect toolset from host_os and PATH.

Since v.1.5.1

Only Windows platform and MS C++, Linux and GCC is detected now.

Returns name of toolset of throw exception if toolset is not detectable.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/mxx_ru/cpp/detect_toolset.rb', line 146

def Cpp.try_detect_toolset_myself
  if RbConfig::CONFIG['host_os'] =~ /linux/
    # Assume that GCC is default compiler on Linux.
    "gcc_linux"
  elsif RbConfig::CONFIG['host_os'] =~ /^freebsd(9|10)$/
    "clang_freebsd"
  else
    if ENV[ 'COMP_ENV' ] and ENV[ 'VC_ARCH' ]
      'icc_win'
    elsif ENV[ 'VS140COMNTOOLS' ]
      'vc14'
    elsif ENV[ 'VS120COMNTOOLS' ]
      'vc12'
    elsif ENV[ 'VS110COMNTOOLS' ]
      'vc11'
    elsif ENV[ 'VS100COMNTOOLS' ]
      'vc10'
    elsif ENV[ 'VS90COMNTOOLS' ]
      'vc9'
    elsif ENV[ 'VS80COMNTOOLS' ]
      'vc8'
    elsif ENV[ 'VS71COMNTOOLS' ]
      'vc7'
    end
  end
end

.try_load_toolset_file(file_name) ⇒ Object

Try load toolset file (without and with ‘mxx_ru/cpp/toolsets’ prefix).

Raises LoadError if loading failed



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/mxx_ru/cpp/detect_toolset.rb', line 101

def Cpp.try_load_toolset_file( file_name )
  files_to_load = [ file_name,
      File.join( 'mxx_ru/cpp/toolsets', file_name ) ]
  load_result = files_to_load.detect { |file_to_load|
      begin
        require file_to_load
      rescue LoadError
        false
      end
    }
  raise MxxRu::InvalidValueEx.new(
    "Unable to load Toolset from files: " +
      "'#{files_to_load.join('; ')}'" ) unless load_result
end