rbind 0.0.26 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,15 +4,16 @@ require 'fileutils'
4
4
 
5
5
  module Rbind
6
6
  class GeneratorC
7
-
8
7
  class HelperBase
9
8
  attr_accessor :includes
10
9
  attr_accessor :name
10
+ attr_accessor :extern_types
11
11
 
12
- def initialize(name,root)
12
+ def initialize(name,root,extern_types=Hash.new)
13
13
  @root = root
14
14
  @name = name
15
15
  @includes = []
16
+ @extern_types = extern_types
16
17
  end
17
18
 
18
19
  def wrap_includes
@@ -31,7 +32,7 @@ module Rbind
31
32
  end
32
33
 
33
34
  class TypesHelperHDR < HelperBase
34
- def initialize(name, root)
35
+ def initialize(name, root,extern_types)
35
36
  raise "wrong type #{root}" unless root.is_a? RDataType
36
37
  super
37
38
  @type_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","type_wrapper.h")).read,nil,"-")
@@ -47,6 +48,10 @@ module Rbind
47
48
 
48
49
  def wrap_types
49
50
  str = ""
51
+ @extern_types.each do |type|
52
+ next if type.basic_type?
53
+ str += type_wrapper(type)
54
+ end
50
55
  @root.each_type do |type|
51
56
  next if type.basic_type?
52
57
  str += type_wrapper(type)
@@ -56,7 +61,7 @@ module Rbind
56
61
  end
57
62
 
58
63
  class TypesHelper < HelperBase
59
- def initialize(name, root)
64
+ def initialize(name, root,extern_types)
60
65
  super
61
66
  @type_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","type_delete.h")).read)
62
67
  end
@@ -71,6 +76,10 @@ module Rbind
71
76
 
72
77
  def wrap_types
73
78
  str = ""
79
+ @extern_types.each do |type|
80
+ next if type.basic_type?
81
+ str += type_wrapper(type)
82
+ end
74
83
  @root.each_type do |type|
75
84
  next if type.basic_type?
76
85
  str += type_wrapper(type)
@@ -98,7 +107,7 @@ module Rbind
98
107
  end
99
108
 
100
109
  class ConversionsHelperHDR < HelperBase
101
- def initialize(name,root)
110
+ def initialize(name,root,extern_types)
102
111
  super
103
112
  @type_conversion = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","type_conversion.hpp")).read,nil,'-')
104
113
  @type_typedef = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","type_typedef.h")).read)
@@ -114,6 +123,11 @@ module Rbind
114
123
 
115
124
  def wrap_conversions
116
125
  str = ""
126
+ @extern_types.each do |type|
127
+ str += type_typedef(type) if type.typedef?
128
+ next if type.basic_type?
129
+ str += type_conversion(type)
130
+ end
117
131
  @root.each_type do |type|
118
132
  str += type_typedef(type) if type.typedef?
119
133
  next if type.basic_type?
@@ -124,7 +138,7 @@ module Rbind
124
138
  end
125
139
 
126
140
  class ConversionsHelper < HelperBase
127
- def initialize(name,root)
141
+ def initialize(name,root,extern_types)
128
142
  super
129
143
  @type_conversion = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","type_conversion.cc")).read,nil,'-')
130
144
  end
@@ -135,6 +149,10 @@ module Rbind
135
149
 
136
150
  def wrap_conversions
137
151
  str = ""
152
+ @extern_types.each do |type|
153
+ next if type.basic_type?
154
+ str += type_conversion(type)
155
+ end
138
156
  @root.each_type do |type|
139
157
  next if type.basic_type?
140
158
  str += type_conversion(type)
@@ -144,7 +162,7 @@ module Rbind
144
162
  end
145
163
 
146
164
  class OperationsHDRHelper < HelperBase
147
- def initialize(name,root)
165
+ def initialize(name,root,extern_types)
148
166
  super
149
167
  end
150
168
 
@@ -153,7 +171,7 @@ module Rbind
153
171
  @root.each_container do |type|
154
172
  str2 = ""
155
173
  type.each_operation do |op|
