Browse Source

FindRuby: Only search for released Ruby versions

Charlie Savage 1 month ago
parent
commit
fe006b5e9d
1 changed files with 7 additions and 13 deletions
  1. 7 13
      Modules/FindRuby.cmake

+ 7 - 13
Modules/FindRuby.cmake

@@ -175,13 +175,17 @@ endif()
 set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby)
 
 # If the user has not specified a Ruby version, create a list of Ruby versions
-# to check going from 1.8 to 4.0
+# to search (newest to oldest). Based on https://www.ruby-lang.org/en/downloads/releases/
 if (NOT Ruby_FIND_VERSION_EXACT)
-  foreach (_ruby_version RANGE 40 18 -1)
+  set(_Ruby_SUPPORTED_VERSIONS 40 34 33 32)
+  set(_Ruby_UNSUPPORTED_VERSIONS 31 30 27 26 25 24 23 22 21 20)
+  foreach (_ruby_version IN LISTS _Ruby_SUPPORTED_VERSIONS _Ruby_UNSUPPORTED_VERSIONS)
     string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version)
     string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version)
     # Append both rubyX.Y and rubyXY (eg: ruby3.4 ruby34)
-    list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby${_ruby_major_version}.${_ruby_minor_version} ruby${_ruby_major_version}${_ruby_minor_version})
+    list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES
+         ruby${_ruby_major_version}.${_ruby_minor_version}
+         ruby${_ruby_major_version}${_ruby_minor_version})
   endforeach ()
 endif ()
 
@@ -233,14 +237,6 @@ function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
                   OUTPUT_VARIABLE _Ruby_OUTPUT
                   ERROR_QUIET)
 
-  # Config was deprecated in Ruby 1.9 and then removed in Ruby 2 - so this is for ancient code
-  if (_Ruby_SUCCESS OR _Ruby_OUTPUT STREQUAL "")
-    execute_process(COMMAND "${Ruby_EXECUTABLE}" -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
-                    RESULT_VARIABLE _Ruby_SUCCESS
-                    OUTPUT_VARIABLE _Ruby_OUTPUT
-                    ERROR_QUIET)
-  endif ()
-
   set(${OUTVAR} "${_Ruby_OUTPUT}" PARENT_SCOPE)
 endfunction()
 
@@ -429,8 +425,6 @@ if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QU
   set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE INTERNAL "The Ruby arch header dir (2.0+)" FORCE)
   set(_Ruby_POSSIBLE_LIB_DIR ${_Ruby_POSSIBLE_LIB_DIR} CACHE INTERNAL "The Ruby lib dir" FORCE)
   set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE INTERNAL "The Ruby ruby-lib dir" FORCE)
-  set(_Ruby_SO_NAME ${_Ruby_SO_NAME} CACHE PATH "The Ruby shared library name" FORCE)
-  set(_Ruby_DLEXT ${_Ruby_DLEXT} CACHE PATH "Ruby extensions extension" FORCE)
   set(_Ruby_SO_NAME ${_Ruby_SO_NAME} CACHE STRING "The Ruby shared library name" FORCE)
   set(_Ruby_DLEXT ${_Ruby_DLEXT} CACHE STRING "Ruby extensions extension" FORCE)
   set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE INTERNAL "The Ruby site arch dir" FORCE)