class RBT::Cmake
Constants
- ERROR_LINE
#¶ ↑
ERROR_LINE
¶ ↑#¶ ↑
Public Class Methods
#¶ ↑
initialize¶ ↑
#¶ ↑
# File lib/rbt/cmake/cmake.rb, line 55 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
#¶ ↑
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
¶ ↑
#¶ ↑
# File lib/rbt/cmake/cmake.rb, line 257 def append_base_directory append @base_directory end
#¶ ↑
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' 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
#¶ ↑
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
#¶ ↑
notify_the_user_which_command_we_will_run
¶ ↑
#¶ ↑
# File lib/rbt/cmake/cmake.rb, line 352 def notify_the_user_which_command_we_will_run opne 'Running the following command from '+sdir(@current_directory)+':' opne " #{sfancy(@cmake_string)}" run_this_system_command_via_io_popen @cmake_string @has_been_run = true end
#¶ ↑
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¶ ↑
#¶ ↑
RBT::Base#reset
# File lib/rbt/cmake/cmake.rb, line 84 def reset super() infer_the_namespace # ======================================================================= # # === @cmake_string # ======================================================================= # @cmake_string = 'cmake'.dup @may_we_exit = false @current_directory = return_pwd @parent_object = nil @has_been_run = false @use_opn = true set_base_directory(temp_directory?) end
#¶ ↑
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 407 def run check_if_cmake_is_available prepend(use_this_prefix?) notify_the_user_which_command_we_will_run end
#¶ ↑
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 309 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::CreateAppDirSkeleton.new( 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_this_system_command_via_io_popen
¶ ↑
#¶ ↑
# File lib/rbt/cmake/cmake.rb, line 369 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
¶ ↑
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_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_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