rice 4.7.0 → 4.8.0

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.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -1
  3. data/CMakeLists.txt +14 -22
  4. data/CMakePresets.json +203 -75
  5. data/FindRuby.cmake +358 -123
  6. data/bin/rice-doc.rb +56 -142
  7. data/bin/rice-rbs.rb +1 -2
  8. data/include/rice/api.hpp +248 -0
  9. data/include/rice/rice.hpp +2281 -1668
  10. data/include/rice/stl.hpp +364 -443
  11. data/lib/rice/doc/config.rb +70 -0
  12. data/lib/rice/doc/cpp_reference.rb +1 -4
  13. data/lib/rice/doc/mkdocs.rb +58 -20
  14. data/lib/rice/doc/rice.rb +20 -0
  15. data/lib/rice/doc.rb +1 -0
  16. data/lib/rice/make_rice_headers.rb +7 -0
  17. data/lib/rice/native_registry.rb +2 -2
  18. data/lib/rice/rbs.rb +4 -4
  19. data/lib/rice/version.rb +1 -1
  20. data/lib/rubygems_plugin.rb +12 -9
  21. data/rice/Arg.hpp +12 -6
  22. data/rice/Arg.ipp +14 -7
  23. data/rice/Buffer.ipp +44 -40
  24. data/rice/Callback.hpp +1 -1
  25. data/rice/Callback.ipp +2 -7
  26. data/rice/Constructor.hpp +1 -1
  27. data/rice/Constructor.ipp +11 -11
  28. data/rice/Data_Object.ipp +59 -30
  29. data/rice/Data_Type.hpp +9 -10
  30. data/rice/Data_Type.ipp +22 -25
  31. data/rice/Director.hpp +1 -0
  32. data/rice/Enum.ipp +58 -39
  33. data/rice/Exception.hpp +4 -4
  34. data/rice/Exception.ipp +7 -7
  35. data/rice/NoGVL.hpp +13 -0
  36. data/rice/Reference.hpp +56 -0
  37. data/rice/Reference.ipp +96 -0
  38. data/rice/Return.hpp +4 -1
  39. data/rice/Return.ipp +0 -6
  40. data/rice/cpp_api/Array.hpp +44 -7
  41. data/rice/cpp_api/Array.ipp +105 -9
  42. data/rice/cpp_api/Class.hpp +2 -2
  43. data/rice/cpp_api/Class.ipp +4 -4
  44. data/rice/cpp_api/Hash.ipp +7 -4
  45. data/rice/cpp_api/Module.hpp +4 -4
  46. data/rice/cpp_api/Module.ipp +12 -10
  47. data/rice/cpp_api/Object.hpp +4 -4
  48. data/rice/cpp_api/Object.ipp +15 -12
  49. data/rice/cpp_api/String.hpp +2 -2
  50. data/rice/cpp_api/String.ipp +11 -8
  51. data/rice/cpp_api/Symbol.ipp +16 -7
  52. data/rice/cpp_api/shared_methods.hpp +5 -9
  53. data/rice/detail/InstanceRegistry.hpp +0 -2
  54. data/rice/detail/Native.hpp +31 -21
  55. data/rice/detail/Native.ipp +281 -133
  56. data/rice/detail/NativeAttributeGet.hpp +5 -7
  57. data/rice/detail/NativeAttributeGet.ipp +26 -26
  58. data/rice/detail/NativeAttributeSet.hpp +2 -4
  59. data/rice/detail/NativeAttributeSet.ipp +20 -16
  60. data/rice/detail/NativeCallback.hpp +77 -0
  61. data/rice/detail/NativeCallback.ipp +280 -0
  62. data/rice/detail/NativeFunction.hpp +11 -21
  63. data/rice/detail/NativeFunction.ipp +58 -119
  64. data/rice/detail/NativeInvoker.hpp +4 -4
  65. data/rice/detail/NativeInvoker.ipp +7 -7
  66. data/rice/detail/NativeIterator.hpp +2 -4
  67. data/rice/detail/NativeIterator.ipp +18 -14
  68. data/rice/detail/NativeMethod.hpp +10 -20
  69. data/rice/detail/NativeMethod.ipp +54 -114
  70. data/rice/detail/NativeProc.hpp +5 -7
  71. data/rice/detail/NativeProc.ipp +39 -28
  72. data/rice/detail/NativeRegistry.hpp +0 -1
  73. data/rice/detail/NativeRegistry.ipp +0 -1
  74. data/rice/detail/Parameter.hpp +15 -8
  75. data/rice/detail/Parameter.ipp +102 -43
  76. data/rice/detail/Proc.ipp +14 -28
  77. data/rice/detail/RubyType.ipp +2 -53
  78. data/rice/detail/Type.hpp +23 -7
  79. data/rice/detail/Type.ipp +73 -93
  80. data/rice/detail/TypeRegistry.ipp +5 -4
  81. data/rice/detail/Wrapper.hpp +1 -1
  82. data/rice/detail/Wrapper.ipp +18 -10
  83. data/rice/detail/from_ruby.hpp +8 -6
  84. data/rice/detail/from_ruby.ipp +306 -173
  85. data/rice/detail/ruby.hpp +23 -0
  86. data/rice/libc/file.hpp +4 -4
  87. data/rice/rice.hpp +6 -8
  88. data/rice/rice_api/Native.ipp +5 -1
  89. data/rice/rice_api/Parameter.ipp +1 -1
  90. data/rice/ruby_mark.hpp +2 -1
  91. data/rice/stl/complex.ipp +12 -8
  92. data/rice/stl/map.ipp +27 -22
  93. data/rice/stl/monostate.ipp +16 -12
  94. data/rice/stl/multimap.hpp +0 -2
  95. data/rice/stl/multimap.ipp +27 -22
  96. data/rice/stl/optional.ipp +27 -11
  97. data/rice/stl/pair.ipp +5 -5
  98. data/rice/stl/reference_wrapper.ipp +5 -4
  99. data/rice/stl/set.ipp +16 -16
  100. data/rice/stl/shared_ptr.hpp +0 -16
  101. data/rice/stl/shared_ptr.ipp +34 -190
  102. data/rice/stl/string.ipp +18 -18
  103. data/rice/stl/string_view.ipp +19 -1
  104. data/rice/stl/tuple.ipp +15 -36
  105. data/rice/stl/unique_ptr.ipp +18 -8
  106. data/rice/stl/unordered_map.ipp +20 -15
  107. data/rice/stl/variant.ipp +37 -21
  108. data/rice/stl/vector.ipp +41 -36
  109. data/rice/traits/function_traits.hpp +19 -19
  110. data/rice/traits/method_traits.hpp +4 -4
  111. data/rice/traits/rice_traits.hpp +162 -39
  112. data/rice.gemspec +1 -4
  113. data/test/test_Array.cpp +261 -3
  114. data/test/test_Attribute.cpp +6 -3
  115. data/test/test_Buffer.cpp +6 -42
  116. data/test/test_Callback.cpp +77 -23
  117. data/test/test_Data_Object.cpp +2 -2
  118. data/test/test_Data_Type.cpp +23 -23
  119. data/test/test_Director.cpp +2 -4
  120. data/test/test_Enum.cpp +34 -5
  121. data/test/test_File.cpp +9 -5
  122. data/test/test_From_Ruby.cpp +7 -6
  123. data/test/test_GVL.cpp +3 -3
  124. data/test/test_Hash.cpp +1 -1
  125. data/test/test_Iterator.cpp +54 -22
  126. data/test/test_Keep_Alive.cpp +1 -1
  127. data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
  128. data/test/test_Module.cpp +5 -5
  129. data/test/test_Overloads.cpp +395 -50
  130. data/test/test_Proc.cpp +54 -0
  131. data/test/test_Reference.cpp +181 -0
  132. data/test/test_Self.cpp +2 -2
  133. data/test/test_Stl_Set.cpp +6 -6
  134. data/test/test_Stl_SharedPtr.cpp +54 -30
  135. data/test/test_Stl_String_View.cpp +12 -0
  136. data/test/test_Stl_Tuple.cpp +1 -1
  137. data/test/test_Stl_Variant.cpp +6 -14
  138. data/test/test_Stl_Vector.cpp +61 -30
  139. data/test/test_String.cpp +4 -2
  140. data/test/test_Struct.cpp +1 -1
  141. data/test/test_Symbol.cpp +12 -0
  142. data/test/test_To_Ruby.cpp +1 -0
  143. data/test/test_Type.cpp +36 -35
  144. data/test/test_global_functions.cpp +1 -1
  145. data/test/unittest.cpp +1 -1
  146. data/test/unittest.hpp +5 -5
  147. metadata +10 -24
  148. data/rice/Function.hpp +0 -17
  149. data/rice/Function.ipp +0 -13
  150. data/rice/detail/MethodInfo.hpp +0 -48
  151. data/rice/detail/MethodInfo.ipp +0 -99
  152. data/rice/detail/NativeCallbackFFI.hpp +0 -55
  153. data/rice/detail/NativeCallbackFFI.ipp +0 -152
  154. data/rice/detail/NativeCallbackSimple.hpp +0 -30
  155. data/rice/detail/NativeCallbackSimple.ipp +0 -29