156
- str2 += "#{op.csignature};\n"
174
+ str2 += "RBIND_EXPORTS #{op.csignature};\n"
157
175
  end
158
176
  if !str2.empty?
159
177
  str += "\n\n///methods for #{type.full_name}\n"
@@ -189,6 +207,16 @@ module Rbind
189
207
  "return toC(&rbind_obj_->#{attribute.name},false);"
190
208
  end
191
209
  end
210
+ elsif __getobj__.is_a?(RCastOperation)
211
+ param = if paras.empty?
212
+ "rbind_obj_"
213
+ else
214
+ paras
215
+ end
216
+ str = "#{return_type} *__rbind_temp_ = dynamic_cast<#{return_type}*>(#{param});\n"
217
+ str += "\tif(!__rbind_temp_)\n"
218
+ str += "\t\t throw std::runtime_error(\"Typecast failed, incompatible types\");\n"
219
+ str + "\treturn toC(__rbind_temp_,false);"
192
220
  else
193
221
  fct = if !constructor? && (return_type.name != "void" || return_type.ptr?)
194
222
  # operator+, operator++ etc
@@ -242,7 +270,7 @@ module Rbind
242
270
  end
243
271
 
244
272
 
245
- def initialize(name,root)
273
+ def initialize(name,root,extern_types)
246
274
  super
247
275
  @operation_wrapper = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","operation_wrapper.cc")).read,nil,"-")
248
276
  end
@@ -265,12 +293,16 @@ module Rbind
265
293
  end
266
294
 
267
295
  class CMakeListsHelper < HelperBase
268
- def initialize(name,pkg_config=Array.new,libs=Array.new,gems=Array.new)
296
+ def initialize(name,lib_name,pkg_config=Array.new,libs=Array.new,ruby_path)
269
297
  super(name,pkg_config)
270
298
  @libs = libs
271
- @gems = gems
272
- @find_gem = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","find_gem.txt")).read)
299
+ @library_name = lib_name
273
300
  @find_package = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","find_package.txt")).read)
301
+ @ruby_path = ruby_path
302
+ end
303
+
304
+ def ruby_path
305
+ @ruby_path
274
306
  end
275
307
 
276
308
  def find_packages
@@ -279,10 +311,6 @@ module Rbind
279
311
  end.join("")
280
312
  end
281
313
 
282
- def find_gems
283
- @find_gem.result(@gems.instance_eval("binding")) unless @gems.empty?
284
- end
285
-
286
314
  def libs
287
315
  str = @root.map do |pkg|
288
316
  "${#{pkg.upcase}_LIBS} ${#{pkg.upcase}_LDFLAGS_OTHER}"
@@ -291,7 +319,7 @@ module Rbind
291
319
  end
292
320
 
293
321
  def library_name
294
- name
322
+ @library_name
295
323
  end
296
324
  end
297
325
 
@@ -299,11 +327,11 @@ module Rbind
299
327
  attr_accessor :library_name
300
328
  attr_accessor :libs
301
329
  attr_accessor :pkg_config
302
- attr_accessor :gems
303
330
  attr_accessor :generate_cmake
304
331
  attr_accessor :output_path
332
+ attr_accessor :ruby_path
305
333
 
306
- def initialize(root,library_name)
334
+ def initialize(root,name,library_name)
307
335
  raise "wrong type #{root}" unless root.is_a? RNamespace
308
336
  @root = root
309
337
  @erb_types_hdr = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","types.h")).read)
@@ -315,17 +343,17 @@ module Rbind
315
343
  @erb_conversions_hdr = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","conversions.hpp")).read)
316
344
  @erb_cmakelists = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","CMakeLists.txt")).read)
317
345
  @erb_find_package = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","find_package.txt")).read)
318
- @erb_pkg_config = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","rbind.pc.in")).read)
319
346
  @includes = Array.new
320
347
  @pkg_config= Array.new
321
- @gems = Array.new
322
348
  @library_name = library_name
349
+ @name = name
323
350
  @generate_cmake = true
324
351
  @libs = []
