Class: CKick::Dependencies
- Inherits:
-
Object
- Object
- CKick::Dependencies
- Includes:
- Hashable
- Defined in:
- lib/ckick/dependencies.rb
Overview
Project dependency settings, such as include path, library path, and compiler flags
Instance Method Summary collapse
-
#add_include(path) ⇒ Object
appends include path (-I) with
path
. -
#add_lib(path) ⇒ Object
appends link path (-L) with
path
. -
#cmake ⇒ Object
CMakeLists’s section content.
-
#flags ⇒ Object
compiler flags in an Array.
-
#initialize(args = {}) ⇒ Dependencies
constructor
-
args
- Dependencies hash (directly the CKickfile :dependencies element parsed with keys as Symbol), must be a Hash ====== Input hash keys *:cflags
- C language specific flags, for e.g.
-
-
#to_hash ⇒ Object
converts to Hash (usable in CKickfile).
Methods included from Hashable
Constructor Details
#initialize(args = {}) ⇒ Dependencies
-
args
- Dependencies hash (directly the CKickfile :dependencies element parsed with keys as Symbol), must be a Hash
Input hash keys
-
:cflags
- C language specific flags, for e.g. ‘-std=c89’, ‘-Wall’, etc., must be an Array of String -
:cxxflags
- C++ language specific flags, for e.g. ‘-std=c++11’, ‘-fno-exceptions’, etc., must be an Array of String -
:include
- Array of paths to append the include path (-I compiler option; include_directories() CMake command) -
:lib
- Array of paths to append the link path (-L compiler option; link_directories() CMake command)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ckick/dependencies.rb', line 24 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
appends include path (-I) with path
path
- include path, must be a CKick::IncludePath
74 75 76 77 |
# File 'lib/ckick/dependencies.rb', line 74 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
appends link path (-L) with path
path
- link path, must be a CKick::LibraryPath
82 83 84 85 |
# File 'lib/ckick/dependencies.rb', line 82 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 |
#cmake ⇒ Object
CMakeLists’s section content
58 59 60 61 62 |
# File 'lib/ckick/dependencies.rb', line 58 def cmake [@cflags, @cxxflags, @include, @lib].flatten(1).collect do |unit| unit.cmake end.join("\n") end |
#flags ⇒ Object
compiler flags in an Array
65 66 67 68 69 |
# File 'lib/ckick/dependencies.rb', line 65 def flags [@cflags, @cxxflags, @include, @lib].flatten(1).uniq.collect do |flag| flag.raw_flag end end |
#to_hash ⇒ Object
converts to Hash (usable in CKickfile)
53 54 55 |
# File 'lib/ckick/dependencies.rb', line 53 def to_hash to_no_empty_value_hash end |