class RBT::Cmake

Constants

ERROR_LINE
#

ERROR_LINE

#
NAMESPACE
#

NAMESPACE

#

Public Class Methods

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

initialize

#
# File lib/rbt/cmake/cmake.rb, line 59
def initialize(
    use_this_prefix = :guess_prefix,
    run_already     = true
  )
  reset
  case run_already
  when :do_not_run_yet
    run_already = false
  end
  set_use_this_prefix(use_this_prefix)
  set_base_directory
  if block_given?
    yielded = yield
    # ===================================================================== #
    # Use it as at the parent object.
    # ===================================================================== #
    if 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 209
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 257
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 269
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'
    opnn
    e swarn('Cmake is not available. Please install `cmake` first.')
    if may_we_exit
      opnn; ewarn '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 155
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 393
def cmake_string? # contains the cmake string.
  @cmake_string
end
create_cmake_file_add_executable(add_library) click to toggle source
#

create_cmake_file_add_executable

#
# File lib/rbt/cmake/cmake.rb, line 182
def create_cmake_file_add_executable(add_library)
end
create_cmake_file_add_library(add_library) click to toggle source
#

create_cmake_file_add_library

#
# File lib/rbt/cmake/cmake.rb, line 176
def create_cmake_file_add_library(add_library)
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 170
def create_cmake_file_add_subdirectory(name)
end
guess_prefix( of_this_dir = Dir.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 135
def guess_prefix(
    of_this_dir = Dir.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 = Dir.pwd )
Alias for: guess_prefix
has_been_run?() click to toggle source
#

has_been_run?

#
# File lib/rbt/cmake/cmake.rb, line 363
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

#
# File lib/rbt/cmake/cmake.rb, line 353
def notify_the_user_which_command_we_will_run
  opnn; e 'Running the following command from '+sdir(@current_directory)+':'
  opnn; e "  #{sfancy(@cmake_string)}"
  run_this_system_command_via_io_popen @cmake_string
  @has_been_run = true
end
opnn() click to toggle source
#

opnn

#
Calls superclass method RBT::Base#opnn
# File lib/rbt/cmake/cmake.rb, line 293
def opnn
  super(NAMESPACE) if @use_opn
end
prefix?( of_this_dir = Dir.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 221
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::Base#reset
# File lib/rbt/cmake/cmake.rb, line 88
def reset
  super()
  @cmake_string      = 'cmake'.dup
  @may_we_exit       = false
  @current_directory = return_pwd
  set_base_directory(temp_directory?)
  @parent_object     = nil
  @has_been_run      = false
  @use_opn           = true
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 408
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 310
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 = RBT::CreateProgram.new(
      full_prefix, true, true, true
    )
    create_program.create_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 339
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 346
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 370
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 241
def set_base_directory(
    i = ' .'
  )
  @base_directory = i
end
set_may_we_exit() click to toggle source
#

set_may_we_exit

#
# File lib/rbt/cmake/cmake.rb, line 194
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::Compile or it is simply nil.

#
# File lib/rbt/cmake/cmake.rb, line 105
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 112
def set_use_this_prefix(i)
  case i
  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 124
def use_this_prefix?
  @use_this_prefix
end
we_use_a_build_directory() click to toggle source
#

we_use_a_build_directory

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