rbind 0.0.9 → 0.0.10

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.
@@ -258,9 +258,11 @@ module Rbind
258
258
  end
259
259
 
260
260
  class CMakeListsHelper < HelperBase
261
- def initialize(name,pkg_config=Array.new,libs=Array.new)
261
+ def initialize(name,pkg_config=Array.new,libs=Array.new,gems=Array.new)
262
262
  super(name,pkg_config)
263
263
  @libs = libs
264
+ @gems = gems
265
+ @find_gem = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","find_gem.txt")).read)
264
266
  @find_package = ERB.new(File.open(File.join(File.dirname(__FILE__),"templates","c","find_package.txt")).read)
265
267
  end
266
268
 
@@ -270,6 +272,10 @@ module Rbind
270
272
  end.join("")
271
273
  end
272
274
 
275
+ def find_gems
276
+ @find_gem.result(@gems.instance_eval("binding")) unless @gems.empty?
277
+ end
278
+
273
279
  def libs
274
280
  str = @root.map do |pkg|
275
281
  "${#{pkg.upcase}_LIBS} ${#{pkg.upcase}_LDFLAGS}"
@@ -368,15 +374,18 @@ module Rbind
368
374
 
369
375
  if generate_cmake && !File.exist?(File.join(path,"CMakeLists.txt"))
370
376
  file_cmakelists = File.new(File.join(path,"CMakeLists.txt"),"w")
371
- libs = gem_paths.map do |path|
372
- Dir.glob(File.join(path,"lib*"))
373
- end
374
- cmakelists = CMakeListsHelper.new(@library_name,@pkg_config,@libs+libs)
377
+ cmakelists = CMakeListsHelper.new(@library_name,@pkg_config,@libs,@gems)
375
378
  file_cmakelists.write @erb_cmakelists.result(cmakelists.binding)
376
379
  if !File.exist?(File.join(path,"rbind.pc.in"))
377
380
  file_pkg_config = File.new(File.join(path,"rbind.pc.in"),"w")
378
381
  file_pkg_config.write @erb_pkg_config.result(Kernel.binding)
379
382
  end
383
+
384
+ src_path = File.join(File.dirname(__FILE__),"templates","c","cmake")
385
+ cmake_path = File.join(path,"cmake")
386
+ FileUtils.mkdir_p(cmake_path) if !File.directory?(cmake_path)
387
+ FileUtils.copy(File.join(src_path,"FindGem.cmake"),File.join(cmake_path,"FindGem.cmake"))
388
+ FileUtils.copy(File.join(src_path,"FindRuby.cmake"),File.join(cmake_path,"FindRuby.cmake"))
380
389
  end
381
390
  end
382
391
  end
@@ -4,13 +4,23 @@ require 'erb'
4
4
 
5
5
  module Rbind
6
6
  class GeneratorRuby
7
- @@ruby_default_value_map ||= {"true" => "true","TRUE" => "true", "false" => "false","FALSE" => "false"}
8
- @@ffi_type_map ||= {"char *" => "string","unsigned char" => "uchar" ,"const char *" => "string" }
7
+ class << self
8
+ attr_accessor :ruby_default_value_map
9
+ attr_accessor :on_normalize_type_name
10
+ attr_accessor :ffi_type_map
11
+ end
12
+ self.ruby_default_value_map ||= {"true" => "true","TRUE" => "true", "false" => "false","FALSE" => "false"}
13
+ self.ffi_type_map ||= {"char *" => "string","unsigned char" => "uchar" ,"const char *" => "string" }
14
+
9
15
 
10
16
  def self.keyword?(name)
11
17
  %w{__FILE__ __LINE__ alias and begin BEGIN break case class def defined? do else elsif end END ensure false for if in module next nil not or redo rescue retry return self super then true undef unless until when while yield}.include? name
12
18
  end
13
19
 
20
+ def self.on_normalize_type_name(&block)
21
+ self.on_normalize_type_name = block
22
+ end
23
+
14
24
  def self.normalize_arg_name(name)
