summaryrefslogtreecommitdiff
path: root/Modules/FindRuby.cmake
diff options
context:
space:
mode:
authorJulien Marrec <julien.marrec@gmail.com>2020-03-11 18:37:19 +0100
committerJulien Marrec <julien.marrec@gmail.com>2020-03-23 13:21:40 +0100
commite6699b9b59a12f6fda8f535d370453bb41f3acce (patch)
tree9ae3fc49588030c0c6ea0fc36047dcdc42f7a30f /Modules/FindRuby.cmake
parent8638c49f2a0b87c131be8f4d3147a2617938e30a (diff)
downloadcmake-e6699b9b59a12f6fda8f535d370453bb41f3acce.tar.gz
FindRuby: Validate Ruby_EXECUTABLE before accepting it
Diffstat (limited to 'Modules/FindRuby.cmake')
-rw-r--r--Modules/FindRuby.cmake40
1 files changed, 40 insertions, 0 deletions
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake
index 1e010bf7d6..699d2b6c9f 100644
--- a/Modules/FindRuby.cmake
+++ b/Modules/FindRuby.cmake
@@ -125,10 +125,50 @@ if(_Ruby_DEBUG_OUTPUT)
message("_Ruby_POSSIBLE_EXECUTABLE_NAMES=${_Ruby_POSSIBLE_EXECUTABLE_NAMES}")
endif()
+function (_RUBY_VALIDATE_INTERPRETER)
+ if (NOT Ruby_EXECUTABLE)
+ return()
+ endif()
+
+ cmake_parse_arguments (PARSE_ARGV 0 _RVI "EXACT;CHECK_EXISTS" "" "")
+ if (_RVI_UNPARSED_ARGUMENTS)
+ set (expected_version ${_RVI_UNPARSED_ARGUMENTS})
+ else()
+ unset (expected_version)
+ endif()
+
+ if (_RVI_CHECK_EXISTS AND NOT EXISTS "${Ruby_EXECUTABLE}")
+ # interpreter does not exist anymore
+ set (_Ruby_Interpreter_REASON_FAILURE "Cannot find the interpreter \"${Ruby_EXECUTABLE}\"")
+ set_property (CACHE Ruby_EXECUTABLE PROPERTY VALUE "Ruby_EXECUTABLE-NOTFOUND")
+ return()
+ endif()
+
+ # Check the version it returns
+ # executable found must have a specific version
+ execute_process (COMMAND "${Ruby_EXECUTABLE}" -e "puts RUBY_VERSION"
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE version
+ ERROR_QUIET
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if (result OR (_RVI_EXACT AND NOT version VERSION_EQUAL expected_version) OR (version VERSION_LESS expected_version))
+ # interpreter not usable or has wrong major version
+ if (result)
+ set (_Ruby_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${Ruby_EXECUTABLE}\"")
+ else()
+ set (_Ruby_Interpreter_REASON_FAILURE "Wrong major version for the interpreter \"${Ruby_EXECUTABLE}\"")
+ endif()
+ set_property (CACHE Ruby_EXECUTABLE PROPERTY VALUE "Ruby_EXECUTABLE-NOTFOUND")
+ return()
+ endif()
+
+endfunction()
+
find_program (Ruby_EXECUTABLE
NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
NAMES_PER_DIR
)
+_RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION})
if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR)
function(_RUBY_CONFIG_VAR RBVAR OUTVAR)