data/FindRuby.cmake CHANGED
@@ -5,65 +5,91 @@
5
5
  FindRuby
6
6
  --------
7
7
 
8
- This module determines if Ruby is installed and finds the locations of its
9
- include files and libraries. Ruby 1.8 through 3.4 are supported.
10
-
11
- The minimum required version of Ruby can be specified using the
12
- standard syntax, e.g.
8
+ Finds Ruby installation and the locations of its include files and libraries:
13
9
 
14
10
  .. code-block:: cmake
15
11
 
16
- find_package(Ruby 3.2.6 EXACT REQUIRED)
17
- # OR
18
- find_package(Ruby 3.2)
12
+ find_package(Ruby [<version>] [COMPONENTS <components>...] [...])
13
+
14
+ Ruby is a general-purpose programming language. This module supports Ruby
15
+ 1.8 through 3.4. Virtual environments, such as RVM or RBENV, are also
16
+ supported.
17
+
18
+ Components
19
+ ^^^^^^^^^^
20
+
21
+ This module supports the following components:
22
+
23
+ ``Interpreter``
24
+ The Ruby interpreter executable.
25
+
26
+ ``Development``
27
+ Headers and libraries needed to build Ruby extensions or embed Ruby.
19
28
 
20
- Virtual environments, such as RVM or RBENV, are supported.
29
+ If no components are specified, both ``Interpreter`` and ``Development``
30
+ are searched for.
31
+
32
+ Imported Targets
33
+ ^^^^^^^^^^^^^^^^
34
+
35
+ This module defines the following :prop_tgt:`IMPORTED` targets:
36
+
37
+ ``Ruby::Interpreter``
38
+ Ruby interpreter. Target defined if component ``Interpreter`` is found.
39
+
40
+ ``Ruby::Ruby``
41
+ Ruby library for embedding Ruby in C/C++ applications.
42
+ Target defined if component ``Development`` is found.
43
+
44
+ ``Ruby::Module``
45
+ Ruby library for building Ruby extension modules.
46
+ Target defined if component ``Development`` is found.
47
+ Use this target when creating native extensions that will be
48
+ loaded into Ruby via ``require``. On most platforms, extension
49
+ modules do not link directly to libruby. Includes appropriate
50
+ symbol visibility settings.
21
51
 
