class RBT::Cmake
Public Class Methods
#¶ ↑
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
#¶ ↑
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
¶ ↑
#¶ ↑
# File lib/rbt/cmake/cmake.rb, line 273 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 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
#¶ ↑
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
#¶ ↑
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
#¶ ↑
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¶ ↑
#¶ ↑
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
#¶ ↑
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
¶ ↑
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_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
¶ ↑
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_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