Class: Ritsu::Project

Inherits:
Object
  • Object
show all
Includes:
SrcFiles::AddCppFile, SrcFiles::AddCuFile, SrcFiles::AddFragFile, SrcFiles::AddHeaderFile, SrcFiles::AddQtHeaderFile, SrcFiles::AddQtUnit, SrcFiles::AddUiFile, SrcFiles::AddUnit, SrcFiles::AddVertFile, Utility::Accessors, Utility::SingleInstance, Utility::Strings
Defined in:
lib/ritsu/target.rb,
lib/ritsu/project.rb,
lib/ritsu/ext/qt/project.rb,
lib/ritsu/src_files/unit.rb,
lib/ritsu/ext/cuda/project.rb,
lib/ritsu/src_files/cpp_file.rb,
lib/ritsu/targets/executable.rb,
lib/ritsu/src_files/header_file.rb,
lib/ritsu/targets/shared_library.rb,
lib/ritsu/targets/static_library.rb,
lib/ritsu/ext/fake_install/project.rb,
lib/ritsu/ext/qt/src_files/ui_file.rb,
lib/ritsu/ext/cuda/src_files/cu_file.rb,
lib/ritsu/ext/glsl/src_files/frag_file.rb,
lib/ritsu/ext/glsl/src_files/vert_file.rb,
lib/ritsu/ext/qt/src_files/header_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SrcFiles::AddQtUnit

#add_qt_unit, #add_qt_units

Methods included from SrcFiles::AddQtHeaderFile

#add_qt_header_file, #add_qt_header_files

Methods included from SrcFiles::AddCppFile

#add_cpp_file, #add_cpp_files

Methods included from SrcFiles::AddVertFile

#add_vert_file, #add_vert_files

Methods included from SrcFiles::AddFragFile

#add_frag_file, #add_frag_files

Methods included from SrcFiles::AddCuFile

#add_cu_file, #add_cu_files

Methods included from SrcFiles::AddUiFile

#add_ui_file, #add_ui_files

Methods included from SrcFiles::AddHeaderFile

#add_header_file, #add_header_files

Methods included from SrcFiles::AddUnit

#add_unit, #add_units

Methods included from Utility::Accessors

included

Methods included from Utility::Strings

convert_whitespaces_to_spaces, first, is_c_name?, is_underscore_case?, leading_spaces, leading_whitespaces

Methods included from Utility::SingleInstance

included, #initialize

Instance Attribute Details

#cmake_listsObject (readonly)

Returns the value of attribute cmake_lists.



22
23
24
# File 'lib/ritsu/project.rb', line 22

def cmake_lists
  @cmake_lists
end

#config_header_fileObject (readonly)

Returns the value of attribute config_header_file.



23
24
25
# File 'lib/ritsu/project.rb', line 23

def config_header_file
  @config_header_file
end

#config_header_template_fileObject (readonly)

Returns the value of attribute config_header_template_file.



24
25
26
# File 'lib/ritsu/project.rb', line 24

def config_header_template_file
  @config_header_template_file
end

#custom_scriptObject

Returns the value of attribute custom_script.



25
26
27
# File 'lib/ritsu/project.rb', line 25

def custom_script
  @custom_script
end

#external_librariesObject (readonly)

Returns the value of attribute external_libraries.



19
20
21
# File 'lib/ritsu/project.rb', line 19

def external_libraries
  @external_libraries
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/ritsu/project.rb', line 17

def name
  @name
end

#project_dirObject

Returns the value of attribute project_dir.



21
22
23
# File 'lib/ritsu/project.rb', line 21

def project_dir
  @project_dir
end

#src_filesObject (readonly)

Returns the value of attribute src_files.



20
21
22
# File 'lib/ritsu/project.rb', line 20

def src_files
  @src_files
end

#targetsObject (readonly)

Returns the value of attribute targets.