325
352
  end
326
353
 
327
- def generate(path = @output_path)
354
+ def generate(path = @output_path,ruby_path = @ruby_path)
328
355
  @output_path = path
356
+ @ruby_path = ruby_path
329
357
  FileUtils.mkdir_p(path) if path && !File.directory?(path)
330
358
  file_types_hdr = File.new(File.join(path,"types.h"),"w")
331
359
  file_types = File.new(File.join(path,"types.cc"),"w")
@@ -334,64 +362,39 @@ module Rbind
334
362
  file_operations_hdr = File.new(File.join(path,"operations.h"),"w")
335
363
  file_conversions = File.new(File.join(path,"conversions.cc"),"w")
336
364
  file_conversions_hdr = File.new(File.join(path,"conversions.hpp"),"w")
337
- rbind_pkgs = Rbind.rbind_pkgs(@pkg_config)
338
- gem_paths = @gems.map do |gem|
339
- Rbind.gem_path(gem)
340
- end
341
365
 
342
- types_hdr = TypesHelperHDR.new("_#{library_name.upcase}_TYPES_H_",@root)
343
- types_hdr.includes = rbind_pkgs.map do |p|
344
- "<#{p}/types.h>"
345
- end
346
- types_hdr.includes += gem_paths.map do |gem|
347
- "<#{gem}/types.h>"
348
- end
366
+ # mark all extern types which must be wrapped
367
+ extern_types = @root.used_extern_types
368
+
369
+ types_hdr = TypesHelperHDR.new("_#{library_name.upcase}_TYPES_H_",@root,extern_types)
349
370
  file_types_hdr.write @erb_types_hdr.result(types_hdr.binding)
350
371
 
351
- types = TypesHelper.new("types",@root)
372
+ types = TypesHelper.new("types",@root,extern_types)
352
373
  file_types.write @erb_types.result(types.binding)
353
374
 
354
375
  consts = ConstsHelper.new("_#{library_name.upcase}_CONSTS_H_",@root)
355
- consts.includes = rbind_pkgs.map do |p|
356
- "<#{p}/constants.h>"
357
- end
358
- consts.includes += gem_paths.map do |gem|
359
- "<#{gem}/constants.h>"
360
- end
361
376
  file_consts.write @erb_consts.result(consts.binding)
362
377
 
363
- conversions_hdr = ConversionsHelperHDR.new("#{library_name.upcase}_CONVERSIONS_H_",@root)
364
- conversions_hdr.includes = rbind_pkgs.map do |p|
365
- "<#{p}/conversions.hpp>"
366
- end
378
+ conversions_hdr = ConversionsHelperHDR.new("#{library_name.upcase}_CONVERSIONS_H_",@root,extern_types)
367
379
  conversions_hdr.includes += includes
368
- conversions_hdr.includes += gem_paths.map do |gem|
369
- "<#{gem}/conversions.hpp>"
370
- end
371
380
  file_conversions_hdr.write @erb_conversions_hdr.result(conversions_hdr.binding)
372
381
 
373
- conversions = ConversionsHelper.new("conversions",@root)
382
+ conversions = ConversionsHelper.new("conversions",@root,extern_types)
374
383
  file_conversions.write @erb_conversions.result(conversions.binding)
375
384
 
376
- operations_hdr = OperationsHDRHelper.new("_#{library_name.upcase}_OPERATIONS_H_",@root)
385
+ operations_hdr = OperationsHDRHelper.new("_#{library_name.upcase}_OPERATIONS_H_",@root,extern_types)
377
386
  file_operations_hdr.write @erb_operations_hdr.result(operations_hdr.binding)
378
387
 
379
- operations = OperationsHelper.new("operations",@root)
388
+ operations = OperationsHelper.new("operations",@root,extern_types)
380
389
  file_operations.write @erb_operations.result(operations.binding)
381
390
 
382
391
  if generate_cmake && !File.exist?(File.join(path,"CMakeLists.txt"))
383
392
  file_cmakelists = File.new(File.join(path,"CMakeLists.txt"),"w")
