Class: Options

Inherits:
Object
  • Object
show all
Defined in:
ext/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(cmake = "cmake") ⇒ Options

Returns a new instance of Options.



2
3
4
5
6
7
# File 'ext/options.rb', line 2

def initialize(cmake="cmake")
  @cmake = cmake
  @options = {}

  configure
end

Instance Method Details

#cmake_optionsObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'ext/options.rb', line 16

def cmake_options
  return @cmake_options if @cmake_options

  output = nil
  Dir.chdir __dir__ do
    output = `#{@cmake.shellescape} -S sources -B build -L`
  end
  @cmake_options = output.lines.drop_while {|line| line.chomp != "-- Cache values"}.drop(1)
                     .filter_map {|line|
                       option, value = line.chomp.split("=", 2)
                       name, type = option.split(":", 2)
                       [
                         name,
                         [
                           type,
                           type == "BOOL" ? value == "ON" : value
                         ]
                       ]
                     }.to_h
end

#to_sObject



9
10
11
12
13
14
# File 'ext/options.rb', line 9

def to_s
  @options
    .reject {|name, (type, value)| value.nil?}
    .collect {|name, (type, value)| "-D #{name}=#{value == true ? "ON" : value == false ? "OFF" : value.shellescape}"}
    .join(" ")
end