15
25
  name = name.to_s.sub(/\A#{RBase.cprefix}?/, "").gsub(/(?<!\A)\p{Lu}/u, '_\0').downcase
16
26
  name = if keyword?(name)
@@ -29,8 +39,8 @@ module Rbind
29
39
  def self.normalize_default_value(parameter)
30
40
  return nil unless parameter.default_value
31
41
  val = if parameter.type.basic_type? || parameter.type.ptr?
32
- if @@ruby_default_value_map.has_key?(parameter.default_value)
33
- @@ruby_default_value_map[parameter.default_value]
42
+ if ruby_default_value_map.has_key?(parameter.default_value)
43
+ ruby_default_value_map[parameter.default_value]
34
44
  elsif parameter.type.name == "float"
35
45
  parameter.default_value.gsub("f","")
36
46
  elsif parameter.type.name == "double"
@@ -77,6 +87,12 @@ module Rbind
77
87
 
78
88
 
79
89
  def self.normalize_type_name(name)
90
+ # custom normalization
91
+ if @on_normalize_type_name
92
+ n = @on_normalize_type_name.call(name)
93
+ return n if n
94
+ end
95
+
80
96
  if name =~ /^u?int\d*$/ || name =~ /^u?int\d+_t$/
81
97
  return "Fixnum"
82
98
  end
@@ -98,7 +114,7 @@ module Rbind
98
114
  end
99
115
 
100
116
  def self.normalize_basic_type_name_ffi(name)
101
- n = @@ffi_type_map[name]
117
+ n = ffi_type_map[name]
102
118
  n ||= name
103
119
  if n =~ /\*/
104
120
  "pointer"
@@ -172,7 +188,7 @@ module Rbind
172
188
  class RBindHelper < HelperBase
173
189
  attr_reader :compact_namespace
174
190
 
175
- def initialize(name, root,compact_namespace=false)
191
+ def initialize(name, root,compact_namespace=true)
176
192
  @compact_namespace = compact_namespace
177
193
  super(name,root)
178
194
  end
@@ -1,27 +1,45 @@
1
1
  cmake_minimum_required(VERSION 2.6)
2
2
  PROJECT(<%= library_name %> CXX)
3
3
 
4
+ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4
5
  include(FindPkgConfig)
5
6
  <%= find_packages %>
6
-
7
+ <%= find_gems%>
7
8
  SET(RBIND_SRC
8
9
  "${CMAKE_CURRENT_SOURCE_DIR}/types.cc"
9
10
  "${CMAKE_CURRENT_SOURCE_DIR}/operations.cc"
10
11
  "${CMAKE_CURRENT_SOURCE_DIR}/conversions.cc")
11
- ADD_LIBRARY(<%= library_name %> SHARED ${RBIND_SRC})
12
12
 
13
- TARGET_LINK_LIBRARIES(<%= library_name %> <%= libs %>)
13
+ add_custom_command(OUTPUT ${RBIND_SRC}
14
+ COMMAND ruby "${CMAKE_CURRENT_SOURCE_DIR}/../rbind.rb")
14
15
 
15
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rbind.pc.in ${CMAKE_CURRENT_BINARY_DIR}/<%= library_name %>.pc @ONLY)
16
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/<%= library_name %>.pc DESTINATION lib/pkgconfig)
16
+ ADD_LIBRARY(<%= library_name %> SHARED ${RBIND_SRC})
17
+ TARGET_LINK_LIBRARIES(<%= library_name %> <%= libs %> ${GEM_LIBRARIES})
17
18
 
18
- install(TARGETS <%= library_name %> LIBRARY DESTINATION lib)
19
- install(FILES types.h operations.h conversions.hpp DESTINATION include/${PROJECT_NAME}/${DIR})
19
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rbind.pc.in ${CMAKE_CURRENT_BINARY_DIR}/<%= library_name %>.pc @ONLY)
20
+ set(ROOT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/..)
20
21
 
