diff options
author | Julien Marrec <julien.marrec@gmail.com> | 2020-03-23 12:16:39 (GMT) |
---|---|---|
committer | Julien Marrec <julien.marrec@gmail.com> | 2020-03-23 12:22:23 (GMT) |
commit | 905d5667e8b49a931078a1bcea26deffe703453b (patch) | |
tree | c42c663aaca77453350c5aac602ef0a4d3407995 /Modules/FindRuby.cmake | |
parent | e6699b9b59a12f6fda8f535d370453bb41f3acce (diff) | |
download | CMake-905d5667e8b49a931078a1bcea26deffe703453b.zip CMake-905d5667e8b49a931078a1bcea26deffe703453b.tar.gz CMake-905d5667e8b49a931078a1bcea26deffe703453b.tar.bz2 |
FindRuby: Add support for RVM installations
Diffstat (limited to 'Modules/FindRuby.cmake')
-rw-r--r-- | Modules/FindRuby.cmake | 98 |
1 files changed, 93 insertions, 5 deletions
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index 699d2b6..1bdee60 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -22,6 +22,9 @@ standard syntax, e.g. It also determines what the name of the library is. +Virtual environments such as RVM are handled as well, by passing +the argument ``Ruby_FIND_VIRTUALENV`` + Result Variables ^^^^^^^^^^^^^^^^ @@ -49,6 +52,28 @@ Also: ``Ruby_INCLUDE_PATH`` same as Ruby_INCLUDE_DIRS, only provided for compatibility reasons, don't use it + +Hints +^^^^^ + +``Ruby_ROOT_DIR`` + Define the root directory of a Ruby installation. + +``Ruby_FIND_VIRTUALENV`` + This variable defines the handling of virtual environments managed by + ``rvm``. It is meaningful only when a virtual environment + is active (i.e. the ``rvm`` script has been evaluated or at least the + ``MY_RUBY_HOME`` environment variable is set). + The ``Ruby_FIND_VIRTUALENV`` variable can be set to empty or + one of the following: + + * ``FIRST``: The virtual environment is used before any other standard + paths to look-up for the interpreter. This is the default. + * ``ONLY``: Only the virtual environment is used to look-up for the + interpreter. + * ``STANDARD``: The virtual environment is not used to look-up for the + interpreter (assuming it isn't still in the PATH...) + #]=======================================================================] # Backwards compatibility @@ -121,8 +146,32 @@ if(NOT Ruby_FIND_VERSION_EXACT) list(REMOVE_DUPLICATES _Ruby_POSSIBLE_EXECUTABLE_NAMES) endif() +# virtual environments handling (eg RVM) +if (DEFINED ENV{MY_RUBY_HOME}) + if(_Ruby_DEBUG_OUTPUT) + message("My ruby home is defined: $ENV{MY_RUBY_HOME}") + endif() + + if (DEFINED Ruby_FIND_VIRTUALENV) + if (NOT Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY|STANDARD)$") + message (AUTHOR_WARNING "FindRuby: ${Ruby_FIND_VIRTUALENV}: invalid value for 'Ruby_FIND_VIRTUALENV'. 'FIRST', 'ONLY' or 'STANDARD' expected. 'FIRST' will be used instead.") + set (_Ruby_FIND_VIRTUALENV "FIRST") + else() + set (_Ruby_FIND_VIRTUALENV ${Ruby_FIND_VIRTUALENV}) + endif() + else() + set (_Ruby_FIND_VIRTUALENV FIRST) + endif() +else() + if (DEFINED Ruby_FIND_VIRTUALENV) + message("Environment variable MY_RUBY_HOME isn't set, defaulting back to Ruby_FIND_VIRTUALENV=STANDARD") + endif() + set (_Ruby_FIND_VIRTUALENV STANDARD) +endif() + if(_Ruby_DEBUG_OUTPUT) message("_Ruby_POSSIBLE_EXECUTABLE_NAMES=${_Ruby_POSSIBLE_EXECUTABLE_NAMES}") + message("_Ruby_FIND_VIRTUALENV=${_Ruby_FIND_VIRTUALENV}") endif() function (_RUBY_VALIDATE_INTERPRETER) @@ -164,11 +213,48 @@ function (_RUBY_VALIDATE_INTERPRETER) endfunction() -find_program (Ruby_EXECUTABLE - NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES} - NAMES_PER_DIR - ) -_RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION}) +while(1) + # Virtual environments handling + if(_Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$") + if(_Ruby_DEBUG_OUTPUT) + message("Inside Matches") + endif() + find_program (Ruby_EXECUTABLE + NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES} + NAMES_PER_DIR + PATHS ENV MY_RUBY_HOME + PATH_SUFFIXES bin Scripts + NO_CMAKE_PATH + NO_CMAKE_ENVIRONMENT_PATH + NO_SYSTEM_ENVIRONMENT_PATH + NO_CMAKE_SYSTEM_PATH) + + if(_Ruby_DEBUG_OUTPUT) + message("Ruby_EXECUTABLE=${Ruby_EXECUTABLE}") + endif() + + _RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION}}) + if(Ruby_EXECUTABLE) + break() + endif() + if(NOT _Ruby_FIND_VIRTUALENV STREQUAL "ONLY") + break() + endif() + elseif(_Ruby_DEBUG_OUTPUT) + message("_Ruby_FIND_VIRTUALENV doesn't match: ${_Ruby_FIND_VIRTUALENV}") + endif() + + # try using standard paths + find_program (Ruby_EXECUTABLE + NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES} + NAMES_PER_DIR) + _RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION}) + if (Ruby_EXECUTABLE) + break() + endif() + + break() +endwhile() if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) function(_RUBY_CONFIG_VAR RBVAR OUTVAR) @@ -306,6 +392,8 @@ if(Ruby_VERSION_MAJOR) set(_Ruby_NODOT_VERSION "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}${Ruby_VERSION_PATCH}") endif() +# FIXME: Currently we require both the interpreter and development components to be found +# in order to use either. See issue #20474. find_path(Ruby_INCLUDE_DIR NAMES ruby.h HINTS |