FindRuby: improve version selection

This will stop e.g. looking for a ruby1.9 executable first if "1.8 EXACT" was
given.
This commit is contained in:
Rolf Eike Beer 2013-03-18 20:17:08 +01:00
parent 526cbafa4e
commit d7e05e4144
1 changed files with 13 additions and 4 deletions

View File

@ -46,15 +46,24 @@ 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 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8
if(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR) if(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${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() else()
set(Ruby_FIND_VERSION_SHORT_NODOT "18") set(Ruby_FIND_VERSION_SHORT_NODOT "18")
endif() endif()
set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.9 ruby19) if(NOT Ruby_FIND_VERSION_EXACT)
list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby1.9 ruby19)
# if we want a version below 1.9, also look for ruby 1.8 # if we want a version below 1.9, also look for ruby 1.8
if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19") if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.8 ruby18) list(APPEND _RUBY_POSSIBLE_EXECUTABLE_NAMES ruby1.8 ruby18)
endif()
list(REMOVE_DUPLICATES _RUBY_POSSIBLE_EXECUTABLE_NAMES)
endif() endif()
find_program(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}) find_program(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})