Class: MxxRu::Cpp::Toolsets::VcFamily

Inherits:
MxxRu::Cpp::Toolset show all
Defined in:
lib/mxx_ru/cpp/toolsets/vc_family.rb

Overview

Toolset implemetation for Visual C++

Direct Known Subclasses

Vc7, Vc8Family

Constant Summary

Constants inherited from MxxRu::Cpp::Toolset

MxxRu::Cpp::Toolset::COMPILER_NAME_TAG, MxxRu::Cpp::Toolset::CPP_COMPILER_NAME_TAG, MxxRu::Cpp::Toolset::C_COMPILER_NAME_TAG, MxxRu::Cpp::Toolset::IMPORT_LIBRARIAN_NAME_TAG, MxxRu::Cpp::Toolset::LIBRARIAN_NAME_TAG, MxxRu::Cpp::Toolset::LINKER_NAME_TAG, MxxRu::Cpp::Toolset::RC_NAME_TAG, MxxRu::Cpp::Toolset::Unknown_tag_ex

Instance Attribute Summary

Attributes inherited from MxxRu::Cpp::Toolset

#cpp_std

Instance Method Summary collapse

Methods inherited from MxxRu::Cpp::Toolset

#clean_dll, #clean_exe, #clean_lib, #clean_mswin_res, #clean_mswin_res_specific_files, #clean_objs, #force_cpp03, #force_cpp0x_std, #force_cpp11, #force_cpp14, #force_cpp17, #full_dll_name, #full_exe_name, #full_lib_name, has_linkable_dependecies?, #make_dll, #make_exe, #make_identification_string, #make_lib, #make_mswin_res, #make_objs, #name, #setup_tag, #tag

Constructor Details

#initialize(a_name) ⇒ VcFamily

Returns a new instance of VcFamily.



38
39
40
41
42
43
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 38

def initialize( a_name )
  super( a_name )

  setup_tag( "host_os", "mswin" )
  setup_tag( "target_os", "mswin" )
end

Instance Method Details

#c_compiler_nameObject

Returns C compiler name. For Visual C++ the only one compiler is used.



67
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 67

def c_compiler_name; compiler_name end

#clean_dll_specific_files(a_dll_file, a_dll_info, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#clean_dll_specific_files.

Removes import library if exists.

Removes *.ilk, *.pdb files.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 173

def clean_dll_specific_files(
  a_dll_file,
  a_dll_info,
  a_target )

  # Remove import library if exists.
  if nil != a_dll_info.link_name
    implib_name = File.join(
        [ a_dll_info.link_path, a_dll_info.link_name ] )
    MxxRu::Util::delete_file( implib_name )

    # *.exp files are also created by Visual C++.
    explib_name =
      MxxRu::Util::change_file_ext( implib_name, ".exp" )
    MxxRu::Util::delete_file( explib_name )
  end

  clean_vc_specific_garbage( a_dll_file )
end

#clean_exe_specific_files(a_exe_file, a_exe_info, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#clean_exe_specific_files.

Removing *.ilk, *.pdb files.



196
197
198
199
200
201
202
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 196

def clean_exe_specific_files(
  a_exe_file,
  a_exe_info,
  a_target )

  clean_vc_specific_garbage( a_exe_file )
end

#clean_lib_specific_files(a_lib_file, a_lib_info, a_target) ⇒ Object

Common description see MxxRu::Cpp::Toolset#clean_lib_specific_files.

Removes VC specific garbage files.



160
161
162
163
164
165
166
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 160

def clean_lib_specific_files(
  a_lib_file,
  a_lib_info,
  a_target )

  clean_vc_specific_garbage( a_lib_file )
end

#clean_vc_specific_garbage(full_name) ⇒ Object

Remove VC specific garbage.

In DEBUG mode: *.ilk, *.pdb files. If something exported from executable: *.exp, *.lib (only if *.exp file exists).