18
19
20
# File 'lib/ritsu/project.rb', line 18

def targets
  @targets
end

Class Method Details

.create(name) {|project| ... } ⇒ Object

Yields:



46
47
48
49
50
# File 'lib/ritsu/project.rb', line 46

def self.create(name)
  project = Project.new(name)
  yield project if block_given?
  project
end

Instance Method Details

#add_cuda_executable(name) {|executable| ... } ⇒ Object

Yields:

  • (executable)


14
15
16
17
18
# File 'lib/ritsu/ext/cuda/project.rb', line 14

def add_cuda_executable(name)
  executable = Ritsu::Targets::Executable.new(name, :project=>self, :cuda_target=>true)
  executable.add_external_library "cuda"
  yield executable if block_given?
end

#add_cuda_shared_library(name) {|shared_library| ... } ⇒ Object

Yields:

  • (shared_library)


20
21
22
23
24
# File 'lib/ritsu/ext/cuda/project.rb', line 20

def add_cuda_shared_library(name)
  shared_library = Ritsu::Targets::SharedLibrary.new(name, :project=>self, :cuda_target=>true)
  shared_library.add_external_library "cuda"
  yield shared_library if block_given?
end

#add_cuda_static_library(name) {|static_library| ... } ⇒ Object

Yields:

  • (static_library)


26
27
28
29
30
# File 'lib/ritsu/ext/cuda/project.rb', line 26

def add_cuda_static_library(name)
  static_library = Ritsu::Targets::StaticLibrary.new(name, :project=>self, :cuda_target=>true)
  static_library.add_external_library "cuda"
  yield static_library if block_given?
end

#add_executable(name) {|executable| ... } ⇒ Object

Yields:

  • (executable)


40
41
42
43
# File 'lib/ritsu/targets/executable.rb', line 40

def add_executable(name)
  executable = Ritsu::Targets::Executable.new(name, :project=>self)
  yield executable if block_given?
end

#add_external_library(name) {|library| ... } ⇒ Object

Yields:

  • (library)


52
53
54
55
56
# File 'lib/ritsu/project.rb', line 52

def add_external_library(name)
  library = ExternalLibrary.new(name)
  yield library if block_given?
  @external_libraries << library
end

#add_shared_library(name) {|shared_library| ... } ⇒ Object

Yields:

  • (shared_library)


34
35
36
37
# File 'lib/ritsu/targets/shared_library.rb', line 34

def add_shared_library(name)
  shared_library = Ritsu::Targets::SharedLibrary.new(name, :project=>self)
  yield shared_library if block_given?
end

#add_static_library(name) {|static_library| ... } ⇒ Object

Yields:

  • (static_library)


28
29
30
31
# File 'lib/ritsu/targets/static_library.rb', line 28

def add_static_library(name)
  static_library = Ritsu::Targets::StaticLibrary.new(name, :project=>self)
  yield static_library if block_given?
end

#compute_src_path(path, options = {}) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ritsu/project.rb', line 66

def compute_src_path(path, options={})
  options = {:relative_to => :src}.merge(options)
  case options[:reltavie_to]
  when :src
    path
  when :absolute
    src_dir = Pathname.new(self.src_dir)
    input_path = Pathname.new(path)
    input_path.relative_path_from(src_dir).to_s
  else
    raise ArgumentError.new("option :relative_to must be either :src or :absolute")
  end
end

#fake_install=(value) ⇒ Object



9
10
11
# File 'lib/ritsu/ext/fake_install/project.rb', line 9

def fake_install=(value)
  @fake_install = value
end

#include_file(filename, options = {}) ⇒ Object



80
81
82
83
# File 'lib/ritsu/project.rb', line 80

def include_file(filename, options={})
  file_content = Ritsu::Utility::Files.read(filename)
  instance_eval(file_content)
end

#initialize_instance(name) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ritsu/project.rb', line 28