21
- if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/extern.rbind)
22
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern.rbind DESTINATION include/${PROJECT_NAME}/${DIR})
23
- endif()
22
+ # global install
23
+ if(GEM_INSTALL)
24
+ # local install
25
+ install(TARGETS <%= library_name %> LIBRARY DESTINATION ${ROOT_FOLDER}/lib/lib)
26
+ install(FILES types.h operations.h conversions.hpp DESTINATION ${ROOT_FOLDER}/lib/include)
27
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern.rbind DESTINATION ${ROOT_FOLDER}/lib/include)
28
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.rbind DESTINATION ${ROOT_FOLDER}/lib/include)
29
+ else()
30
+ # global install
31
+ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/<%= library_name %>.pc DESTINATION lib/pkgconfig)
32
+ install(TARGETS <%= library_name %> LIBRARY DESTINATION lib)
33
+ install(FILES types.h operations.h conversions.hpp DESTINATION include/${PROJECT_NAME})
34
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/extern.rbind DESTINATION include/${PROJECT_NAME})
35
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.rbind DESTINATION include/${PROJECT_NAME})
24
36
 
25
- if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.rbind)
26
- install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.rbind DESTINATION include/${PROJECT_NAME}/${DIR})
37
+ FIND_PACKAGE(Ruby)
38
+ IF(NOT RUBY_INCLUDE_PATH)
39
+ MESSAGE(STATUS "Ruby library not found. Cannot install ruby extensions")
40
+ ELSEIF(NOT RUBY_EXTENSIONS_AVAILABLE)
41
+ STRING(REGEX REPLACE ".*lib(32|64)?/?" "lib/" RUBY_LIBRARY_INSTALL_DIR ${RUBY_RUBY_LIB_PATH})
42
+ INSTALL(DIRECTORY ${ROOT_FOLDER}/lib/ruby DESTINATION ${RUBY_LIBRARY_INSTALL_DIR}
43
+ FILES_MATCHING PATTERN "*.rb")
44
+ ENDIF(NOT RUBY_INCLUDE_PATH)
27
45
  endif()