22
52
  Result Variables
23
53
  ^^^^^^^^^^^^^^^^
24
54
 
25
- This module will set the following variables in your project:
55
+ This module defines the following variables:
26
56
 
27
57
  ``Ruby_FOUND``
28
- set to true if ruby was found successfully
29
- ``Ruby_EXECUTABLE``
30
- full path to the ruby binary
31
- ``Ruby_INCLUDE_DIRS``
32
- include dirs to be used when using the ruby library
33
- ``Ruby_LIBRARIES``
34
- .. versionadded:: 3.18
35
- libraries needed to use ruby from C.
58
+ .. versionadded:: 3.3
59
+
60
+ Boolean indicating whether (the requested version of) ruby was found.
61
+
36
62
  ``Ruby_VERSION``
37
- the version of ruby which was found, e.g. "3.2.6"
63
+ The version of ruby which was found, e.g. ``3.2.6``.
64
+
38
65
  ``Ruby_VERSION_MAJOR``
39
66
  Ruby major version.
67
+
40
68
  ``Ruby_VERSION_MINOR``
41
69
  Ruby minor version.
70
+
42
71
  ``Ruby_VERSION_PATCH``
43
72
  Ruby patch version.
44
73
 
45
- .. versionchanged:: 3.18
46
- Previous versions of CMake used the ``RUBY_`` prefix for all variables.
74
+ ``Ruby_EXECUTABLE``
75
+ The full path to the ruby binary.
47
76
 
48
- .. deprecated:: 4.0
49
- The following variables are deprecated. See policy :policy:`CMP0185`.
77
+ ``Ruby_INCLUDE_DIRS``
78
+ Include dirs to be used when using the ruby library.
50
79
 
51
- ``RUBY_EXECUTABLE``
52
- same as ``Ruby_EXECUTABLE``.
53
- ``RUBY_INCLUDE_DIRS``
54
- same as ``Ruby_INCLUDE_DIRS``.
55
- ``RUBY_INCLUDE_PATH``
56
- same as ``Ruby_INCLUDE_DIRS``.
57
- ``RUBY_LIBRARY``
58
- same as ``Ruby_LIBRARY``.
59
- ``RUBY_VERSION``
60
- same as ``Ruby_VERSION``.
61
- ``RUBY_FOUND``
62
- same as ``Ruby_FOUND``.
80
+ ``Ruby_LIBRARIES``
81
+ .. versionadded:: 3.18
82
+
83
+ Libraries needed to use ruby from C.
84
+
85
+ .. versionchanged:: 3.18
86
+ Previous versions of CMake used the ``RUBY_`` prefix for all variables.
63
87
 
64
88
  Hints
65
89
  ^^^^^
66
90
 
91
+ This module accepts the following variables:
92
+
67
93
  ``Ruby_FIND_VIRTUALENV``
68
94
  .. versionadded:: 3.18
69
95
 
@@ -79,13 +105,64 @@ Hints
79
105
  Virtual environments may be provided by:
80
106
 
81
107
  ``rvm``
82
- Requires that the ``MY_RUBY_HOME`` environment environment is defined.
108
+ Requires that the ``MY_RUBY_HOME`` environment is defined.
83
109
 
84
110
  ``rbenv``
85
111
  Requires that ``rbenv`` is installed in ``~/.rbenv/bin``
86
112
  or that the ``RBENV_ROOT`` environment variable is defined.
113
+
114
+ Deprecated Variables
115
+ ^^^^^^^^^^^^^^^^^^^^
116
+
117
+ The following variables are provided for backward compatibility:
118
+
119
+ .. deprecated:: 4.0
120
+ The following variables are deprecated. See policy :policy:`CMP0185`.
121
+
122
+ ``RUBY_FOUND``
123
+ Same as ``Ruby_FOUND``.
124
+ ``RUBY_VERSION``
125
+ Same as ``Ruby_VERSION``.
126
+ ``RUBY_EXECUTABLE``
127
+ Same as ``Ruby_EXECUTABLE``.
128
+ ``RUBY_INCLUDE_DIRS``
129
+ Same as ``Ruby_INCLUDE_DIRS``.
130
+ ``RUBY_INCLUDE_PATH``
131
+ Same as ``Ruby_INCLUDE_DIRS``.
132
+ ``RUBY_LIBRARY``
133
+ Same as ``Ruby_LIBRARY``.
134
+
135
+ Examples
136
+ ^^^^^^^^
137
+
138
+ Finding Ruby and specifying the minimum required version:
139
+
140
+ .. code-block:: cmake
141
+
142
+ find_package(Ruby 3.2.6 EXACT REQUIRED)
143
+ # or
144
+ find_package(Ruby 3.2)
87
145
  #]=======================================================================]
88
146
 
147
+ #cmake_policy(GET CMP0185 _Ruby_CMP0185)
148
+
149
+ if(NOT _Ruby_CMP0185 STREQUAL "NEW")
150
+ # Backwards compatibility
151
+ # Define camel case versions of input variables
152
+ foreach (UPPER
153
+ RUBY_EXECUTABLE
154
+ RUBY_LIBRARY
155
+ RUBY_INCLUDE_DIR
156
+ RUBY_CONFIG_INCLUDE_DIR)
157
+ if (DEFINED ${UPPER})
158
+ string(REPLACE "RUBY_" "Ruby_" Camel ${UPPER})
159
+ if (NOT DEFINED ${Camel})
160
+ set(${Camel} ${${UPPER}})
161
+ endif ()
162
+ endif ()
163
+ endforeach ()
164
+ endif()
165
+
89
166
  # Uncomment the following line to get debug output for this file