384
- cmakelists = CMakeListsHelper.new(@library_name,@pkg_config,@libs,@gems)
393
+ cmakelists = CMakeListsHelper.new(@name,@library_name,@pkg_config,@libs,@ruby_path)
385
394
  file_cmakelists.write @erb_cmakelists.result(cmakelists.binding)
386
- if !File.exist?(File.join(path,"rbind.pc.in"))
387
- file_pkg_config = File.new(File.join(path,"rbind.pc.in"),"w")
388
- file_pkg_config.write @erb_pkg_config.result(Kernel.binding)
389
- end
390
-
391
395
  src_path = File.join(File.dirname(__FILE__),"templates","c","cmake")
392
396
  cmake_path = File.join(path,"cmake")
393
397
  FileUtils.mkdir_p(cmake_path) if !File.directory?(cmake_path)
394
- FileUtils.copy(File.join(src_path,"FindGem.cmake"),File.join(cmake_path,"FindGem.cmake"))
395
398
  FileUtils.copy(File.join(src_path,"FindRuby.cmake"),File.join(cmake_path,"FindRuby.cmake"))
396
399
  end
397
400
  end
@@ -2,11 +2,13 @@ require 'yaml'
2
2
 
3
3
  module Rbind
4
4
  class GeneratorExtern
5
- Config = Struct.new(:ruby_module_name,:file_prefix)
5
+ Config = Struct.new(:ruby_module_name,:file_prefix,:cpath)
6
6
 
7
7
  attr_accessor :output_path
8
8
  attr_accessor :ruby_module_name
9
9
  attr_accessor :file_prefix
10
+ attr_accessor :cpath
11
+
10
12
  def self.normalize_type_name(name)
11
13
  name.gsub('::','.').gsub(" ","")
12
14
  end
@@ -19,10 +21,11 @@ module Rbind
19
21
  @root = root
20
22
  end
21
23
 
22
- def generate(path = @output_path,ruby_module_name = @ruby_module_name,file_prefix = @file_prefix)
24
+ def generate(path = @output_path,ruby_module_name = @ruby_module_name,file_prefix = @file_prefix,cpath=@cpath)
23
25
  @output_path = path
24
26
  @ruby_module_name = ruby_module_name
25
27
  @file_prefix = file_prefix
28
+ @cpath = File.expand_path(cpath)
26
29
  FileUtils.mkdir_p(path) if path && !File.directory?(path)
27
30
  file_extern = File.new(File.join(path,"extern.rbind"),"w")
28
31
  file_config = File.new(File.join(path,"config.rbind"),"w")
@@ -43,6 +46,7 @@ module Rbind
43
46
  @root.each_type do |t|
44
47
  if t.is_a? RClass
45
48
  t.each_operation do |op|
49
+ next if op.is_a? RCastOperation
46
50
  r = if op.return_type
47
51
  GeneratorExtern.normalize_type_name(op.return_type.full_name)
48
52
  end
@@ -56,7 +60,7 @@ module Rbind
56
60
  end
57
61
 
58
62
  file_extern.write("\n")
59
- file_config.write Config.new(ruby_module_name,file_prefix).to_yaml
63
+ file_config.write Config.new(ruby_module_name,file_prefix,@cpath).to_yaml
60
64
  end
61
65
  end
62
66
  end
@@ -170,7 +170,7 @@ module Rbind
170
170
  n.gsub(/^(\w)(.*)/) do
171
171
  $1.upcase+$2
172
172
  end
173
- end.join("")
173
+ end.join("_")
174
174
  end
175
175
 
176
176
  def self.normalize_basic_type_name_ffi(name)
data/lib/rbind/logger.rb CHANGED
@@ -6,7 +6,8 @@ module Rbind
6
6
  def self.extend_object(o)
7
7
  super
8
8
  o.log = ::Logger.new(STDOUT)
9
- o.log.level = ::Logger::INFO
9
+ #o.log.level = ::Logger::INFO
10
+ o.log.level = ::Logger::WARN
10
11
  o.log.progname = o.name
