diff options
author | Brad King <brad.king@kitware.com> | 2020-03-18 13:09:13 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-03-18 13:09:18 (GMT) |
commit | 863b0fa2aca3ece98d177f2dbafcad56f7037c8a (patch) | |
tree | bd969dd2c1f77b23e88bf52a9f43acf51ebb1163 /Modules | |
parent | d9ad00119d9d412f6ab245a11f72209704c74c81 (diff) | |
parent | 46064c819357ca6f83ed24d08f2762cac8c12157 (diff) | |
download | CMake-863b0fa2aca3ece98d177f2dbafcad56f7037c8a.zip CMake-863b0fa2aca3ece98d177f2dbafcad56f7037c8a.tar.gz CMake-863b0fa2aca3ece98d177f2dbafcad56f7037c8a.tar.bz2 |
Merge topic 'FindRuby-updates'
46064c8193 FindRuby: Add support for versions up to 2.7
675eaf3bd0 FindRuby: Update MSVC runtime library selection
b970e25d98 FindRuby: Remove extra whitespace
ecdace4d61 FindRuby: Include FPHSA closer to where it is used
f52f496138 FindRuby: Provide Ruby_LIBRARIES result variable
b00d736a0b FindRuby: Add dedicated tests
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4481
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindRuby.cmake | 143 |
1 files changed, 94 insertions, 49 deletions
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index 5df242b..1e010bf 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -8,25 +8,42 @@ FindRuby Find Ruby This module finds if Ruby is installed and determines where the -include files and libraries are. Ruby 1.8, 1.9, 2.0 and 2.1 are +include files and libraries are. Ruby 1.8 through 2.7 are supported. The minimum required version of Ruby can be specified using the -standard syntax, e.g. find_package(Ruby 1.8) +standard syntax, e.g. -It also determines what the name of the library is. This code sets -the following variables: +.. code-block:: cmake + find_package(Ruby 2.5.1 EXACT REQUIRED) + # OR + find_package(Ruby 2.4) + +It also determines what the name of the library is. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``Ruby_FOUND`` + set to true if ruby was found successfully ``Ruby_EXECUTABLE`` full path to the ruby binary ``Ruby_INCLUDE_DIRS`` include dirs to be used when using the ruby library -``Ruby_LIBRARY`` - full path to the ruby library +``Ruby_LIBRARIES`` + libraries needed to use ruby from C. ``Ruby_VERSION`` the version of ruby which was found, e.g. "1.8.7" -``Ruby_FOUND`` - set to true if ruby ws found successfully +``Ruby_VERSION_MAJOR`` + Ruby major version. +``Ruby_VERSION_MINOR`` + Ruby minor version. +``Ruby_VERSION_PATCH`` + Ruby patch version. + Also: @@ -63,37 +80,57 @@ endforeach() # on which version of ruby is required set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby) -# if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8 -if(DEFINED Ruby_FIND_VERSION_MAJOR AND DEFINED Ruby_FIND_VERSION_MINOR) - set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR}") - # we can't construct that if only major version is given - set(_Ruby_POSSIBLE_EXECUTABLE_NAMES - ruby${Ruby_FIND_VERSION_MAJOR}.${Ruby_FIND_VERSION_MINOR} - ruby${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR} - ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}) -else() - set(Ruby_FIND_VERSION_SHORT_NODOT "18") +# If not specified, allow everything as far back as 1.8.0 +if(NOT DEFINED Ruby_FIND_VERSION_MAJOR) + set(Ruby_FIND_VERSION "1.8.0") + set(Ruby_FIND_VERSION_MAJOR 1) + set(Ruby_FIND_VERSION_MINOR 8) + set(Ruby_FIND_VERSION_PATCH 0) +endif() + +if(_Ruby_DEBUG_OUTPUT) + message("Ruby_FIND_VERSION=${Ruby_FIND_VERSION}") + message("Ruby_FIND_VERSION_MAJOR=${Ruby_FIND_VERSION_MAJOR}") + message("Ruby_FIND_VERSION_MINOR=${Ruby_FIND_VERSION_MINOR}") + message("Ruby_FIND_VERSION_PATCH=${Ruby_FIND_VERSION_PATCH}") endif() +set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR}") + +# Set name of possible executables, ignoring the minor +# Eg: +# 2.1.1 => from ruby27 to ruby21 included +# 2.1 => from ruby27 to ruby21 included +# 2 => from ruby26 to ruby20 included +# empty => from ruby27 to ruby18 included if(NOT Ruby_FIND_VERSION_EXACT) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.4 ruby24) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.3 ruby23) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.2 ruby22) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.1 ruby21) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby2.0 ruby20) - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby1.9 ruby19) - - # if we want a version below 1.9, also look for ruby 1.8 - if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19") - list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby1.8 ruby18) - endif() + + foreach(_ruby_version RANGE 27 18 -1) + string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version) + string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version) + + if(NOT "${_ruby_major_version}${_ruby_minor_version}" VERSION_LESS ${Ruby_FIND_VERSION_SHORT_NODOT}) + # Append both rubyX.Y and rubyXY (eg: ruby2.7 ruby27) + list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby${_ruby_major_version}.${_ruby_minor_version} ruby${_ruby_major_version}${_ruby_minor_version}) + else() + break() + endif() + + endforeach() list(REMOVE_DUPLICATES _Ruby_POSSIBLE_EXECUTABLE_NAMES) endif() -find_program(Ruby_EXECUTABLE NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}) +if(_Ruby_DEBUG_OUTPUT) + message("_Ruby_POSSIBLE_EXECUTABLE_NAMES=${_Ruby_POSSIBLE_EXECUTABLE_NAMES}") +endif() -if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) +find_program (Ruby_EXECUTABLE + NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES} + NAMES_PER_DIR + ) + +if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) function(_RUBY_CONFIG_VAR RBVAR OUTVAR) execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']" RESULT_VARIABLE _Ruby_SUCCESS @@ -205,6 +242,21 @@ if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR) set(Ruby_VERSION_MAJOR 2) set(Ruby_VERSION_MINOR 4) endif() + # check whether we found 2.5.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?5") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 5) + endif() + # check whether we found 2.6.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?6") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 6) + endif() + # check whether we found 2.7.x + if(${Ruby_EXECUTABLE} MATCHES "ruby2\\.?7") + set(Ruby_VERSION_MAJOR 2) + set(Ruby_VERSION_MINOR 7) + endif() endif() if(Ruby_VERSION_MAJOR) @@ -222,10 +274,10 @@ find_path(Ruby_INCLUDE_DIR /usr/lib/ruby/${_Ruby_VERSION_SHORT}/i586-linux-gnu/ ) -set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR} ) +set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR}) # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir -if( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_Ruby_VERSION_SHORT_NODOT}" GREATER 18 OR Ruby_HDR_DIR) +if( Ruby_FIND_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_HDR_DIR) find_path(Ruby_CONFIG_INCLUDE_DIR NAMES ruby/config.h config.h HINTS @@ -242,21 +294,10 @@ endif() set(_Ruby_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_Ruby_VERSION_SHORT} ruby${_Ruby_VERSION_SHORT_NODOT} ruby-${_Ruby_VERSION_SHORT} ruby-${Ruby_VERSION}) if(WIN32) - set( _Ruby_MSVC_RUNTIME "" ) - if( MSVC_VERSION EQUAL 1200 ) - set( _Ruby_MSVC_RUNTIME "60" ) - endif() - if( MSVC_VERSION EQUAL 1300 ) - set( _Ruby_MSVC_RUNTIME "70" ) - endif() - if( MSVC_VERSION EQUAL 1310 ) - set( _Ruby_MSVC_RUNTIME "71" ) - endif() - if( MSVC_VERSION EQUAL 1400 ) - set( _Ruby_MSVC_RUNTIME "80" ) - endif() - if( MSVC_VERSION EQUAL 1500 ) - set( _Ruby_MSVC_RUNTIME "90" ) + if(MSVC_TOOLSET_VERSION) + set(_Ruby_MSVC_RUNTIME "${MSVC_TOOLSET_VERSION}") + else() + set(_Ruby_MSVC_RUNTIME "") endif() set(_Ruby_ARCH_PREFIX "") @@ -273,7 +314,6 @@ endif() find_library(Ruby_LIBRARY NAMES ${_Ruby_POSSIBLE_LIB_NAMES} HINTS ${Ruby_POSSIBLE_LIB_DIR} ) -include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) set(_Ruby_REQUIRED_VARS Ruby_EXECUTABLE Ruby_INCLUDE_DIR Ruby_LIBRARY) if(_Ruby_VERSION_SHORT_NODOT GREATER 18) list(APPEND _Ruby_REQUIRED_VARS Ruby_CONFIG_INCLUDE_DIR) @@ -295,9 +335,14 @@ if(_Ruby_DEBUG_OUTPUT) message(STATUS "--------------------") endif() +include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_Ruby_REQUIRED_VARS} VERSION_VAR Ruby_VERSION ) +if(Ruby_FOUND) + set(Ruby_LIBRARIES ${Ruby_LIBRARY}) +endif() + mark_as_advanced( Ruby_EXECUTABLE Ruby_LIBRARY |