90
167
  # set(CMAKE_MESSAGE_LOG_LEVEL DEBUG)
91
168
 
@@ -94,13 +171,15 @@ Hints
94
171
  set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby)
95
172
 
96
173
  # If the user has not specified a Ruby version, create a list of Ruby versions
97
- # to check going from 1.8 to 3.4
174
+ # to check going from 1.8 to 4.0
98
175
  if (NOT Ruby_FIND_VERSION_EXACT)
99
- foreach (_ruby_version RANGE 34 18 -1)
176
+ foreach (_ruby_version RANGE 40 18 -1)
100
177
  string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version)
101
178
  string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version)
102
179
  # Append both rubyX.Y and rubyXY (eg: ruby3.4 ruby34)
103
- list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby${_ruby_major_version}.${_ruby_minor_version} ruby${_ruby_major_version}${_ruby_minor_version})
180
+ list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES
181
+ ruby${_ruby_major_version}.${_ruby_minor_version}
182
+ ruby${_ruby_major_version}${_ruby_minor_version})
104
183
  endforeach ()
105
184
  endif ()
106
185
 
@@ -147,14 +226,14 @@ endfunction()
147
226
 
148
227
  # Query Ruby RBConfig module for the specified variable (_RUBY_CONFIG_VAR)
149
228
  function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
150
- execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']"
229
+ execute_process(COMMAND "${Ruby_EXECUTABLE}" -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']"
151
230
  RESULT_VARIABLE _Ruby_SUCCESS
152
231
  OUTPUT_VARIABLE _Ruby_OUTPUT
153
232
  ERROR_QUIET)
154
233
 
155
234
  # Config was deprecated in Ruby 1.9 and then removed in Ruby 2 - so this is for ancient code
156
235
  if (_Ruby_SUCCESS OR _Ruby_OUTPUT STREQUAL "")
157
- execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
236
+ execute_process(COMMAND "${Ruby_EXECUTABLE}" -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
158
237
  RESULT_VARIABLE _Ruby_SUCCESS
159
238
  OUTPUT_VARIABLE _Ruby_OUTPUT
160
239
  ERROR_QUIET)
@@ -219,6 +298,54 @@ function(_RUBY_CHECK_RBENV)
219
298
  endif ()
220
299
  endfunction()
221
300
 
301
+ # Check Ruby installed via Homebrew on macOS
302
+ function(_RUBY_CHECK_BREW)
303
+ # Try to locate brew in common locations and in PATH
304
+ find_program(_BREW_EXECUTABLE
305
+ NAMES brew
306
+ NAMES_PER_DIR
307
+ PATHS
308
+ /opt/homebrew/bin # Apple Silicon default
309
+ /usr/local/bin # Intel default
310
+ ENV PATH
311
+ NO_CACHE
312
+ )
313
+
314
+ if (NOT _BREW_EXECUTABLE)
315
+ return()
316
+ endif ()
317
+
318
+ MESSAGE(DEBUG "Found brew at: ${_BREW_EXECUTABLE}")
319
+
320
+ # Query Homebrew for the prefix of the 'ruby' formula.
321
+ # If Ruby is not installed via Homebrew, this will fail.
322
+ execute_process(
323
+ COMMAND "${_BREW_EXECUTABLE}" --prefix ruby
324
+ RESULT_VARIABLE _Ruby_BREW_RESULT
325
+ OUTPUT_VARIABLE _Ruby_BREW_DIR
326
+ ERROR_QUIET
327
+ OUTPUT_STRIP_TRAILING_WHITESPACE
328
+ )
329
+ MESSAGE(DEBUG "Ruby BREW is: ${_Ruby_BREW_DIR}")
330
+
331
+ if (NOT _Ruby_BREW_RESULT EQUAL 0 OR _Ruby_BREW_DIR STREQUAL "")
332
+ # No 'ruby' formula installed in Homebrew
333
+ return()
334
+ endif ()
335
+
336
+ find_program(Ruby_EXECUTABLE
337
+ NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
338
+ NAMES_PER_DIR
339
+ PATHS "${_Ruby_BREW_DIR}/bin"
340
+ VALIDATOR _RUBY_VALIDATE_INTERPRETER
341
+ NO_DEFAULT_PATH
342
+ )
343
+
344
+ if (Ruby_EXECUTABLE)
345
+ set(Ruby_ENV "BREW" CACHE INTERNAL "Ruby environment")
346
+ endif ()
347
+ endfunction()
348
+
222
349
  # Check system installed Ruby
223
350
  function(_RUBY_CHECK_SYSTEM)
