diff options
author | Julien Marrec <julien.marrec@gmail.com> | 2020-03-11 17:37:19 (GMT) |
---|---|---|
committer | Julien Marrec <julien.marrec@gmail.com> | 2020-03-23 12:21:40 (GMT) |
commit | e6699b9b59a12f6fda8f535d370453bb41f3acce (patch) | |
tree | 9ae3fc49588030c0c6ea0fc36047dcdc42f7a30f /Modules/FindRuby.cmake | |
parent | 8638c49f2a0b87c131be8f4d3147a2617938e30a (diff) | |
download | CMake-e6699b9b59a12f6fda8f535d370453bb41f3acce.zip CMake-e6699b9b59a12f6fda8f535d370453bb41f3acce.tar.gz CMake-e6699b9b59a12f6fda8f535d370453bb41f3acce.tar.bz2 |
FindRuby: Validate Ruby_EXECUTABLE before accepting it
Diffstat (limited to 'Modules/FindRuby.cmake')
-rw-r--r-- | Modules/FindRuby.cmake | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index 1e010bf..699d2b6 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) |