11
12
  o.log.formatter = proc do |severity, datetime, progname, msg|
12
13
  "#{progname}: #{msg}\n"
data/lib/rbind/rbind.rb CHANGED
@@ -8,7 +8,7 @@ module Rbind
8
8
  attr_accessor :includes
9
9
  attr_accessor :name
10
10
  attr_accessor :pkg_config
11
- attr_accessor :gems
11
+ attr_accessor :rbind_pkgs # extern rbind pkgs
12
12
 
13
13
  def self.pkg_paths(pkg_name)
14
14
  out = IO.popen("pkg-config --cflags-only-I #{pkg_name}")
@@ -19,41 +19,21 @@ module Rbind
19
19
  paths
20
20
  end
21
21
 
22
- def self.rbind_pkgs(pkg_names)
23
- pkg_names.find_all do |p|
24
- !!(p =~ /^rbind_.*/)
25
- end
26
- end
27
-
28
- def self.gem_path(gem_name)
29
- # TODO use gem api
30
- out = IO.popen("gem contents #{gem_name}")
31
- out.readlines.each do |line|
32
- return $1 if line =~ /(.*)extern.rbind/
33
- end
34
- raise "Cannot find paths for gem #{gem_name}"
35
- end
36
-
37
- def self.rbind_pkg_paths(pkg_names)
38
- rbind_packages = rbind_pkgs(pkg_names)
39
- rbind_paths = rbind_packages.map do |pkg|
40
- paths = pkg_paths(pkg)
41
- path = paths.find do |p|
42
- File.exist?(File.join(p,pkg,"extern.rbind"))
43
- end
44
- raise "cannot find extern.rbind for rbind package #{pkg}" unless path
45
- File.join(path,pkg)
46
- end
22
+ def self.rbind_pkg_path(name)
23
+ files = Gem.find_files("#{name}/rbind/extern.rbind")
24
+ raise "Cannot find paths for rbind package #{name}" if files.empty?
25
+ File.dirname(files.first)
47
26
  end
48
27
 
49
28
  def initialize(name,parser = DefaultParser.new)
50
- @name = name
29
+ @name = GeneratorRuby.name
51
30
  @includes = []
52
31
  @pkg_config = []
53
- @gems = []
32
+ @rbind_pkgs= []
54
33
  @parser = parser
34
+
55
35
  lib_name = "rbind_#{name.downcase}"
56
- @generator_c = GeneratorC.new(@parser,lib_name)
36
+ @generator_c = GeneratorC.new(@parser,name,lib_name)
57
37
  @generator_ruby = GeneratorRuby.new(@parser,name,lib_name)
58
38
  @generator_extern = GeneratorExtern.new(@parser)
59
39
  end
@@ -90,19 +70,11 @@ module Rbind
90
70
  def parse_extern
91
71
  # extern package are always paresed with the default parser
92
72
  local_parser = DefaultParser.new(parser)
93
- paths = Rbind.rbind_pkg_paths(@pkg_config)
94
- paths.each do |pkg|
95
- config = YAML.load(File.open(File.join(pkg,"config.rbind")).read)
96
- path = File.join(pkg,"extern.rbind")
97
- ::Rbind.log.info "parsing extern rbind pkg file #{path}"
98
- raise "no module name found" if !config.ruby_module_name || config.ruby_module_name.empty?
99
- local_parser.parse(File.open(path).read,config.ruby_module_name)
100
- end
101
- @gems.each do |gem|
102
- path = Rbind.gem_path(gem)
73
+ @rbind_pkgs.each do |pkg|
74
+ path = Rbind.rbind_pkg_path(pkg)
103
75
  config = YAML.load(File.open(File.join(path,"config.rbind")).read)
104
76
  path = File.join(path,"extern.rbind")
105
- ::Rbind.log.info "parsing extern gem file #{path}"
77
+ ::Rbind.log.info "parsing extern rbind file #{path}"
106
78
  local_parser.parse(File.open(path).read,config.ruby_module_name)
107
79
  end
108
80
  self
