Class: AutoC::CMake

Inherits:
Object
  • Object
show all
Defined in:
lib/autoc/cmake.rb

Overview

CMake package renderer for the AutoC module

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(m) ⇒ CMake

Returns a new instance of CMake.



18
# File 'lib/autoc/cmake.rb', line 18

def initialize(m) = @module = m

Instance Attribute Details

#moduleObject (readonly)

Returns the value of attribute module.



14
15
16
# File 'lib/autoc/cmake.rb', line 14

def module
  @module
end

Class Method Details

.render(m) ⇒ Object



34
# File 'lib/autoc/cmake.rb', line 34

def self.render(m) = self.new(m).render

Instance Method Details

#file_nameObject



16
# File 'lib/autoc/cmake.rb', line 16

def file_name = "#{self.module.name}.cmake"

#renderObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/autoc/cmake.rb', line 20

def render
  m = self.module
  sources = self.module.sources.collect { |s| "${CMAKE_CURRENT_SOURCE_DIR}/#{s.file_name}" } .join(' ')
  stream = %{
    set(#{m.name}_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/#{m.header.file_name})
    set(#{m.name}_SOURCES #{sources})
    add_library(#{m.name} OBJECT ${#{m.name}_SOURCES})
    target_include_directories(#{m.name} INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
  }
  unless Digest::MD5.digest(stream) == (Digest::MD5.digest(File.read(file_name)) rescue nil)
    File.write(file_name, stream)
  end
end