Module: Build

Defined in:
lib/canuby/build/cmake.rb,
lib/canuby/build/msbuild.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


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/canuby/build/cmake.rb', line 26

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.



42
43
44
45
46
47
48
49
50
51
# File 'lib/canuby/build/msbuild.rb', line 42

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



26
27
28
29
30
31
32
# File 'lib/canuby/build/msbuild.rb', line 26

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