@@ -127,6 +99,10 @@ module Rbind
127
99
  parser.parse parse_headers_dry(*headers)
128
100
  end
129
101
 
102
+ def parse_header(header)
103
+ parser.parse parse_headers_dry(header)
104
+ end
105
+
130
106
  def build
131
107
  ::Rbind.log.info "build c wrappers"
132
108
  path = File.join(generator_c.output_path,"build")
@@ -146,33 +122,27 @@ module Rbind
146
122
  end
147
123
 
148
124
  def generate(c_path = "src",ruby_path = "ruby/lib/#{name.downcase}")
149
- generate_c c_path
150
- generate_extern c_path
125
+ generate_c c_path,ruby_path
126
+ generate_extern ruby_path,c_path
151
127
  generate_ruby ruby_path
152
128
  end
153
129
 
154
130
  def generate_ruby(path)
155
131
  ::Rbind.log.info "generate ruby ffi wrappers"
156
- paths = Rbind.rbind_pkg_paths(@pkg_config)
157
- modules = paths.map do |pkg|
158
- config = YAML.load(File.open(File.join(pkg,"config.rbind")).read)
159
- config.file_prefix
160
- end
161
- @generator_ruby.required_module_names = modules + gems
132
+ @generator_ruby.required_module_names = rbind_pkgs
162
133
  @generator_ruby.generate(path)
163
134
  end
164
135
 
165
- def generate_c(path)
136
+ def generate_c(path,ruby_path)
166
137
  ::Rbind.log.info "generate c wrappers"
167
138
  @generator_c.includes += includes
168
139
  @generator_c.includes.uniq!
169
140
  @generator_c.pkg_config = pkg_config
170
- @generator_c.gems = gems
171
- @generator_c.generate(path)
141
+ @generator_c.generate(path,ruby_path)
172
142
  end
173
143
 
174
- def generate_extern(path)
175
- @generator_extern.generate(path,@generator_ruby.module_name,@generator_ruby.file_prefix)
144
+ def generate_extern(path,cpath)
145
+ @generator_extern.generate(File.join(path,"rbind"),@generator_ruby.module_name,@generator_ruby.file_prefix,cpath)
176
146
  end
177
147
 
178
148
  def use_namespace(name)
@@ -4,7 +4,6 @@ PROJECT(<%= library_name %> CXX)
4
4
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
5
5
  include(FindPkgConfig)
6
6
  <%= find_packages %>
7
- <%= find_gems%>
8
7
  SET(RBIND_SRC
9
8
  "${CMAKE_CURRENT_SOURCE_DIR}/types.cc"
10
9
  "${CMAKE_CURRENT_SOURCE_DIR}/operations.cc"
@@ -14,31 +13,19 @@ add_custom_command(OUTPUT ${RBIND_SRC}
14
13
  COMMAND ruby "${CMAKE_CURRENT_SOURCE_DIR}/../rbind.rb")
15
14
 
16
15
  ADD_LIBRARY(<%= library_name %> SHARED ${RBIND_SRC})
17
- TARGET_LINK_LIBRARIES(<%= library_name %> <%= libs %> ${GEM_LIBRARIES})
18
-
19
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rbind.pc.in ${CMAKE_CURRENT_BINARY_DIR}/<%= library_name %>.pc @ONLY)
16
+ TARGET_LINK_LIBRARIES(<%= library_name %> <%= libs %>)
20
17
 
21
18
  set(ROOT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/../..)
22
- if(GEM_INSTALL)
23
- # local install
24
- install(TARGETS <%= library_name %> LIBRARY DESTINATION ${ROOT_FOLDER}/lib)
25
- install(FILES types.h operations.h conversions.hpp DESTINATION ${ROOT_FOLDER}/include)
26
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern.rbind DESTINATION ${ROOT_FOLDER}/include)
27
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.rbind DESTINATION ${ROOT_FOLDER}/include)
28
- else()
29
- # global install
30
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/<%= library_name %>.pc DESTINATION lib/pkgconfig)
31
- install(TARGETS <%= library_name %> LIBRARY DESTINATION lib)
32
- install(FILES types.h operations.h conversions.hpp DESTINATION include/${PROJECT_NAME})
33
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern.rbind DESTINATION include/${PROJECT_NAME})
34
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.rbind DESTINATION include/${PROJECT_NAME})
19
+ install(TARGETS <%= library_name %> LIBRARY DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../<%= ruby_path %>)
35
20
 
