class RBT::Cmake

Public Class Methods

new( use_this_prefix = :guess_prefix, run_already = true ) { || ... } click to toggle source
#

initialize

#
# File lib/rbt/cmake/cmake.rb, line 50
def initialize(
    use_this_prefix = :guess_prefix,
    run_already     = true,
    &block
  )
  reset
  case use_this_prefix
  when :do_not_run_yet
    run_already = false
    use_this_prefix = :guess_prefix
  end
  case run_already
  # ======================================================================= #
  # === :do_not_run_yet
  # ======================================================================= #
  when :do_not_run_yet
    run_already = false
  end
  set_use_this_prefix(use_this_prefix)
  set_base_directory
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    # ===================================================================== #
    # Use it as at the parent object.
    # ===================================================================== #
    if yielded.is_a?(Symbol)
      case yielded
      # =================================================================== #
      # ===  :colourized_and_padded
      # =================================================================== #
      when :colourized_and_padded
        @use_extra_padding_for_the_system_command = true
      else
        e tomato("Not found the following symbol: :#{yielded}")
      end
    elsif yielded.is_a?(Hash)
      set_parent_object(yielded[:self]) if yielded.has_key? :self
      set_use_opn(yielded[:use_opn]) if yielded.has_key? :use_opn
    else
      set_parent_object(yielded)
    end
  end
  run if run_already
end

Public Instance Methods

add_prefix()
append(i) click to toggle source
#

append

This method will simply append data onto the @cmake_string.

NO checking involved, so call it only when you are sure that you want to add this.

Use this method and ONLY this method when you wish to extend the @cmake_string.

#
# File lib/rbt/cmake/cmake.rb, line 225
def append(i)
  @cmake_string << " #{i}"
  @cmake_string.strip! # Clean up too.
  @cmake_string.squeeze!(' ')
end
append_base_directory() click to toggle source
#

append_base_directory

#
# File lib/rbt/cmake/cmake.rb, line 273
def append_base_directory
  append @base_directory
end
Also aliased as: add_prefix
check_if_cmake_is_available( may_we_exit = @may_we_exit ) click to toggle source
#

check_if_cmake_is_available

We must find out whether cmake is available or not.

If it is not available, we must exit, but only if the argument provided allows us to do this.

#
# File lib/rbt/cmake/cmake.rb, line 285
def check_if_cmake_is_available(
    may_we_exit = @may_we_exit
  )
  case may_we_exit
  when :do_not_exit
    may_we_exit = false
  end
  _ = `cmake 2>&1`
  if _.include? 'not found'
    opne swarn('Cmake is not available. Please install `cmake` first.')
    if may_we_exit
      opnwarn 'Exiting now.'
      exit
    end
    return false
  else
    return true
  end
end
Also aliased as: cmake_is_available?
check_if_cmakelists_file_exists?(where = Dir.pwd) click to toggle source
#

check_if_cmakelists_file_exists?

This method checks if a CMakeLists.txt file exists.

#
# File lib/rbt/cmake/cmake.rb, line 189
def check_if_cmakelists_file_exists?(where = Dir.pwd)
  if File.exist? where+'/CMakeLists.txt'
    true
  else
    false
  end
end
cmake_is_available?( may_we_exit = @may_we_exit )
cmake_string()
Alias for: cmake_string?
cmake_string?() click to toggle source
#

cmake_string?

#
# File lib/rbt/cmake/cmake.rb, line 382
def cmake_string? # contains the cmake string.
  @cmake_string
end
create_cmake_file_add_subdirectory(name) click to toggle source
#

create_cmake_file_add_subdirectory

From this point on we list only methods which are to be used to create a cmake file. These should one day be used to automatically create a cmake project.

#
# File lib/rbt/cmake/cmake.rb, line 204
def create_cmake_file_add_subdirectory(name)
end
guess_prefix( of_this_dir = return_pwd ) click to toggle source
#

guess_prefix

