Class: CKick::Dependencies

Inherits:
Object
  • Object
show all
Includes:
Hashable
Defined in:
lib/ckick/dependencies.rb

Instance Method Summary collapse

Methods included from Hashable

#to_no_empty_value_hash

Constructor Details

#initialize(args = {}) ⇒ Dependencies

Returns a new instance of Dependencies.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ckick/dependencies.rb', line 17

def initialize args={}
  raise IllegalInitializationError unless args.is_a?(Hash)

  cflags = args[:cflags] || []
  raise IllegalInitializationError, "cflags provided to dependencies is not an Array" unless cflags.is_a?(Array)
  @cflags = cflags.collect do |flag|
    CFlag.new(flag: flag)
    end

  cxxflags = args[:cxxflags] || []
  raise IllegalInitializationError, "cxxflags provided to dependencied is not an Array" unless cxxflags.is_a?(Array)
  @cxxflags = cxxflags.collect do |flag|
    CXXFlag.new(flag: flag)
  end

  includes = args[:include] || []
  raise IllegalInitializationError, "include provided to dependencies is not an Array" unless includes.is_a?(Array)
  @include = includes.collect do |include|
    IncludePath.new(path: include)
  end

  libs = args[:lib] || []
  raise IllegalInitializationError, "lib provided to dependencies is not an Array" unless libs.is_a?(Array)
  @lib = libs.collect do |lib|
    LibraryPath.new(path: lib)
  end
end

Instance Method Details

#add_include(path) ⇒ Object



61
62
63
64
# File 'lib/ckick/dependencies.rb', line 61

def add_include(path)
  raise BadIncludePathError, "path must be a CKick::IncludePath object" unless path.is_a?(IncludePath)
  @include << path unless @include.include?(path)
end

#add_lib(path) ⇒ Object



66
67
68
69
# File 'lib/ckick/dependencies.rb', line 66

def add_lib(path)
  raise BadLibraryPathError, "path must be a CKick::LibraryPath object" unless path.is_a?(LibraryPath)
  @lib << path unless @lib.include?(path)
end

#cmakeObject



49
50
51
52
53
# File 'lib/ckick/dependencies.rb', line 49

def cmake
  [@cflags, @cxxflags, @include, @lib].flatten(1).collect do |unit|
      unit.cmake
  end.join("\n")
end

#flagsObject



55
56
57
58
59
# File 'lib/ckick/dependencies.rb', line 55

def flags
  [@cflags, @cxxflags, @include, @lib].flatten(1).uniq.collect do |flag|
    flag.raw_flag
  end
end

#to_hashObject



45
46
47
# File 'lib/ckick/dependencies.rb', line 45

def to_hash
  to_no_empty_value_hash
end