Class: BuildTool::BuildSystem::CMake

Inherits:
Base
  • Object
show all
Includes:
MJ::Tools::SubProcess
Defined in:
lib/build-tool/build-system/cmake.rb

Direct Known Subclasses

KdeL10n

Defined Under Namespace

Classes: CMakeError, MakeError

Instance Attribute Summary

Attributes inherited from Base

#defaults, #feature, #module, #out_of_source

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #active?, #after_rebase, #append, #build_directory, #check_build_directory, #dup, #env, #install_prefix, #option_hash, #option_names, #option_set?, #parent, #prepend, #recipe, #remove_build_directory, #set, #source_directory, #to_s

Constructor Details

#initialize(*args) ⇒ CMake

Returns a new instance of CMake.



17
18
19
20
21
22
23
24
# File 'lib/build-tool/build-system/cmake.rb', line 17

def initialize( *args )
    super( *args )
    @supported_options <<
        'CMAKE_BUILD_TYPE' <<
        'CMAKE_CXXFLAGS' <<
        'CMAKE_VERBOSE_MAKEFILE' <<
        'LIB_SUFFIX'
end

Instance Method Details

#cmake(command, wd = build_directory) ⇒ Object

Execute a cmake command in the context of the build directory



52
53
54
55
56
57
58
# File 'lib/build-tool/build-system/cmake.rb', line 52

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

#configureObject



60
61
62
63
64
65
66
# File 'lib/build-tool/build-system/cmake.rb', line 60

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

#configured?Boolean

Check if the module is configured

Returns:

  • (Boolean)


31
32
33
# File 'lib/build-tool/build-system/cmake.rb', line 31

def configured?
    Pathname.new( build_directory ).join( 'Makefile' ).exist?
end

#do_make(target = nil) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/build-tool/build-system/cmake.rb', line 68

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

#install(fast) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/build-tool/build-system/cmake.rb', line 76

def install( fast )
    if fast
        make( "install/fast" )
    else
        make( "install" )
    end
end

#install_fast_supported?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/build-tool/build-system/cmake.rb', line 84

def install_fast_supported?
    true
end

#make(target = nil) ⇒ Object



88
89
90
# File 'lib/build-tool/build-system/cmake.rb', line 88

def make( target = nil )
    do_make( target )
end

#nameObject



35
36
37
# File 'lib/build-tool/build-system/cmake.rb', line 35

def name
    "cmake"
end

#option_stringObject



92
93
94
95
96
97
98
99
# File 'lib/build-tool/build-system/cmake.rb', line 92

def option_string
    arr = []
    option_names.each do |var|
        val = self[var]
        arr << "-D#{var}='#{val}'"
    end
    arr.join(" ")
end

#reconfigureObject

Configure the module



44
45
46
47
48
49
# File 'lib/build-tool/build-system/cmake.rb', line 44

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