21
+ # global install
22
+ if(NOT GEM_INSTALL)
36
23
  FIND_PACKAGE(Ruby)
37
24
  IF(NOT RUBY_INCLUDE_PATH)
38
25
  MESSAGE(STATUS "Ruby library not found. Cannot install ruby extensions")
39
26
  ELSE(NOT RUBY_INCLUDE_PATH)
40
- STRING(REGEX REPLACE ".*lib(32|64)?/?" "lib/" RUBY_LIBRARY_INSTALL_DIR ${RUBY_RUBY_LIB_PATH})
41
- INSTALL(DIRECTORY ${ROOT_FOLDER}/lib/ DESTINATION ${RUBY_LIBRARY_INSTALL_DIR}
42
- FILES_MATCHING PATTERN "*.rb")
27
+ STRING(REGEX REPLACE ".*lib(32|64)?/?" "lib/" RUBY_LIBRARY_INSTALL_DIR ${RUBY_RUBY_LIB_DIR})
28
+ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../lib/ DESTINATION ${RUBY_LIBRARY_INSTALL_DIR}
29
+ FILES_MATCHING PATTERN "*.rb" PATTERN "*.rbind" PATTERN "*.so" PATTERN "*.dylib")
43
30
  ENDIF(NOT RUBY_INCLUDE_PATH)
44
- endif()
31
+ ENDIF(NOT GEM_INSTALL)
@@ -77,6 +77,8 @@ IF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
77
77
 
78
78
  EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['rubyhdrdir']"
79
79
  OUTPUT_VARIABLE RUBY_HDR_DIR)
80
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['rubyarchhdrdir']"
81
+ OUTPUT_VARIABLE RUBY_ARCH_HDR_DIR)
80
82
 
81
83
  EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['libdir']"
82
84
  OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR)
@@ -114,6 +116,7 @@ IF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
114
116
  SET(RUBY_VERSION_PATCH ${RUBY_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
115
117
  SET(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
116
118
  SET(RUBY_HDR_DIR ${RUBY_HDR_DIR} CACHE PATH "The Ruby header dir (1.9)" FORCE)
119
+ SET(RUBY_ARCH_HDR_DIR ${RUBY_ARCH_HDR_DIR} CACHE PATH "The Ruby header dir for architecture-specific files (1.9)" FORCE)
117
120
  SET(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
118
121
  SET(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
119
122
  SET(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
@@ -178,27 +181,26 @@ FIND_PATH(RUBY_INCLUDE_DIR
178
181
  NAMES ruby.h
179
182
  HINTS
180
183
  ${RUBY_HDR_DIR}
181
- ${RUBY_ARCH_DIR}
182
- /usr/lib/ruby/${_RUBY_VERSION_SHORT}/i586-linux-gnu/ )
183
-
184
- SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} )
184
+ ${RUBY_ARCH_DIR})
185
+ set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR})
185
186
 
186
187
  # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
187
188
  IF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR)
188
- message(STATUS "lookign for config.h")
189
+ message(STATUS "FindRuby: looking for config.h")
189
190
  FIND_PATH(RUBY_CONFIG_INCLUDE_DIR
190
191
  NAMES ruby/config.h config.h
191
192
  HINTS
192
193
  ${RUBY_HDR_DIR}/${RUBY_ARCH}
194
+ ${RUBY_ARCH_HDR_DIR}
193
195
  ${RUBY_ARCH_DIR}
194
196
  )
195
197
 
196
- SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} )
198
+ list(APPEND RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR})
197
199
  ENDIF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR)
198
200
 
199
201
 
200
202
  # Determine the list of possible names for the ruby library