The argument ‘of_this_dir` passed to this method should include a ’-‘.

guess_prefix will simply return the new prefix.

#
# File lib/rbt/cmake/cmake.rb, line 169
def guess_prefix(
    of_this_dir = return_pwd
  )
  basename = File.basename(of_this_dir)
  basename = of_this_dir.split('-') if of_this_dir.include? '-'
  _ = programs_dir?.dup
  if of_this_dir.include? '-'
    _ << File.basename(basename.first).capitalize+'/'+basename[1]
  else
    _ << basename
  end
  return _
end
Also aliased as: prefix?, guess_prefix?
guess_prefix?( of_this_dir = return_pwd )
Alias for: guess_prefix
has_been_run?() click to toggle source
#

has_been_run?

#
# File lib/rbt/cmake/cmake.rb, line 352
def has_been_run?
  @has_been_run
end
notify_the_user_which_command_we_will_run() click to toggle source
#

notify_the_user_which_command_we_will_run

This useful method will notify the user which specific command will be run.

#
# File lib/rbt/cmake/cmake.rb, line 408
def notify_the_user_which_command_we_will_run
  orev "Running the following command "\
       "from #{sdir(@current_directory)}#{rev}:"
  e if @use_extra_padding_for_the_system_command
  e cornflowerblue("  #{@cmake_string}")
  e if @use_extra_padding_for_the_system_command
  run_this_system_command_via_io_popen(@cmake_string)
  @has_been_run = true # Keep track of the fact that we already run this once.
end
opnn() click to toggle source
#

opnn

#
Calls superclass method RBT::LeanPrototype#opnn
# File lib/rbt/cmake/cmake.rb, line 308
def opnn
  super(namespace?) if use_opn?
end
prefix?( of_this_dir = return_pwd )
Alias for: guess_prefix
prepend(i) click to toggle source
#

prepend

This will prepend to the cmake string. Best way to use this is via the prefix variable.

#
# File lib/rbt/cmake/cmake.rb, line 237
def prepend(i)
  # ======================================================================= #
  # We must find the position of the 'cmake' string.
  # ======================================================================= #
  if @cmake_string.include? 'cmake'
    start_position = @cmake_string.index('cmake')+('cmake'.size)
    @cmake_string[start_position,0] = ' '+i
  else 
    @cmake_string.prepend(" #{i}")
  end
  @cmake_string.strip! # Clean up too.
  @cmake_string.squeeze!(' ')
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/cmake/cmake.rb, line 101
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @current_directory
  # ======================================================================= #
  @current_directory = return_pwd
  # ======================================================================= #
  # === @cmake_string
  # ======================================================================= #
  @cmake_string      = 'cmake'.dup
  # ======================================================================= #
  # === @may_we_exit
  # ======================================================================= #
  @may_we_exit       = false
  @parent_object     = nil
  @has_been_run      = false
  # ======================================================================= #
  # === @use_opn
  # ======================================================================= #
  @use_opn           = true
  # ======================================================================= #
  # === @use_extra_padding_for_the_system_command
  # ======================================================================= #
  @use_extra_padding_for_the_system_command = false
  set_base_directory(temp_directory?)
end
return_configure_command_that_was_used()
Alias for: cmake_string?
run() click to toggle source
#

run

If you need some examples for a proper cmake string, have a look:

cmake . -DCMAKE_INSTALL_PREFIX=$MY_TEMP/install_test
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
#
# File lib/rbt/cmake/cmake.rb, line 436
def run
  check_if_cmake_is_available
  prepend(use_this_prefix?)
  notify_the_user_which_command_we_will_run
end
run_full( also_run_make_and_make_install = false, full_prefix = prefix? ) click to toggle source
#

run_full

This method will also run “make” and “make install”.

Afterwards, it will invoke CreateProgram, and then AdvancedSymlink.

You probably won’t need this method if you use this class here as part of RBT, but in the event that you also wish to call this class standalone, this code should suffice.

Since Aug 2011 we use the variable @base_directory.

#
# File lib/rbt/cmake/cmake.rb, line 325
def run_full(
    also_run_make_and_make_install = false,
    full_prefix                    = prefix?
  )
  append_base_directory
  run
  if also_run_make_and_make_install
    run_make_command
    run_make_install_command
    # ===================================================================== #
    # === RBT::CreateProgram
    #
    # Next, delegate towards RBT::CreateProgram.
    # ===================================================================== #
    create_program = action(:app_dir_skeleton, full_prefix)
    create_program.create_the_directories
    # ===================================================================== #
    # Since Aug 2011 we also run AdvancedSymlink. @default_prefix
    # must be set when we arrive at this point here.
    # ===================================================================== #
    @advanced_symlink = RBT::AdvancedSymlink.new(full_prefix)
  end
end
run_make_command() click to toggle source
#

run_make_command

#
# File lib/rbt/cmake/cmake.rb, line 391
def run_make_command
  run_this_system_command_via_io_popen 'make'+ERROR_LINE
end
run_make_install_command() click to toggle source
#

run_make_install_command

#
# File lib/rbt/cmake/cmake.rb, line 398
def run_make_install_command
  run_this_system_command_via_io_popen 'make install'+ERROR_LINE
end
run_this_system_command_via_io_popen(i) click to toggle source
#

run_this_system_command_via_io_popen

#
# File lib/rbt/cmake/cmake.rb, line 359
def run_this_system_command_via_io_popen(i)
  io_object = IO.popen(i, {:err => [:child, :out]}).each { |line|
    if @parent_object
      # =================================================================== #
      # In this case, delegate to the parent object.
      # =================================================================== #
      @parent_object.parse_this_line_obtained_via_io_popen(line)
    else
      # =================================================================== #
      # Else, handle everything here in this class.
      # =================================================================== #
      if RBT.const_defined? :ColourizeParser
        line = ColourizeParser.parse_this_line(line)
      end
      e line
    end
  }
  io_object.close
end
set_base_directory( i = ' .' ) click to toggle source
#

set_base_directory

The method set_base_directory sets the variable @base_directory to use. By default, it uses ‘ .’ as its target.

#
# File lib/rbt/cmake/cmake.rb, line 257
def set_base_directory(
    i = ' .'
  )
  @base_directory = i
end
set_full_configure_line(i) click to toggle source
#

set_full_configure_line

This method can be specifically used from the outside.

#
# File lib/rbt/cmake/cmake.rb, line 423
def set_full_configure_line(i)
  @cmake_string = i
end
set_may_we_exit() click to toggle source
#

set_may_we_exit

#
# File lib/rbt/cmake/cmake.rb, line 210
def set_may_we_exit
  @may_we_exit = true # We may exit.
end
set_parent_object(i = nil) click to toggle source
#

set_parent_object

The parent object, presently, may only be of class RBT::Action::Installer or it is simply nil.

#
# File lib/rbt/cmake/cmake.rb, line 135
def set_parent_object(i = nil)
  @parent_object = i
end
set_prefix(i)
Alias for: set_use_this_prefix
set_use_this_prefix(i) click to toggle source
#

set_use_this_prefix

#
# File lib/rbt/cmake/cmake.rb, line 142
def set_use_this_prefix(i)
  case i
  # ======================================================================= #
  # === :guess
  # ======================================================================= #
  when :guess,
       :guess_prefix
    i = guess_prefix
  end
  _ = " -DCMAKE_INSTALL_PREFIX=#{i}"
  @use_this_prefix = _
end
Also aliased as: set_prefix
string()
Alias for: cmake_string?
use_this_prefix?() click to toggle source
#

use_this_prefix?

#
# File lib/rbt/cmake/cmake.rb, line 158
def use_this_prefix?
  @use_this_prefix
end
verbose_run_the_actual_system_command()
we_use_a_build_directory() click to toggle source
#

we_use_a_build_directory

#
# File lib/rbt/cmake/cmake.rb, line 266
def we_use_a_build_directory
  set_base_directory(' ..')
end