def initialize_instance(name)
  if !is_c_name?(name)
    raise ArgumentError.new(
      "the project name must be a valid C name")
  end
  
  @name = name
  @targets = Set.new
  @external_libraries = Set.new
  @src_files = Set.new
  @project_dir = File.expand_path('.')
  @custom_script = ""
  
  @cmake_lists = Ritsu::SrcFiles::ProjectCmakeLists.new(self)
  @config_header_file = Ritsu::SrcFiles::ProjectConfigHeaderFile.new(self)
  @config_header_template_file = Ritsu::SrcFiles::ProjectConfigHeaderTemplateFile.new(self)
end

#performs_fake_install?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/ritsu/ext/fake_install/project.rb', line 5

def performs_fake_install?
  @fake_install ||= false
end

#projectObject



58
59
60
# File 'lib/ritsu/project.rb', line 58

def project
  self
end

#setup_cudaObject



5
6
7
8
9
10
11
12
# File 'lib/ritsu/ext/cuda/project.rb', line 5

def setup_cuda
  add_external_library("cuda") do |e|
    e.cmake_find_script "FIND_PACKAGE(CUDA REQUIRED)"
    e.cmake_depend_script "INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS})"
    e.cuda_depend_script "CUDA_INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS})"
    e.cmake_name "${CUDA_LIBRARIES}"
  end
end

#setup_fake_installObject



13
14
15
# File 'lib/ritsu/ext/fake_install/project.rb', line 13

def setup_fake_install
  @fake_install = true
end

#setup_qtObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ritsu/ext/qt/project.rb', line 5

def setup_qt
  ### Qt ###
  add_external_library("qt") do |e|
    e.cmake_find_script <<-QT_FIND_SCRIPT

FIND_PACKAGE(Qt4 REQUIRED)

MACRO (RITSU_QT4_WRAP_UI outfiles )
  QT4_EXTRACT_OPTIONS(ui_files ui_options ${ARGN})

  FOREACH (it ${ui_files})
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
SET(outfile ${CMAKE_CURRENT_SOURCE_DIR}/ui_${outfile}.h)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
  COMMAND ${QT_UIC_EXECUTABLE}
  ARGS ${ui_options} -o ${outfile} ${infile}
  MAIN_DEPENDENCY ${infile})
SET(${outfiles} ${${outfiles}} ${outfile})
  ENDFOREACH (it)

ENDMACRO (RITSU_QT4_WRAP_UI)

QT_FIND_SCRIPT
    e.cmake_depend_script "INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR})"
    e.cmake_name "${QT_QTCORE_LIBRARY}"
  end

  ### Qt GUI ###
  add_external_library("qtgui") do |e|
    e.cmake_find_script ""
    e.cmake_depend_script "INCLUDE_DIRECTORIES(${QT_QTGUI_INCLUDE_DIR})"
    e.cmake_name "${QT_QTGUI_LIBRARY}"
  end

  ### Qt OpenGL ###
  add_external_library("qtopengl") do |e|
    e.cmake_find_script ""
    e.cmake_depend_script "INCLUDE_DIRECTORIES(${QT_QTOPENGL_INCLUDE_DIR})"
    e.cmake_name "${QT_QTOPENGL_LIBRARY}"
  end
end

#src_dirObject



62
63
64
# File 'lib/ritsu/project.rb', line 62

def src_dir
  project_dir + "/src"
end

#targets_sorted_by_topological_orderObject



148
149
150
151
152
153
# File 'lib/ritsu/target.rb', line 148

def targets_sorted_by_topological_order
  Target.compute_topological_orders
  result = targets.to_a
  result.sort! {|x,y| x.topological_order - y.topological_order}
  result
end

#updateObject



85
86
87
88
89
90
91
92
# File 'lib/ritsu/project.rb', line 85

def update
  src_files.each do |src_file|
    src_file.update
  end
  targets.each do |target|
    target.update
  end
end