201
- SET(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT} ${RUBY_RUBY_LIBRARY})
203
+ SET(_RUBY_POSSIBLE_LIB_NAMES ruby${_RUBY_VERSION_SHORT} ${RUBY_RUBY_LIBRARY} ruby ruby-static)
202
204
 
203
205
  IF(WIN32)
204
206
  SET( _RUBY_MSVC_RUNTIME "" )
@@ -225,7 +227,10 @@ IF(WIN32)
225
227
  "msvcrt-ruby${RUBY_NODOT_VERSION}-static" )
226
228
  ENDIF(WIN32)
227
229
 
228
- FIND_LIBRARY(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} )
230
+ FIND_LIBRARY(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} NO_DEFAULT_PATH)
231
+ if(NOT RUBY_LIBRARY)
232
+ FIND_LIBRARY(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR})
233
+ endif()
229
234
 
230
235
  INCLUDE(FindPackageHandleStandardArgs)
231
236
  SET(_RUBY_REQUIRED_VARS RUBY_EXECUTABLE RUBY_INCLUDE_DIR RUBY_LIBRARY)
@@ -236,7 +241,9 @@ ENDIF(_RUBY_VERSION_SHORT_NODOT GREATER 18)
236
241
  IF(_RUBY_DEBUG_OUTPUT)
237
242
  MESSAGE(STATUS "--------FindRuby.cmake debug------------")
238
243
  MESSAGE(STATUS "_RUBY_POSSIBLE_EXECUTABLE_NAMES: ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}")
244
+ MESSAGE(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}")
239
245
  MESSAGE(STATUS "_RUBY_POSSIBLE_LIB_NAMES: ${_RUBY_POSSIBLE_LIB_NAMES}")
246
+ MESSAGE(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}")
240
247
  MESSAGE(STATUS "RUBY_ARCH_DIR: ${RUBY_ARCH_DIR}")
241
248
  MESSAGE(STATUS "RUBY_HDR_DIR: ${RUBY_HDR_DIR}")
242
249
  MESSAGE(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}")
@@ -1,6 +1,6 @@
1
1
 
2
2
  #include "conversions.hpp"
3
- #include "operations.h"
3
+ #include "operations.h"
4
4
  <%= wrap_includes %>
5
5
 
6
6
  char last_error_message[255] = {0};
@@ -1,5 +1,8 @@
1
1
  #ifndef <%= name %>
2
2
  #define <%= name %>
3
+
4
+ #include "types.h"
5
+
3
6
  <%= wrap_includes %>
4
7
 
5
8
  #ifdef __cplusplus
@@ -8,9 +11,9 @@ extern "C"
8
11
  #endif
9
12
 
10
13
  // general rbind functions
11
- const char* rbindGetLastError();
12
- bool rbindHasError();
13
- void rbindClearError();
14
+ RBIND_EXPORTS const char* rbindGetLastError();
15
+ RBIND_EXPORTS bool rbindHasError();
16
+ RBIND_EXPORTS void rbindClearError();
14
17
 
15
18
  <%= wrap_operations %>
16
19
 
@@ -8,5 +8,5 @@ typedef struct <%= cname %>
8
8
  bool bowner; // true if struct is the owner of the object
9
9
  }<%= cname %>;
10
10
 
11
- void <%= cdelete_method %>(<%= cname %> *ptr);
11
+ RBIND_EXPORTS void <%= cdelete_method %>(<%= cname %> *ptr);
12
12
 
@@ -1,7 +1,16 @@
1
1
  #ifndef <%= name %>
2
2
  #define <%= name %>
3
3
 
4
+ #if (defined WIN32 || defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS
5
+ # define RBIND_EXPORTS __declspec(dllexport)
6
+ #elif defined __GNUC__ && __GNUC__ >= 4
7
+ # define RBIND_EXPORTS __attribute__ ((visibility ("default")))
8
+ #else
9
+ # define RBIND_EXPORTS
10
+ #endif
11
+
4
12
  #include <cstddef>
13
+
5
14
  <%= wrap_includes %>
6
15
 
7
16
  #ifdef __cplusplus