224
351
  find_program(Ruby_EXECUTABLE
@@ -241,6 +368,11 @@ if (NOT Ruby_EXECUTABLE AND Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
241
368
  endif ()
242
369
  endif ()
243
370
 
371
+ # Check for Homebrew Ruby (non-virtualenv, common on MacOS)
372
+ if (NOT Ruby_EXECUTABLE AND NOT Ruby_FIND_VIRTUALENV STREQUAL "ONLY")
373
+ _RUBY_CHECK_BREW()
374
+ endif ()
375
+
244
376
  # Fallback to system installed Ruby
245
377
  if (NOT Ruby_EXECUTABLE AND NOT Ruby_FIND_VIRTUALENV STREQUAL "ONLY")
246
378
  _RUBY_CHECK_SYSTEM()
@@ -254,20 +386,30 @@ if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QU
254
386
  _RUBY_CONFIG_VAR("MINOR" Ruby_VERSION_MINOR)
255
387
  _RUBY_CONFIG_VAR("TEENY" Ruby_VERSION_PATCH)
256
388
 
257
- # query the different directories
389
+ # Ruby extensions information
390
+ _RUBY_CONFIG_VAR("arch" Ruby_ARCH) # x86_64-linux, arm64-darwin, x64-mswin64_140, etc
391
+ # Extension directory where so/bundle files are stored
258
392
  _RUBY_CONFIG_VAR("archdir" Ruby_ARCH_DIR)
259
- _RUBY_CONFIG_VAR("arch" Ruby_ARCH)
393
+ # Extension suffix
394
+ _RUBY_CONFIG_VAR("DLEXT" _Ruby_DLEXT) # so, bundle, *not* dll
395
+
396
+ # Headers
260
397
  _RUBY_CONFIG_VAR("rubyhdrdir" Ruby_HDR_DIR)
261
398
  _RUBY_CONFIG_VAR("rubyarchhdrdir" Ruby_ARCHHDR_DIR)
262
- _RUBY_CONFIG_VAR("libdir" _Ruby_POSSIBLE_LIB_DIR)
399
+
400
+ # Ruby library information
401
+ _RUBY_CONFIG_VAR("libdir" _Ruby_POSSIBLE_LIB_DIR) # /usr/lib64
402
+ _RUBY_CONFIG_VAR("RUBY_SO_NAME" _Ruby_SO_NAME) # ruby, x64-vcruntime140-ruby340, etc.
403
+
404
+ # Ruby directory for ruby files (*.rb). TODO - not relevant should be removed
263
405
  _RUBY_CONFIG_VAR("rubylibdir" Ruby_RUBY_LIB_DIR)
264
406
 
265
- # site_ruby
407
+ # site_ruby - TODO - not relevant and should be removed
266
408
  _RUBY_CONFIG_VAR("sitearchdir" Ruby_SITEARCH_DIR)
267
409
  _RUBY_CONFIG_VAR("sitelibdir" Ruby_SITELIB_DIR)
268
410
 
269
- # vendor_ruby available ?
270
- execute_process(COMMAND ${Ruby_EXECUTABLE} -r vendor-specific -e "print 'true'"
411
+ # vendor_ruby - TODO - Not relevant and should be removed.
412
+ execute_process(COMMAND "${Ruby_EXECUTABLE}" -r vendor-specific -e "print 'true'"
271
413
  OUTPUT_VARIABLE Ruby_HAS_VENDOR_RUBY ERROR_QUIET)
272
414
 
273
415
  if (Ruby_HAS_VENDOR_RUBY)
@@ -277,19 +419,21 @@ if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QU
277
419
 
278
420
  # save the results in the cache so we don't have to run ruby the next time again
279
421
  set(_Ruby_EXECUTABLE_LAST_QUERIED "${Ruby_EXECUTABLE}" CACHE INTERNAL "The ruby executable last queried for version and path info")
280
- set(Ruby_VERSION_MAJOR ${Ruby_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
281
- set(Ruby_VERSION_MINOR ${Ruby_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
282
- set(Ruby_VERSION_PATCH ${Ruby_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
283
- set(Ruby_ARCH_DIR ${Ruby_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
284
- set(Ruby_HDR_DIR ${Ruby_HDR_DIR} CACHE PATH "The Ruby header dir (1.9+)" FORCE)
285
- set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE PATH "The Ruby arch header dir (2.0+)" FORCE)
286
- set(_Ruby_POSSIBLE_LIB_DIR ${_Ruby_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
287
- set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
288
- set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
289
- set(Ruby_SITELIB_DIR ${Ruby_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
422
+ set(Ruby_VERSION_MAJOR ${Ruby_VERSION_MAJOR} CACHE STRING "The Ruby major version" FORCE)
423
+ set(Ruby_VERSION_MINOR ${Ruby_VERSION_MINOR} CACHE STRING "The Ruby minor version" FORCE)
424
+ set(Ruby_VERSION_PATCH ${Ruby_VERSION_PATCH} CACHE STRING "The Ruby patch version" FORCE)
425
+ set(Ruby_ARCH_DIR ${Ruby_ARCH_DIR} CACHE INTERNAL "The Ruby arch dir" FORCE)
426
+ set(Ruby_HDR_DIR ${Ruby_HDR_DIR} CACHE INTERNAL "The Ruby header dir (1.9+)" FORCE)
427
+ set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE INTERNAL "The Ruby arch header dir (2.0+)" FORCE)
428
+ set(_Ruby_POSSIBLE_LIB_DIR ${_Ruby_POSSIBLE_LIB_DIR} CACHE INTERNAL "The Ruby lib dir" FORCE)
429
+ set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE INTERNAL "The Ruby ruby-lib dir" FORCE)
430
+ set(_Ruby_SO_NAME ${_Ruby_SO_NAME} CACHE PATH "The Ruby shared library name" FORCE)
431
+ set(_Ruby_DLEXT ${_Ruby_DLEXT} CACHE PATH "Ruby extensions extension" FORCE)
432
+ set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE INTERNAL "The Ruby site arch dir" FORCE)
433
+ set(Ruby_SITELIB_DIR ${Ruby_SITELIB_DIR} CACHE INTERNAL "The Ruby site lib dir" FORCE)
290
434
  set(Ruby_HAS_VENDOR_RUBY ${Ruby_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
291
- set(Ruby_VENDORARCH_DIR ${Ruby_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
292
- set(Ruby_VENDORLIB_DIR ${Ruby_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
435
+ set(Ruby_VENDORARCH_DIR ${Ruby_VENDORARCH_DIR} CACHE INTERNAL "The Ruby vendor arch dir" FORCE)
436
+ set(Ruby_VENDORLIB_DIR ${Ruby_VENDORLIB_DIR} CACHE INTERNAL "The Ruby vendor lib dir" FORCE)
293
437
 
294
438
  mark_as_advanced(
295
439
  Ruby_ARCH_DIR
@@ -298,6 +442,8 @@ if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QU
298
442
  Ruby_ARCHHDR_DIR
299
443
  _Ruby_POSSIBLE_LIB_DIR
300
444
  Ruby_RUBY_LIB_DIR
445
+ _Ruby_SO_NAME
446
+ _Ruby_DLEXT
301
447
  Ruby_SITEARCH_DIR
302
448
  Ruby_SITELIB_DIR
303
449
  Ruby_HAS_VENDOR_RUBY
@@ -306,7 +452,7 @@ if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QU
306
452
  Ruby_VERSION_MAJOR
307
453
  Ruby_VERSION_MINOR
308
454
  Ruby_VERSION_PATCH
309
- )
455
+ )
310
456
  endif ()
311
457
 
312
458
  # In case Ruby_EXECUTABLE could not be executed (e.g. cross compiling)
@@ -324,12 +470,12 @@ if (Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR)
324
470
  # check whether we found 2.[0-7].x
325
471
  if (${Ruby_EXECUTABLE} MATCHES "ruby2")
326
472
  set(Ruby_VERSION_MAJOR 2)
327
- string(REGEX_REPLACE ${Ruby_EXECUTABLE} "ruby2\\.?([0-7])" "\\1" Ruby_VERSION_MINOR)
473
+ string(REGEX REPLACE ${Ruby_EXECUTABLE} "ruby2\\.?([0-7])" "\\1" Ruby_VERSION_MINOR)
328
474
  endif ()
329
475
  # check whether we found 3.[0-1].x
330
476
  if (${Ruby_EXECUTABLE} MATCHES "ruby3")
331
477
  set(Ruby_VERSION_MAJOR 3)
332
- string(REGEX_REPLACE ${Ruby_EXECUTABLE} "ruby3\\.?([0-1])" "\\1" Ruby_VERSION_MINOR)
478
+ string(REGEX REPLACE ${Ruby_EXECUTABLE} "ruby3\\.?([0-4])" "\\1" Ruby_VERSION_MINOR)
333
479
  endif ()
334
480
  endif ()
335
481
 
@@ -343,73 +489,35 @@ endif ()
343
489
 
344
490
  # FIXME: Currently we require both the interpreter and development components to be found
345
491
  # in order to use either. See issue #20474.
346
- find_path(Ruby_INCLUDE_DIR
347
- NAMES ruby.h
348
- HINTS
349
- ${Ruby_HDR_DIR}
350
- ${Ruby_ARCH_DIR}
351
- /usr/lib/ruby/${_Ruby_VERSION_SHORT}/i586-linux-gnu/
352
- )
353
-
354
- set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR})
355
-
356
- # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
357
- if (Ruby_FIND_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_HDR_DIR)
358
- find_path(Ruby_CONFIG_INCLUDE_DIR
359
- NAMES ruby/config.h config.h
360
- HINTS
361
- ${Ruby_HDR_DIR}/${Ruby_ARCH}
362
- ${Ruby_ARCH_DIR}
363
- ${Ruby_ARCHHDR_DIR}
364
- )
365
-
366
- set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIRS} ${Ruby_CONFIG_INCLUDE_DIR})
367
- endif ()
368
492
 
369
- # Determine the list of possible names for the ruby library
370
- set(_Ruby_POSSIBLE_LIB_NAMES
371
- ruby
372
- ruby-static
373
- ruby-${Ruby_VERSION}
374
- ruby${_Ruby_VERSION_NODOT}
375
- ruby${_Ruby_VERSION_NODOT_ZERO_PATCH}
376
- ruby-${_Ruby_VERSION_SHORT}
377
- ruby${_Ruby_VERSION_SHORT}
378
- ruby${_Ruby_VERSION_SHORT_NODOT}
379
- )
493
+ # Save CMAKE_FIND_FRAMEWORK
494
+ set(_Ruby_CMAKE_FIND_FRAMEWORK_ORIGINAL ${CMAKE_FIND_FRAMEWORK})
380
495
 
381
- if (WIN32)
382
- set(_Ruby_POSSIBLE_RUNTIMES "ucrt;msvcrt;vcruntime140;vcruntime140_1;vcruntime${MSVC_TOOLSET_VERSION}")
383
- set(_Ruby_POSSIBLE_VERSION_SUFFIXES "${_Ruby_VERSION_NODOT};${_Ruby_VERSION_NODOT_ZERO_PATCH}")
496
+ # Avoid finding the ancient Ruby framework included in macOS.
497
+ set(CMAKE_FIND_FRAMEWORK LAST)
384
498
 
385
- if (CMAKE_SIZEOF_VOID_P EQUAL 8)
386
- set(_Ruby_POSSIBLE_ARCH_PREFIXES "libx64-;x64-")
387
- else ()
388
- set(_Ruby_POSSIBLE_ARCH_PREFIXES "lib")
389
- endif ()
499
+ find_path(Ruby_INCLUDE_DIR
500
+ NAMES ruby.h
501
+ HINTS ${Ruby_HDR_DIR})
390
502
 
391
- foreach (_Ruby_RUNTIME ${_Ruby_POSSIBLE_RUNTIMES})
392
- foreach (_Ruby_VERSION_SUFFIX ${_Ruby_POSSIBLE_VERSION_SUFFIXES})
393
- foreach (_Ruby_ARCH_PREFIX ${_Ruby_POSSIBLE_ARCH_PREFIXES})
394
- list(APPEND _Ruby_POSSIBLE_LIB_NAMES
395
- "${_Ruby_ARCH_PREFIX}${_Ruby_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}"
396
- "${_Ruby_ARCH_PREFIX}${_Ruby_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}-static")
397
- endforeach ()
398
- endforeach ()
399
- endforeach ()
400
- endif ()
503
+ find_path(Ruby_CONFIG_INCLUDE_DIR
504
+ NAMES ruby/config.h config.h
505
+ HINTS ${Ruby_ARCHHDR_DIR})
401
506
 
402
- find_library(Ruby_LIBRARY NAMES ${_Ruby_POSSIBLE_LIB_NAMES} HINTS ${_Ruby_POSSIBLE_LIB_DIR})
507
+ set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR} ${Ruby_CONFIG_INCLUDE_DIR})
403
508
 
404
- set(_Ruby_REQUIRED_VARS Ruby_EXECUTABLE Ruby_INCLUDE_DIR Ruby_LIBRARY)
405
- if (_Ruby_VERSION_SHORT_NODOT GREATER 18)
406
- list(APPEND _Ruby_REQUIRED_VARS Ruby_CONFIG_INCLUDE_DIR)
407
- endif ()
509
+ find_library(Ruby_LIBRARY
510
+ NAMES "${_Ruby_SO_NAME}"
511
+ HINTS ${_Ruby_POSSIBLE_LIB_DIR})
512
+
513
+ # Restore CMAKE_FIND_FRAMEWORK
514
+ set(CMAKE_FIND_FRAMEWORK ${_Ruby_CMAKE_FIND_FRAMEWORK_ORIGINAL})
408
515
 
409
516
  message(DEBUG "--------FindRuby.cmake debug------------")
410
517
  message(DEBUG "_Ruby_POSSIBLE_EXECUTABLE_NAMES: ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}")
411
518
  message(DEBUG "_Ruby_POSSIBLE_LIB_DIR: ${_Ruby_POSSIBLE_LIB_DIR}")
412
- message(DEBUG "_Ruby_POSSIBLE_LIB_NAMES: ${_Ruby_POSSIBLE_LIB_NAMES}")
519
+ message(DEBUG "Ruby_LIBRUBY_SO: ${_Ruby_SO_NAME}")
520
+ message(DEBUG "_Ruby_DLEXT: ${_Ruby_DLEXT}")
413
521
  message(DEBUG "Ruby_FIND_VIRTUALENV=${Ruby_FIND_VIRTUALENV}")
414
522
  message(DEBUG "Ruby_ENV: ${Ruby_ENV}")
415
523
  message(DEBUG "Found Ruby_VERSION: \"${Ruby_VERSION}\"")
@@ -419,14 +527,109 @@ message(DEBUG "Ruby_INCLUDE_DIR: ${Ruby_INCLUDE_DIR}")
419
527
  message(DEBUG "Ruby_CONFIG_INCLUDE_DIR: ${Ruby_CONFIG_INCLUDE_DIR}")
420
528
  message(DEBUG "Ruby_HDR_DIR: ${Ruby_HDR_DIR}")
421
529
  message(DEBUG "Ruby_ARCH_DIR: ${Ruby_ARCH_DIR}")
530
+ message(DEBUG "Ruby_ARCHHDR_DIR: ${Ruby_ARCHHDR_DIR}")
422
531
  message(DEBUG "--------------------")
423
532
 
533
+ # Components
534
+ #
535
+ # If the caller does not request components, preserve legacy behavior
536
+ if (NOT Ruby_FIND_COMPONENTS)
537
+ set(Ruby_FIND_COMPONENTS Interpreter Development)
538
+ endif ()
539
+
540
+ set(_Ruby_WANT_INTERPRETER FALSE)
541
+ set(_Ruby_WANT_DEVELOPMENT FALSE)
542
+ set(_Ruby_REQUIRED_VARS "")
543
+
544
+ foreach (component IN LISTS Ruby_FIND_COMPONENTS)
545
+ if (component STREQUAL "Interpreter")
546
+ set(_Ruby_WANT_INTERPRETER TRUE)
547
+ list(APPEND _Ruby_REQUIRED_VARS Ruby_EXECUTABLE)
548
+ elseif (component STREQUAL "Development")
549
+ set(_Ruby_WANT_DEVELOPMENT TRUE)
550
+ list(APPEND _Ruby_REQUIRED_VARS Ruby_INCLUDE_DIR Ruby_CONFIG_INCLUDE_DIR)
551
+ if (WIN32)
552
+ list(APPEND _Ruby_REQUIRED_VARS Ruby_LIBRARY)
553
+ endif ()
554
+ else ()
555
+ message(FATAL_ERROR
556
+ "FindRuby: Unsupported component '${component}'. Supported components are: Interpreter, Development")
557
+ endif ()
558
+ endforeach ()
559
+
560
+ # Set component found flags
561
+ set(Ruby_Interpreter_FOUND ${Ruby_EXECUTABLE})
562
+ if (Ruby_INCLUDE_DIR AND Ruby_CONFIG_INCLUDE_DIR AND (Ruby_LIBRARY OR NOT WIN32))
563
+ set(Ruby_Development_FOUND TRUE)
564
+ else ()
565
+ set(Ruby_Development_FOUND FALSE)
566
+ endif ()
567
+
424
568
  include(FindPackageHandleStandardArgs)
425
- find_package_handle_standard_args(Ruby REQUIRED_VARS ${_Ruby_REQUIRED_VARS}
426
- VERSION_VAR Ruby_VERSION)
569
+ find_package_handle_standard_args(Ruby
570
+ REQUIRED_VARS ${_Ruby_REQUIRED_VARS}
571
+ VERSION_VAR Ruby_VERSION
572
+ HANDLE_COMPONENTS)
427
573
 
428
574
  if (Ruby_FOUND)
429
- set(Ruby_LIBRARIES ${Ruby_LIBRARY})
575
+ if (NOT TARGET Ruby::Interpreter)
576
+ add_executable(Ruby::Interpreter IMPORTED GLOBAL)
577
+ set_target_properties(Ruby::Interpreter PROPERTIES
578
+ IMPORTED_LOCATION "${Ruby_EXECUTABLE}"
579
+ )
580
+ endif ()
581
+
582
+ if (Ruby_Development_FOUND)
583
+ set(Ruby_LIBRARIES ${Ruby_LIBRARY})
584
+
585
+ if (Ruby_LIBRARY AND NOT TARGET Ruby::Ruby)
586
+ add_library(Ruby::Ruby UNKNOWN IMPORTED)
587
+ set_target_properties(Ruby::Ruby PROPERTIES
588
+ IMPORTED_LOCATION "${Ruby_LIBRARY}"
589
+ INTERFACE_INCLUDE_DIRECTORIES "${Ruby_INCLUDE_DIRS}"
590
+ # Custom property for extension suffix (with dot), e.g. ".so", ".bundle"
591
+ INTERFACE_RUBY_EXTENSION_SUFFIX ".${_Ruby_DLEXT}"
592
+ )
593
+ endif ()
594
+
595
+ # Ruby::Module - For building Ruby extension modules
596
+ if (NOT TARGET Ruby::Module)
597
+ if (WIN32)
598
+ add_library(Ruby::Module UNKNOWN IMPORTED)
599
+ set_target_properties(Ruby::Module PROPERTIES
600
+ IMPORTED_LOCATION "${Ruby_LIBRARY}"
601
+ )
602
+ else ()
603
+ add_library(Ruby::Module INTERFACE IMPORTED)
604
+ endif ()
605
+
606
+ set_target_properties(Ruby::Module PROPERTIES
607
+ INTERFACE_INCLUDE_DIRECTORIES "${Ruby_INCLUDE_DIRS}"
608
+ # Custom property for extension suffix (with dot), e.g. ".so", ".bundle"
609
+ INTERFACE_RUBY_EXTENSION_SUFFIX ".${_Ruby_DLEXT}"
610
+ INTERFACE_C_VISIBILITY_PRESET hidden
611
+ INTERFACE_CXX_VISIBILITY_PRESET hidden
612
+ INTERFACE_VISIBILITY_INLINES_HIDDEN ON
613
+ )
614
+
615
+ # macOS: allow unresolved Ruby API symbols; resolved when Ruby loads the bundle.
616
+ if (APPLE)
617
+ target_link_options(Ruby::Module INTERFACE
618
+ "LINKER:-undefined,dynamic_lookup"
619
+ )
620
+ endif ()
621
+
622
+ # Linux (and other ELF platforms):
623
+ # Normally undefined Ruby API symbols are allowed in shared objects and resolved at dlopen().
624
+ # But if the toolchain/preset adds -Wl,--no-undefined, linking will fail.
625
+ # This counteracts that.
626
+ if (UNIX AND NOT APPLE)
627
+ target_link_options(Ruby::Module INTERFACE
628
+ "LINKER:--unresolved-symbols=ignore-all"
629
+ )
630
+ endif ()
631
+ endif ()
632
+ endif ()
430
633
  endif ()
431
634
 
432
635
  mark_as_advanced(
@@ -434,4 +637,36 @@ mark_as_advanced(
434
637
  Ruby_LIBRARY
435
638
  Ruby_INCLUDE_DIR
436
639
  Ruby_CONFIG_INCLUDE_DIR
437
- )
640
+ )
641
+
642
+ if(NOT _Ruby_CMP0185 STREQUAL "NEW")
643
+ # Set some variables for compatibility with previous version of this file (no need to provide a CamelCase version of that...)
644
+ set(RUBY_POSSIBLE_LIB_PATH ${_Ruby_POSSIBLE_LIB_DIR})
645
+ set(RUBY_RUBY_LIB_PATH ${Ruby_RUBY_LIB_DIR})
646
+ set(RUBY_INCLUDE_PATH ${Ruby_INCLUDE_DIRS})
647
+
648
+ # Backwards compatibility
649
+ # Define upper case versions of output variables
650
+ foreach (Camel
651
+ Ruby_EXECUTABLE
652
+ Ruby_INCLUDE_DIRS
653
+ Ruby_LIBRARY
654
+ Ruby_VERSION
655
+ Ruby_VERSION_MAJOR
656
+ Ruby_VERSION_MINOR
657
+ Ruby_VERSION_PATCH
658
+
659
+ Ruby_ARCH_DIR
660
+ Ruby_ARCH
661
+ Ruby_HDR_DIR
662
+ Ruby_ARCHHDR_DIR
663
+ Ruby_RUBY_LIB_DIR
664
+ Ruby_SITEARCH_DIR
665
+ Ruby_SITELIB_DIR
666
+ Ruby_HAS_VENDOR_RUBY
667
+ Ruby_VENDORARCH_DIR
668
+ Ruby_VENDORLIB_DIR)
669
+ string(TOUPPER ${Camel} UPPER)
670
+ set(${UPPER} ${${Camel}})
671
+ endforeach ()
672
+ endif()