require 'mj/tools/subprocess' require 'build-tool/build-system/base' module BuildTool; module BuildSystem # # # class CMake < Base include MJ::Tools::SubProcess class MakeError < BuildTool::Error; end class CMakeError < BuildTool::Error; end def initialize( *args ) super( *args ) @supported_options << 'CMAKE_BUILD_TYPE' << 'CMAKE_CXXFLAGS' << 'CMAKE_VERBOSE_MAKEFILE' << 'LIB_SUFFIX' end # ### ATTRIBUTES # # Check if the module is configured def configured? Pathname.new( build_directory ).join( 'Makefile' ).exist? end def name "cmake" end # ### METHODS # # Configure the module def reconfigure() if File.exist?( "#{build_directory}/CMakeCache.txt" ) return false if self.class.execute( "rm -f #{build_directory}/CMakeCache.txt" ) != 0 end configure end # Execute a cmake command in the context of the build directory def cmake( command, wd = build_directory ) rc = self.class.execute "cmake #{command}", wd, env if rc != 0 raise CMakeError, "cmake failed with error #{rc}!" end rc end def configure check_build_directory( true ) opt = option_string opt += " -DCMAKE_INSTALL_PREFIX=#{install_prefix.to_s}" if install_prefix rc = cmake "#{source_directory} #{opt}" rc end def do_make( target = nil ) rc = self.class.execute( "make #{target ? target : "" }", build_directory, self.module.environment.values ) if rc != 0 raise MakeError, "make #{target || "" } failed with error code #{rc}"; end rc end def install( fast ) if fast make( "install/fast" ) else make( "install" ) end end def install_fast_supported? true end def make( target = nil ) do_make( target ) end def option_string arr = [] option_names.each do |var| val = self[var] arr << "-D#{var}='#{val}'" end arr.join(" ") end end # class CMake end; end # module BuildTool::BuildSystem