Sha256: 59e1d6dc6978b338376e47ddbaf20c1715f199a45fb7f03b3a3e70c86e33a325

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require 'mini_portile2/mini_portile'
require 'open3'

class MiniPortileCMake < MiniPortile
  def configure_prefix
    "-DCMAKE_INSTALL_PREFIX=#{File.expand_path(port_path)}"
  end

  def initialize(name, version, **kwargs)
    super(name, version, **kwargs)
    @cmake_command = kwargs[:cmake_command]
  end

  def configure_defaults
    if MiniPortile.mswin? && generator_available?('NMake')
      ['-G', 'NMake Makefiles']
    elsif MiniPortile.mingw? && generator_available?('MSYS')
      ['-G', 'MSYS Makefiles']
    else
      []
    end
  end

  def configure
    return if configured?

    cache_file = File.join(tmp_path, 'configure.options_cache')
    File.open(cache_file, "w") { |f| f.write computed_options.to_s }

    execute('configure', [cmake_cmd] + computed_options + ["."])
  end

  def configured?
    configure = File.join(work_path, 'configure')
    makefile  = File.join(work_path, 'CMakefile')
    cache_file  = File.join(tmp_path, 'configure.options_cache')

    stored_options  = File.exist?(cache_file) ? File.read(cache_file) : ""
    current_options = computed_options.to_s

    (current_options == stored_options) && newer?(makefile, configure)
  end

  def make_cmd
    return "nmake" if MiniPortile.mswin?
    super
  end

  def cmake_cmd
    (ENV["CMAKE"] || @cmake_command || "cmake").dup
  end

  private

  def generator_available?(generator_type)
    stdout_str, status = Open3.capture2("#{cmake_cmd} --help")

    raise 'Unable to determine whether CMake supports #{generator_type} Makefile generator' unless status.success?

    stdout_str.include?("#{generator_type} Makefiles")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mini_portile2-2.8.3 lib/mini_portile2/mini_portile_cmake.rb