Class: Cxxproject::StaticLibrary
- Inherits:
-
BuildingBlock
- Object
- BuildingBlock
- Cxxproject::StaticLibrary
- Includes:
- HasIncludes, HasLibraries, HasSources
- Defined in:
- lib/cxxproject/buildingblocks/static_library.rb
Constant Summary
Constants included from HasLibraries
HasLibraries::DEPENDENCY, HasLibraries::LIB, HasLibraries::LIB_WITH_PATH, HasLibraries::SEARCH_PATH, HasLibraries::USERLIB
Instance Attribute Summary collapse
-
#whole_archive ⇒ Object
readonly
Returns the value of attribute whole_archive.
Attributes included from HasSources
Attributes inherited from BuildingBlock
#config_files, #config_name, #name, #output_dir, #output_dir_abs, #pre_step, #project_dir, #tags
Instance Method Summary collapse
- #add_grouping_tasks(archive) ⇒ Object
- #additional_path_components ⇒ Object
- #calc_archive_name ⇒ Object
- #calc_command_line ⇒ Object
- #complete_init ⇒ Object
-
#convert_to_rake ⇒ Object
task that will link the given object files to a static lib.
-
#get_archive_name ⇒ Object
relative path.
-
#get_task_name ⇒ Object
full path.
-
#initialize(name, whole_archive = false) ⇒ StaticLibrary
constructor
A new instance of StaticLibrary.
Methods included from HasIncludes
#includes, #local_includes, #set_includes, #set_local_includes
Methods included from HasSources
#add_to_sources_to_build, #additional_object_file_flags, #apply_depfile, #calc_command_line_for_source, #calc_compiler_strings, #calc_dirs_with_files, #collect_sources_and_toolchains, #convert_depfile, #create_object_file_task, #create_object_file_tasks, #define_string, #deps_in_depFiles, #enhance_with_additional_files, #exclude_sources, #get_define_string, #get_dep_file, #get_include_string, #get_object_file, #get_source_type, #get_sources_task_name, #include_string, #no_sources_found, #parse_includes, #prepare_tasks_for_objects, #process_console_output, #set_exclude_sources, #set_source_patterns, #set_sources, #set_tcs4source, #source_patterns, #sources, #tcs4source
Methods included from HasLibraries
#add_lib_element, #add_lib_elements, #lib_elements
Methods inherited from BuildingBlock
#add_output_dir_dependency, #calc_complete_output_dir, #catch_output, #check_config_file, #complete_output_dir, #has_tcs?, #printCmd, #process_result, #read_file_or_empty_string, #remove_empty_strings_and_join, #set_config_files, #set_config_name, #set_name, #set_output_dir, #set_project_dir, #set_tcs, #setup_rake_dependencies, #tcs, #typed_file_task
Methods included from HasDependencies
#add_unique, #all_dependencies, #all_dependencies_recursive, #collect_dependencies, #convert_named_values_to_string, #dependencies, #direct_deps, #helper_dependencies, #resolve_by_name, #set_dependencies, #set_helper_dependencies
Constructor Details
#initialize(name, whole_archive = false) ⇒ StaticLibrary
Returns a new instance of StaticLibrary.
16 17 18 19 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 16 def initialize(name, whole_archive=false) super(name) @whole_archive = whole_archive end |
Instance Attribute Details
#whole_archive ⇒ Object (readonly)
Returns the value of attribute whole_archive.
14 15 16 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 14 def whole_archive @whole_archive end |
Instance Method Details
#add_grouping_tasks(archive) ⇒ Object
121 122 123 124 125 126 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 121 def add_grouping_tasks(archive) namespace 'lib' do desc archive task @name => archive end end |
#additional_path_components ⇒ Object
31 32 33 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 31 def additional_path_components ['libs'] end |
#calc_archive_name ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 75 def calc_archive_name aname = get_archive_name # if @output_dir_abs # prefix = File.rel_from_to_project(@project_dir, @output_dir) # aname = aname[prefix.length..-1] # end return aname end |
#calc_command_line ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 61 def calc_command_line objs = @objects if @output_dir_abs prefix = File.rel_from_to_project(@project_dir, @output_dir) # objs.map! { |m| m[prefix.length..-1] } end archiver = @tcs[:ARCHIVER] cmd = [archiver[:COMMAND]] # ar cmd += archiver[:ARCHIVE_FLAGS].split(" ") cmd += archiver[:FLAGS] cmd << calc_archive_name # -o debug/x.exe cmd += objs end |
#complete_init ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 21 def complete_init() if @output_dir_abs add_lib_element(HasLibraries::LIB, @name, true) add_lib_element(HasLibraries::SEARCH_PATH, File.join(@output_dir, 'libs'), true) else add_lib_element(HasLibraries::LIB_WITH_PATH, File.join(@output_dir,"lib#{@name}.a"), true) end super end |
#convert_to_rake ⇒ Object
task that will link the given object files to a static lib
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 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 86 def convert_to_rake() object_multitask = prepare_tasks_for_objects() archiver = @tcs[:ARCHIVER] res = typed_file_task Rake::Task::LIBRARY, get_task_name => object_multitask do cmd = calc_command_line aname = calc_archive_name Dir.chdir(@project_dir) do FileUtils.rm(aname) if File.exists?(aname) # cmd.map! {|c| c.include?(' ') ? "\"#{c}\"" : c } rd, wr = IO.pipe cmd << { :err => wr, :out => wr } sp = spawn(*cmd) cmd.pop consoleOutput = ProcessHelper.readOutput(sp, rd, wr) process_result(cmd, consoleOutput, @tcs[:ARCHIVER][:ERROR_PARSER], "Creating #{aname}") check_config_file() end end res. = enhance_with_additional_files(res) add_output_dir_dependency(get_task_name, res, true) add_grouping_tasks(get_task_name) setup_rake_dependencies(res, object_multitask) return res end |
#get_archive_name ⇒ Object
relative path
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 35 def get_archive_name() # relative path return @archive_name if @archive_name parts = [@output_dir] if @output_dir_abs parts = [@output_dir_relPath] if @output_dir_relPath parts += additional_path_components() end parts << "lib#{@name}.a" @archive_name = File.join(parts) @archive_name end |
#get_task_name ⇒ Object
full path
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cxxproject/buildingblocks/static_library.rb', line 50 def get_task_name() # full path return @task_name if @task_name parts = [@output_dir] parts << 'libs' if @output_dir_abs parts << "lib#{@name}.a" @task_name = File.join(parts) @task_name = @project_dir + "/" + @task_name unless @output_dir_abs @task_name end |