416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 416

def clean_vc_specific_garbage( full_name )
  MxxRu::Util::delete_file(
    MxxRu::Util::change_file_ext( full_name, ".ilk" ) )
  MxxRu::Util::delete_file(
    MxxRu::Util::change_file_ext( full_name, ".pdb" ) )

  exp_file_name = MxxRu::Util::change_file_ext( full_name, ".exp" )
  if File.exists?( exp_file_name )
    MxxRu::Util::delete_file( exp_file_name )
    # Import library for this export-file must be removed too.
    MxxRu::Util::delete_file(
      MxxRu::Util::change_file_ext( full_name, ".lib" ) )
  end
end

#compiler_nameObject

Returns compiler name.



46
47
48
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 46

def compiler_name
  return tag( COMPILER_NAME_TAG, "cl" )
end

#cpp_compiler_nameObject

Returns C++ compiler name. For Visual C++ the only one compiler is used.



71
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 71

def cpp_compiler_name; compiler_name; end

#dll_file_name(source_name, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#dll_file_name.



279
280
281
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 279

def dll_file_name( source_name, target )
  return construct_target_name( source_name, NO_PREFIX, ".dll", target )
end

#exe_file_name(source_name, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#exe_file_name.



359
360
361
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 359

def exe_file_name( source_name, target )
  return construct_target_name( source_name, NO_PREFIX, ".exe", target )
end

See description at MxxRu::Cpp::Toolset#implib_link_name.



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 284

def implib_link_name(
  dll_real_name,
  target )

  # Import library should be defined explicitly for Visual C++.
  if nil != target.mxx_implib_path
    return lib_file_name( target.mxx_target_name, target )
  end

  return nil
end

See description at MxxRu::Cpp::Toolset#implib_link_path.

Returns a value, based on MxxRu::Cpp::Target#mxx_implib_path.



300
301
302
303
304
305
306
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 300

def implib_link_path(
  dll_real_name,
  dll_real_path,
  target )
  return target.mxx_obj_placement.get_lib(
    target.mxx_implib_path, self, target )
end

#lib_file_name(source_name, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#lib_file_name.



255
256
257
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 255

def lib_file_name( source_name, target )
  return construct_target_name( source_name, NO_PREFIX, '.lib', target )
end

See description at MxxRu::Cpp::Toolset#lib_link_name.



260
261
262
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 260

def lib_link_name( source_name, target )
  return lib_file_name( source_name, target )
end

#librarian_nameObject

Returns librarian name.



56
57
58
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 56

def librarian_name
  return tag( LIBRARIAN_NAME_TAG, "lib" )
end

#linker_nameObject

Returns linker name.



51
52
53
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 51

def linker_name
  return tag( LINKER_NAME_TAG, "link" )
end

#make_c_obj_command_lines(obj_name, source_name, compiler_options, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_c_obj_command_lines.



210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 210

def make_c_obj_command_lines(
  obj_name,
  source_name,
  compiler_options,
  target )

  tmpfile = MxxRu::Util::TmpFiles.instance.create(
    "-c -TC -Fo#{obj_name} " +
    "#{compiler_options.join(' ')} #{source_name}" )

  return [ "#{compiler_name} @#{tmpfile}" ]
end

#make_cpp_obj_command_lines(obj_name, source_name, compiler_options, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_c_obj_command_lines.



224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 224

def make_cpp_obj_command_lines(
  obj_name,
  source_name,
  compiler_options,
  target )

  tmpfile = MxxRu::Util::TmpFiles.instance.create(
    "-c -TP -Fo#{obj_name} " +
    "#{compiler_options.join(' ')} #{source_name}" )

  return [ "#{compiler_name} @#{tmpfile}" ]
end

#make_dll_command_lines(a_dll_name, a_dll_info, a_linker_lists, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_dll_command_lines.



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 309

def make_dll_command_lines(
  a_dll_name,
  a_dll_info,
  a_linker_lists,
  a_target )

  result = "/DLL " +
    "#{a_linker_lists.linker_options.join(' ')} " +
    "/OUT:#{a_dll_name} "

  if a_linker_lists.resources.size
    result << "#{a_target.mxx_all_mswin_rlink_options.join(' ')} "
  end

  if nil != a_dll_info.link_name
    implib_name = File.join( [ a_dll_info.link_path,
      a_dll_info.link_name ] )
    result << "/IMPLIB:#{implib_name} "
  end

  a_linker_lists.lib_paths.each { |p| result << "/LIBPATH:#{p} " }

  result << "#{a_linker_lists.objs.join(' ')} "
  result << "#{make_libraries_list_for_linker(a_linker_lists.libs)} "
  result << "#{a_linker_lists.resources.join(' ')} "

  tmpfile = MxxRu::Util::TmpFiles.instance.create( result )

  return [ "#{linker_name} @#{tmpfile}" ]
end

#make_dll_requirements(a_dll_name, a_dll_info, a_linker_lists, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_dll_requirements.



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 341

def make_dll_requirements(
  a_dll_name,
  a_dll_info,
  a_linker_lists,
  a_target )

  result = DllRequirements.new

  # Dependencies are exists only if import library is present.
  if nil != a_dll_info.link_name
    result.add_libs( [ a_dll_info.link_name ] )
    result.add_lib_paths( [ a_dll_info.link_path ] )
  end

  return result
end

#make_exe_command_lines(a_exe_name, a_exe_info, a_linker_lists, a_target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_exe_command_lines.



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 364

def make_exe_command_lines(
  a_exe_name,
  a_exe_info,
  a_linker_lists,
  a_target )

  result = "#{a_linker_lists.linker_options.join(' ')} " +
    "/OUT:#{a_exe_name} "

  if a_linker_lists.resources.size
    result << "#{a_target.mxx_all_mswin_rlink_options.join(' ')} "
  end

  a_linker_lists.lib_paths.each { |p| result << "/LIBPATH:#{p} " }

  result << "#{a_linker_lists.objs.join(' ')} "
  result << "#{make_libraries_list_for_linker(a_linker_lists.libs)} "
  result << "#{a_linker_lists.resources.join(' ')} "

  tmpfile = MxxRu::Util::TmpFiles.instance.create( result )

  return [ "#{linker_name} @#{tmpfile}" ]
end

#make_lib_command_lines(lib_name, obj_files, librarian_options, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_lib_command_lines.



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 265

def make_lib_command_lines(
  lib_name,
  obj_files,
  librarian_options,
  target )

  tmpfile = MxxRu::Util::TmpFiles.instance.create(
    "#{librarian_options.join(' ')} " +
    "/OUT:#{lib_name} #{obj_files.join(' ')}" )

  return [ "#{librarian_name} @#{tmpfile}" ]
end

#make_mswin_res_command_lines(res_name, rc_file, rc_options, target) ⇒ Object

See description at MxxRu::Cpp::Toolset#make_mswin_res_command_lines.



243
244
245
246
247
248
249
250
251
252
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 243

def make_mswin_res_command_lines(
  res_name,
  rc_file,
  rc_options,
  target )

  return [ "#{rc_name} " +
    "#{rc_options.join(' ')} /r " +
    "/fo#{res_name} #{rc_file}" ]
end

#mswin_res_file_name(source_name) ⇒ Object

See description at MxxRu::Cpp::Toolset#mswin_res_file_name.



238
239
240
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 238

def mswin_res_file_name( source_name )
  return source_name + ".res"
end

#obj_file_extObject

See description at MxxRu::Cpp::Toolset#obj_file_ext.



205
206
207
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 205

def obj_file_ext
  return ".obj"
end

#rc_nameObject

Returns resource compiler name.



61
62
63
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 61

def rc_name
  return tag( RC_NAME_TAG, "rc" )
end

#setup_mandatory_options(target) ⇒ Object

See description at MxxRu::Cpp::Toolset#setup_mandatory_options.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 74

def setup_mandatory_options( target )

  target.compiler_option( "-nologo" )
  target.linker_option( "/NOLOGO" )
  target.librarian_option( "/NOLOGO" )
  target.cpp_compiler_option( "-EHsc" )

  if RUNTIME_DEBUG == target.mxx_runtime_mode
    target.compiler_option( "-Zi" )
    target.linker_option( "/DEBUG" )
    setup_vc_specific_debug_options( target )
  elsif RUNTIME_RELEASE == target.mxx_runtime_mode
    target.define( "NDEBUG" )
    if OPTIM_SIZE == target.mxx_optimization
      target.compiler_option( "-O1" )
    else
      target.compiler_option( "-O2" )
    end
  end

  if RTTI_ENABLED == target.mxx_rtti_mode
    target.cpp_compiler_option( "-GR" )
  end

  if RTL_SHARED == target.mxx_rtl_mode
    if THREADING_SINGLE == target.mxx_threading_mode
      raise MxxRu::UnsupportedModeEx.new(
        "Visual C++ not support single-threaded shared RTL" )
    else
      if RUNTIME_DEBUG == target.mxx_runtime_mode
        target.compiler_option( "-MDd" )
      else
        target.compiler_option( "-MD" )
      end
    end
  else
    if THREADING_MULTI == target.mxx_threading_mode
      if RUNTIME_DEBUG == target.mxx_runtime_mode
        target.compiler_option( "-MTd" )
      else
        target.compiler_option( "-MT" )
      end
    else
      if RUNTIME_DEBUG == target.mxx_runtime_mode
        target.compiler_option( "-MLd" )
      else
        target.compiler_option( "-ML" )
      end
    end
  end

  if target.target_type.name == DllTargetType::TYPE
    target.compiler_option( "-LD" )
  end

  if SCREEN_WINDOW == target.mxx_screen_mode
    target.linker_option( "/SUBSYSTEM:WINDOWS" )
  else
    target.linker_option( "/SUBSYSTEM:CONSOLE" )
  end

  # All defines and all include_path should be applied
  # to resource compiler too.
  target.mxx_all_defines.each { |d|
    target.compiler_option( "-D" + d )
    target.mswin_rc_option( "/d" + d )
  }

  target.mxx_all_include_paths.each { |p|
    target.compiler_option( "-I" + p )
    target.mswin_rc_option( "/i" + p )
  }

  # Resource compiler specific options.
  target.mxx_all_mswin_rc_defines.each { |d|
    target.mswin_rc_option( "/d" + d )
  }
  target.mxx_all_mswin_rc_include_paths.each { |p|
    target.mswin_rc_option( "/i" + p )
  }

end

#setup_vc_specific_debug_options(target) ⇒ Object

Setting up VC specific options for managing PDB files.

Adding ‘/Fd<full-target-name>.pdb’ option for compiler. Adding ‘/PDB:<full-target-name>.pdb’ option for linker (in case of EXE or DLL).



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/mxx_ru/cpp/toolsets/vc_family.rb', line 393

def setup_vc_specific_debug_options( target )
  full_name =
    case target.target_type.name
      when ExeTargetType::TYPE
        make_exe_name( target.mxx_target_name, target ).full_name
      when DllTargetType::TYPE
        make_dll_name( target.mxx_target_name, target ).full_name
      when LibTargetType::TYPE
        make_lib_name( target.mxx_target_name, target ).full_name
      else nil
    end
  if full_name
    pdb_file = MxxRu::Util::change_file_ext( full_name, ".pdb" )
    target.compiler_option( "/Fd#{pdb_file}" )
    target.linker_option( "/PDB:#{pdb_file}" )
  end
end