@@ -0,0 +1,155 @@
1
+ # Author thomas.roehr@dfki.de
2
+ #
3
+ # Version 0.3 2013-07-02
4
+ # - rely on `gem content` to find library and header
5
+ # - introduce GEM_OS_PKG to allow search via pkgconfig
6
+ # Version 0.2 2010-01-14
7
+ # - add support for searching for multiple gems
8
+ # Version 0.1 2010-12-15
9
+ # - support basic search functionality
10
+ # - tested to find rice
11
+ #
12
+ # OUTPUT:
13
+ #
14
+ # GEM_INCLUDE_DIRS After successful search contains the include directores
15
+ #
16
+ # GEM_LIBRARIES After successful search contains the full path of each found library
17
+ #
18
+ #
19
+ # Usage:
20
+ # set(GEM_DEBUG TRUE)
21
+ # find_package(Gem COMPONENTS rice hoe)
22
+ # include_directories(${GEM_INCLUDE_DIRS})
23
+ # target_link_libraries(${GEM_LIBRARIES}
24
+ #
25
+ # in case pkg-config should be used to search for the os pkg, set GEM_OS_PKG, i.e.
26
+ # set(GEM_OS_PKG TRUE)
27
+ #
28
+ # Check for how 'gem' should be called
29
+ find_program(GEM_EXECUTABLE
30
+ NAMES "gem${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}"
31
+ "gem${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}"
32
+ "gem-${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}"
33
+ "gem-${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}"
34
+ "gem${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}"
35
+ "gem${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}"
36
+ "gem-${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}"
37
+ "gem-${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}"
38
+ "gem")
39
+
40
+ # Making backward compatible
41
+ if(Gem_DEBUG)
42
+ set(GEM_DEBUG TRUE)
43
+ endif()
44
+
45
+ if(NOT GEM_EXECUTABLE)
46
+ MESSAGE(FATAL_ERROR "Could not find the gem executable - install 'gem' first")
47
+ endif()
48
+
49
+ if(NOT Gem_FIND_COMPONENTS)
50
+ MESSAGE(FATAL_ERROR "If searching for a Gem you have to provide COMPONENTS with the name of the gem")
51
+ endif()
52
+
53
+ set(GEM_FOUND TRUE)
54
+ foreach(Gem_NAME ${Gem_FIND_COMPONENTS})
55
+ # If the gem is installed as a gem
56
+ if(NOT GEM_OS_PKG)
57
+ set(GEM_HOME ENV{GEM_HOME})
58
+
59
+ # Use `gem content <gem-name>` to extract current information about installed gems
60
+ # Store the information into ${GEM_LOCAL_INFO}
61
+ EXECUTE_PROCESS(COMMAND ${GEM_EXECUTABLE} content ${Gem_NAME} OUTPUT_VARIABLE GEM_LOCAL_INFO)
62
+
63
+ if("${GEM_LOCAL_INFO}" STREQUAL "")
64
+ MESSAGE(FATAL_ERROR "No local gem found. Check your GEM_HOME setting!")
65
+ else()
66
+ set(_library_NAME_PATTERN lib${Gem_NAME}.a
67
+ lib${Gem_NAME}.so
68
+ lib${Gem_NAME}.dylib
69
+ ${Gem_NAME}.a
70
+ ${Gem_NAME}.so
71
+ ${Gem_NAME}.dylib
72
+ .*.a
73
+ .*.so
74
+ .*.dylib
75
+ )
76
+
77
+ set(_header_SUFFIX_PATTERN
78
+ .h
79
+ .hh
80
+ .hpp
81
+ )
82
+
83
+ # Create a list from the output results of the gem command
84
+ string(REPLACE "\n" ";" GEM_CONTENT_LIST ${GEM_LOCAL_INFO})
85
+ foreach(_gem_CONTENT_PATH ${GEM_CONTENT_LIST})
86
+
87
+ # Convert so that only '/' Unix path separator are being using
88
+ # needed to do proper regex matching
89
+ FILE(TO_CMAKE_PATH ${_gem_CONTENT_PATH} gem_CONTENT_PATH)
90
+
91
+ # Identify library -- checking for a library in the gems 'lib' (sub)directory
92
+ # Search for an existing library, but only within the gems folder
93
+ foreach(_library_NAME ${_library_NAME_PATTERN})
94
+ STRING(REGEX MATCH ".*${Gem_NAME}.*/lib/.*${_library_NAME}$" GEM_PATH_INFO "${gem_CONTENT_PATH}")
95
+ if(NOT "${GEM_PATH_INFO}" STREQUAL "")
96
+ list(APPEND GEM_LIBRARIES ${GEM_PATH_INFO})
97
+ break()
98
+ endif()
99
+ endforeach()
100
+
101
+ # Identify headers
102
+ # Checking for available headers in an include directory
103
+ foreach(_header_PATTERN ${_header_SUFFIX_PATTERN})
104
+ STRING(REGEX MATCH ".*${Gem_NAME}.*/include/.*${_header_PATTERN}$" GEM_PATH_INFO "${gem_CONTENT_PATH}")
105
+ if(NOT "${GEM_PATH_INFO}" STREQUAL "")
106
+ STRING(REGEX REPLACE "(.*${Gem_NAME}.*/include/).*${_header_PATTERN}$" "\\1" GEM_PATH_INFO "${gem_CONTENT_PATH}")
107
+ list(APPEND GEM_INCLUDE_DIRS ${GEM_PATH_INFO})
108
+ break()
109
+ endif()
110
+ endforeach()
111
+ endforeach()
112
+
113
+ # Compact the lists
114
+ if(${GEM_LIBRARIES})
115
+ LIST(REMOVE_DUPLICATES GEM_LIBRARIES)
116
+ endif()
117
+ if(${GEM_INCLUDE_DIRS})
118
+ LIST(REMOVE_DUPLICATES GEM_INCLUDE_DIRS)
119
+ endif()
120
+ endif()
121
+ else(NOT GEM_OS_PKG)
122
+ pkg_check_modules(GEM_PKG ${Gem_NAME})
123
+ set(GEM_INCLUDE_DIRS ${GEM_PKG_INCLUDE_DIRS})
124
+ set(GEM_LIBRARIES ${GEM_PKG_LIBRARIES} ${GEM_PKG_STATIC_LIBRARIES})
125
+ list(APPEND GEM_LIBRARIES ${GEM_PKG_LDFLAGS} ${GEM_PKG_STATIC_LDFLAGS})
126
+ list(APPEND GEM_LIBRARIES ${GEM_PKG_LDFLAGS_OTHER} ${GEM_PKG_STATIC_LDFLAGS_OTHER})
127
+
128
+ if(GEM_DEBUG)
129
+ message(STATUS "GEM_OS_PKG is defined")
130
+ message(STATUS "GEM_INCLUDE_DIRS ${GEM_INCLUDE_DIRS}")
131
+ message(STATUS "GEM_STATIC_LIBRARY_DIRS ${GEM_PKG_STATIC_LIBRARY_DIRS}")
132
+ message(STATUS "GEM_LIBRARY_DIRS ${GEM_PKG_STATIC_LIBRARY_DIRS}")
133
+ message(STATUS "GEM_STATIC_LIBRARIES ${GEM_PKG_STATIC_LIBRARIES}")
134
+ message(STATUS "GEM_LIBRARIES ${GEM_LIBRARIES}")
135
+ endif()
136
+ endif()
137
+
138
+ if("${GEM_LIBRARIES}" STREQUAL "")
139
+ set(GEM_FOUND FALSE)
140
+ else()
141
+ MESSAGE(STATUS "Gem: ${Gem_NAME} found")
142
+ endif()
143
+
144
+ if(GEM_DEBUG)
145
+ message(STATUS "${Gem_NAME} library dir: ${GEM_LIBRARIES}")
146
+ message(STATUS "${Gem_NAME} include dir: ${GEM_INCLUDE_DIRS}")
147
+ endif()
148
+
149
+ if(Gem_FIND_REQUIRED)
150
+ if(NOT GEM_FOUND)
151
+ MESSAGE(FATAL_ERROR "Gem: ${Gem_NAME} could not be found")
152
+ endif()
153
+ endif()
154
+ endforeach()
155
+
@@ -0,0 +1,260 @@
1
+ # - Find Ruby
2
+ # This module finds if Ruby is installed and determines where the include files
3
+ # and libraries are. Ruby 1.8 and 1.9 are supported. The minimum required version
4
+ # specified in the find_package() command is honored.
5
+ # It also determines what the name of the library is. This
6
+ # code sets the following variables:
7
+ #
8
+ # RUBY_EXECUTABLE = full path to the ruby binary
9
+ # RUBY_INCLUDE_DIRS = include dirs to be used when using the ruby library
10
+ # RUBY_LIBRARY = full path to the ruby library
11
+ # RUBY_VERSION = the version of ruby which was found, e.g. "1.8.7"
12
+ # RUBY_FOUND = set to true if ruby ws found successfully
13
+ #
14
+ # RUBY_INCLUDE_PATH = same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
15
+
16
+ #=============================================================================
17
+ # Copyright 2004-2009 Kitware, Inc.
18
+ # Copyright 2008-2009 Alexander Neundorf <neundorf@kde.org>
19
+ #
20
+ # Distributed under the OSI-approved BSD License (the "License");
21
+ # see accompanying file Copyright.txt for details.
22
+ #
23
+ # This software is distributed WITHOUT ANY WARRANTY; without even the
24
+ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25
+ # See the License for more information.
26
+ #=============================================================================
27
+ # (To distributed this file outside of CMake, substitute the full
28
+ # License text for the above reference.)
29
+
30
+ # RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"archdir"@:>@)'`
31
+ # RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"sitearchdir"@:>@)'`
32
+ # RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"sitelibdir"@:>@)'`
33
+ # RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"libdir"@:>@)'`
34
+ # RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",RbConfig::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
35
+
36
+ # uncomment the following line to get debug output for this file
37
+ # SET(_RUBY_DEBUG_OUTPUT TRUE)
38
+
39
+ # Determine the list of possible names of the ruby executable depending
40
+ # on which version of ruby is required
41
+ SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${RUBY_PROGRAM_NAME} ruby)
42
+
43
+ # if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8
44
+ IF(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
45
+ SET(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${RUBY_FIND_VERSION_MINOR}")
46
+ ELSE(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
47
+ SET(Ruby_FIND_VERSION_SHORT_NODOT "18")
48
+ ENDIF(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
49
+
50
+ SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.9 ruby19)
51
+
52
+ # if we want a version below 1.9, also look for ruby 1.8
53
+ IF("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
54
+ SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.8 ruby18)
55
+ ENDIF("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
56
+
57
+ FIND_PROGRAM(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})
58
+
59
+
60
+ IF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
61
+ # query the ruby version
62
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['MAJOR']"
63
+ OUTPUT_VARIABLE RUBY_VERSION_MAJOR)
64
+
65
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['MINOR']"
66
+ OUTPUT_VARIABLE RUBY_VERSION_MINOR)
67
+
68
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['TEENY']"
69
+ OUTPUT_VARIABLE RUBY_VERSION_PATCH)
70
+
71
+ # query the different directories
72
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['archdir']"
73
+ OUTPUT_VARIABLE RUBY_ARCH_DIR)
74
+
75
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['arch']"
76
+ OUTPUT_VARIABLE RUBY_ARCH)
77
+
78
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['rubyhdrdir']"
79
+ OUTPUT_VARIABLE RUBY_HDR_DIR)
80
+
81
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['libdir']"
82
+ OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR)
83
+
84
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['rubylibdir']"
85
+ OUTPUT_VARIABLE RUBY_RUBY_LIB_DIR)
86
+
87
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['LIBRUBY_SO']"
88
+ OUTPUT_VARIABLE RUBY_RUBY_LIBRARY)
89
+ STRING(REGEX REPLACE "^lib" "" RUBY_RUBY_LIBRARY "${RUBY_RUBY_LIBRARY}")
90
+ STRING(REGEX REPLACE "\\.so.*" "" RUBY_RUBY_LIBRARY "${RUBY_RUBY_LIBRARY}")
91
+
92
+ # site_ruby
93
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['sitearchdir']"
94
+ OUTPUT_VARIABLE RUBY_SITEARCH_DIR)
95
+
96
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['sitelibdir']"
97
+ OUTPUT_VARIABLE RUBY_SITELIB_DIR)
98
+
99
+ # vendor_ruby available ?
100
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
101
+ OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET)
102
+
103
+ IF(RUBY_HAS_VENDOR_RUBY)
104
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendorlibdir']"
105
+ OUTPUT_VARIABLE RUBY_VENDORLIB_DIR)
106
+
107
+ EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendorarchdir']"
108
+ OUTPUT_VARIABLE RUBY_VENDORARCH_DIR)
109
+ ENDIF(RUBY_HAS_VENDOR_RUBY)
110
+
111
+ # save the results in the cache so we don't have to run ruby the next time again
112
+ SET(RUBY_VERSION_MAJOR ${RUBY_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
113
+ SET(RUBY_VERSION_MINOR ${RUBY_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
114
+ SET(RUBY_VERSION_PATCH ${RUBY_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
115
+ SET(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
116
+ SET(RUBY_HDR_DIR ${RUBY_HDR_DIR} CACHE PATH "The Ruby header dir (1.9)" FORCE)
117
+ SET(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
118
+ SET(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
119
+ SET(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
120
+ SET(RUBY_SITELIB_DIR ${RUBY_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
121
+ SET(RUBY_HAS_VENDOR_RUBY ${RUBY_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
122
+ SET(RUBY_VENDORARCH_DIR ${RUBY_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
123
+ SET(RUBY_VENDORLIB_DIR ${RUBY_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
124
+
125
+ MARK_AS_ADVANCED(
126
+ RUBY_ARCH_DIR
127
+ RUBY_ARCH
128
+ RUBY_HDR_DIR
129
+ RUBY_POSSIBLE_LIB_DIR
130
+ RUBY_RUBY_LIB_DIR
131
+ RUBY_SITEARCH_DIR
132
+ RUBY_SITELIB_DIR
133
+ RUBY_HAS_VENDOR_RUBY
134
+ RUBY_VENDORARCH_DIR
135
+ RUBY_VENDORLIB_DIR
136
+ RUBY_VERSION_MAJOR
137
+ RUBY_VERSION_MINOR
138
+ RUBY_VERSION_PATCH
139
+ )
140
+ ENDIF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
141
+
142
+ # In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling)
143
+ # try to detect which version we found. This is not too good.
144
+ IF(NOT RUBY_VERSION_MAJOR)
145
+ # by default assume 1.8.0
146
+ SET(RUBY_VERSION_MAJOR 1)
147
+ SET(RUBY_VERSION_MINOR 8)
148
+ SET(RUBY_VERSION_PATCH 0)
149
+ # check whether we found 1.9.x
150
+ IF(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
151
+ SET(RUBY_VERSION_MAJOR 1)
152
+ SET(RUBY_VERSION_MINOR 9)
153
+ ENDIF(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
154
+ ENDIF(NOT RUBY_VERSION_MAJOR)
155
+
156
+
157
+ SET(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}")
158
+ SET(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}")
159
+ SET(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}")
160
+
161
+ # Now we know which version we found
162
+ IF(Ruby_FIND_VERSION)
163
+ IF(${RUBY_VERSION} VERSION_LESS ${Ruby_FIND_VERSION})
164
+ # force running ruby the next time again
165
+ SET(RUBY_VERSION_MAJOR "" CACHE PATH "The Ruby major version" FORCE)
166
+ IF(Ruby_FIND_REQUIRED)
167
+ MESSAGE(FATAL_ERROR "Ruby version ${Ruby_FIND_VERSION} required, but only version ${RUBY_VERSION} found.")
168
+ ELSE(Ruby_FIND_REQUIRED)
169
+ IF(NOT Ruby_FIND_QUIETLY)
170
+ MESSAGE(STATUS "Ruby version ${Ruby_FIND_VERSION} required, but only version ${RUBY_VERSION} found.")
171
+ ENDIF(NOT Ruby_FIND_QUIETLY)
172
+ RETURN()
173
+ ENDIF(Ruby_FIND_REQUIRED)
174
+ ENDIF(${RUBY_VERSION} VERSION_LESS ${Ruby_FIND_VERSION})
175
+ ENDIF(Ruby_FIND_VERSION)
176
+
177
+ FIND_PATH(RUBY_INCLUDE_DIR
178
+ NAMES ruby.h
179
+ HINTS
180
+ ${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} )
185
+
186
+ # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
187
+ 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
+ FIND_PATH(RUBY_CONFIG_INCLUDE_DIR
190
+ NAMES ruby/config.h config.h
191
+ HINTS
192
+ ${RUBY_HDR_DIR}/${RUBY_ARCH}
193
+ ${RUBY_ARCH_DIR}
194
+ )
195
+
196
+ SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} )
197
+ ENDIF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR)
198
+
199
+
200
+ # 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})
202
+
203
+ IF(WIN32)
204
+ SET( _RUBY_MSVC_RUNTIME "" )
205
+ IF( MSVC60 )
206
+ SET( _RUBY_MSVC_RUNTIME "60" )
207
+ ENDIF( MSVC60 )
208
+ IF( MSVC70 )
209
+ SET( _RUBY_MSVC_RUNTIME "70" )
210
+ ENDIF( MSVC70 )
211
+ IF( MSVC71 )
212
+ SET( _RUBY_MSVC_RUNTIME "71" )
213
+ ENDIF( MSVC71 )
214
+ IF( MSVC80 )
215
+ SET( _RUBY_MSVC_RUNTIME "80" )
216
+ ENDIF( MSVC80 )
217
+ IF( MSVC90 )
218
+ SET( _RUBY_MSVC_RUNTIME "90" )
219
+ ENDIF( MSVC90 )
220
+
221
+ LIST(APPEND _RUBY_POSSIBLE_LIB_NAMES
222
+ "msvcr${_RUBY_MSVC_RUNTIME}-ruby${RUBY_NODOT_VERSION}"
223
+ "msvcr${_RUBY_MSVC_RUNTIME}-ruby${RUBY_NODOT_VERSION}-static"
224
+ "msvcrt-ruby${RUBY_NODOT_VERSION}"
225
+ "msvcrt-ruby${RUBY_NODOT_VERSION}-static" )
226
+ ENDIF(WIN32)
227
+
228
+ FIND_LIBRARY(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} )
229
+
230
+ INCLUDE(FindPackageHandleStandardArgs)
231
+ SET(_RUBY_REQUIRED_VARS RUBY_EXECUTABLE RUBY_INCLUDE_DIR RUBY_LIBRARY)
232
+ IF(_RUBY_VERSION_SHORT_NODOT GREATER 18)
233
+ LIST(APPEND _RUBY_REQUIRED_VARS RUBY_CONFIG_INCLUDE_DIR)
234
+ ENDIF(_RUBY_VERSION_SHORT_NODOT GREATER 18)
235
+
236
+ IF(_RUBY_DEBUG_OUTPUT)
237
+ MESSAGE(STATUS "--------FindRuby.cmake debug------------")
238
+ MESSAGE(STATUS "_RUBY_POSSIBLE_EXECUTABLE_NAMES: ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}")
239
+ MESSAGE(STATUS "_RUBY_POSSIBLE_LIB_NAMES: ${_RUBY_POSSIBLE_LIB_NAMES}")
240
+ MESSAGE(STATUS "RUBY_ARCH_DIR: ${RUBY_ARCH_DIR}")
241
+ MESSAGE(STATUS "RUBY_HDR_DIR: ${RUBY_HDR_DIR}")
242
+ MESSAGE(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}")
243
+ MESSAGE(STATUS "Found RUBY_VERSION: \"${RUBY_VERSION}\" , short: \"${_RUBY_VERSION_SHORT}\", nodot: \"${_RUBY_VERSION_SHORT_NODOT}\"")
244
+ MESSAGE(STATUS "_RUBY_REQUIRED_VARS: ${_RUBY_REQUIRED_VARS}")
245
+ MESSAGE(STATUS "--------------------")
246
+ ENDIF(_RUBY_DEBUG_OUTPUT)
247
+
248
+ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby DEFAULT_MSG ${_RUBY_REQUIRED_VARS})
249
+
250
+ MARK_AS_ADVANCED(
251
+ RUBY_EXECUTABLE
252
+ RUBY_LIBRARY
253
+ RUBY_INCLUDE_DIR
254
+ RUBY_CONFIG_INCLUDE_DIR
255
+ )
256
+
257
+ # Set some variables for compatibility with previous version of this file
258
+ SET(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR})
259
+ SET(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR})
260
+ SET(RUBY_INCLUDE_PATH ${RUBY_INCLUDE_DIRS})
@@ -0,0 +1,3 @@
1
+ find_package(Gem COMPONENTS REQUIRED <%= self.join(" ") %>)
2
+ include_directories(${GEM_INCLUDE_DIRS})
3
+
@@ -8,7 +8,7 @@ module <%= name %>
8
8
  extend FFI::Library
9
9
 
10
10
  #load library <%= library_name %>
11
- path = Dir.chdir(File.dirname(__FILE__)) do
11
+ path = Dir.chdir(File.join(File.dirname(__FILE__),"..","..","lib")) do
12
12
  path = Dir.glob("lib<%= library_name %>.*").first
13
13
  File.absolute_path(path) if path
14
14
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'rbind'
3
- s.version = '0.0.9'
4
- s.date = '2013-06-30'
3
+ s.version = '0.0.10'
4
+ s.date = '2013-07-02'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Alexander Duda']
7
7
  s.email = ['Alexander.Duda@dfki.de']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-30 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ''
15
15
  email:
@@ -41,9 +41,12 @@ files:
41
41
  - lib/rbind/logger.rb
42
42
  - lib/rbind/rbind.rb
43
43
  - lib/rbind/templates/c/CMakeLists.txt
44
+ - lib/rbind/templates/c/cmake/FindGem.cmake
45
+ - lib/rbind/templates/c/cmake/FindRuby.cmake
44
46
  - lib/rbind/templates/c/consts.h
45
47
  - lib/rbind/templates/c/conversions.cc
46
48
  - lib/rbind/templates/c/conversions.hpp
49
+ - lib/rbind/templates/c/find_gem.txt
47
50
  - lib/rbind/templates/c/find_package.txt
48
51
  - lib/rbind/templates/c/operation_wrapper.cc
49
52
  - lib/rbind/templates/c/operations.cc
@@ -93,4 +96,3 @@ signing_key:
93
96
  specification_version: 3
94
97
  summary: Library for genereating automated ffi-bindings for c/c++ libraries
95
98
  test_files: []
96
- has_rdoc: