Module: Build

Defined in:
lib/canuby/util.rb

Overview

Building related methods

Class Method Summary collapse

Class Method Details

.cmake(gen_short) ⇒ Object

Generate native build projects via CMake.

Canuby currently fully supports these Generators:

- Visual Studio 15 2017


158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/canuby/util.rb', line 158

def self.cmake(gen_short)
  case gen_short
  when '"Visual Studio 15 2017"', 'VS15'
    generator = '"Visual Studio 15 2017"'
  else
    raise ArgumentError, 'Wrong generator supplied!' if generator.nil?
  end
  begin
    Open3.popen2("cmake .. -G #{generator}") do |_stdin, stdout, _status_thread|
      stdout.each_line { |line| logger.debug(line.delete("\n")) }
    end
  rescue StandardError
    raise StandardError, 'Do you have CMake installed?'
  end
end

.msbuild(project, project_file, verbosity = 'm') ⇒ Object

Build a Visual Studio project via MSBUild. Note: only works on Windows!

Verbosity controlls the msbuild verbosity not if it is printed to console. To show the actual output in console run canuby with the debug flag.

Verbosity accepts: q, m, n, d, and diag defaults to q. Higher than m is not recommended.



191
192
193
194
195
196
197
198
199
200
# File 'lib/canuby/util.rb', line 191

def self.msbuild(project, project_file, verbosity = 'm')
  logger.info("Building #{project}...")
  Stage.clean(project)
  build_dir = Paths.build_dir(project)
  mkdir_p build_dir unless Dir.exist?(build_dir)
  Dir.chdir(build_dir) do
    cmake('"Visual Studio 15 2017"')
    vcvars("msbuild #{project_file}.sln /p:Configuration=#{ENV['rel_type']} /p:Platform=Win32  /v:#{verbosity} /nologo")
  end
end

.vcvars(cmd) ⇒ Object

Run command trough vcvars



175
176
177
178
179
180
181
# File 'lib/canuby/util.rb', line 175

def self.vcvars(cmd)
  Open3.popen2("#{ENV['vcvars']} && #{cmd}") do |_stdin, stdout, _status_thread|
    stdout.each_line { |line| logger.debug(line.delete("\n")) }
  end
rescue StandardError
  raise StandardError, "Do you have Visual Studio installed? #{stdout}"
end