MantisBT - CMake
View Issue Details
0015345CMakeModulespublic2015-01-12 07:432015-06-01 08:38
David Coppa 
Rolf Eike Beer 
normalminoralways
closedfixed 
CMake 3.1 
CMake 3.1.1CMake 3.1.1 
0015345: FindRuby: Problem with "find_package(Ruby 2.0)"
OS is OpenBSD, but I think this also applies to Linux or other Unix-like OSes.
Both ruby-2.0.0 and ruby-2.1.5 are installed on the system:

$ ls -1 /usr/local/bin/ruby*
/usr/local/bin/ruby20
/usr/local/bin/ruby21

Using "find_package(Ruby 2.1)" works as expected:

-- ATTENTION -> Ruby_FIND_VERSION_MINOR == 1
-- ATTENTION -> setting Ruby_FIND_VERSION_SHORT_NODOT...
-- --------FindRuby.cmake debug------------
-- _RUBY_POSSIBLE_EXECUTABLE_NAMES: ruby2.1;ruby21;ruby;ruby2.0;ruby20;ruby1.9;ruby19;ruby1.8;ruby18
-- _RUBY_POSSIBLE_LIB_NAMES: ruby;ruby-static;ruby2.1;ruby21;ruby-2.1;ruby-2.1.0
-- RUBY_ARCH_DIR: /usr/local/lib/ruby/2.1/x86_64-openbsd
-- RUBY_HDR_DIR: /usr/local/include/ruby-2.1
-- RUBY_POSSIBLE_LIB_DIR: /usr/local/lib
-- Found RUBY_VERSION: "2.1.0" , short: "2.1", nodot: "21"
-- _RUBY_REQUIRED_VARS: RUBY_EXECUTABLE;RUBY_INCLUDE_DIR;RUBY_LIBRARY;RUBY_CONFIG_INCLUDE_DIR
-- RUBY_EXECUTABLE: /usr/local/bin/ruby21
-- RUBY_LIBRARY: /usr/local/lib/libruby21.so.1.0
-- RUBY_INCLUDE_DIR: /usr/local/include/ruby-2.1
-- RUBY_CONFIG_INCLUDE_DIR: /usr/local/include/ruby-2.1/x86_64-openbsd
-- --------------------
-- Found Ruby: /usr/local/bin/ruby21 (found suitable version "2.1.0", minimum required is "2.1")

** NOTE: I've added some messages to help understand the problem and set _RUBY_DEBUG_OUTPUT to true.

While "find_package(Ruby 2.0)" is broken:

-- ATTENTION -> Ruby_FIND_VERSION_MINOR == 0
-- --------FindRuby.cmake debug------------
-- _RUBY_POSSIBLE_EXECUTABLE_NAMES: ruby;ruby2.1;ruby21;ruby2.0;ruby20;ruby1.9;ruby19;ruby1.8;ruby18
-- _RUBY_POSSIBLE_LIB_NAMES: ruby;ruby-static;ruby2.1;ruby21;ruby-2.1;ruby-2.1.0
-- RUBY_ARCH_DIR: /usr/local/lib/ruby/2.1/x86_64-openbsd
-- RUBY_HDR_DIR: /usr/local/include/ruby-2.1
-- RUBY_POSSIBLE_LIB_DIR: /usr/local/lib
-- Found RUBY_VERSION: "2.1.0" , short: "2.1", nodot: "21"
-- _RUBY_REQUIRED_VARS: RUBY_EXECUTABLE;RUBY_INCLUDE_DIR;RUBY_LIBRARY;RUBY_CONFIG_INCLUDE_DIR
-- RUBY_EXECUTABLE: /usr/local/bin/ruby21
-- RUBY_LIBRARY: /usr/local/lib/libruby21.so.1.0
-- RUBY_INCLUDE_DIR: /usr/local/include/ruby-2.1
-- RUBY_CONFIG_INCLUDE_DIR: /usr/local/include/ruby-2.1/x86_64-openbsd
-- --------------------
-- Found Ruby: /usr/local/bin/ruby21 (found suitable version "2.1.0", minimum required is "2.0")

This is because, when "Ruby_FIND_VERSION_MINOR" is 0, the "if(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)" check at line 61 evaluates to false.

Changing line 61 to:

"if(DEFINED Ruby_FIND_VERSION_MAJOR AND DEFINED Ruby_FIND_VERSION_MINOR)"

works around the issue for me:

-- ATTENTION -> Ruby_FIND_VERSION_MINOR == 0
-- ATTENTION -> setting Ruby_FIND_VERSION_SHORT_NODOT ...
-- --------FindRuby.cmake debug------------
-- _RUBY_POSSIBLE_EXECUTABLE_NAMES: ruby2.0;ruby20;ruby;ruby2.1;ruby21;ruby1.9;ruby19;ruby1.8;ruby18
-- _RUBY_POSSIBLE_LIB_NAMES: ruby;ruby-static;ruby2.0;ruby20;ruby-2.0;ruby-2.0.0
-- RUBY_ARCH_DIR: /usr/local/lib/ruby/2.0/x86_64-openbsd
-- RUBY_HDR_DIR: /usr/local/include/ruby-2.0
-- RUBY_POSSIBLE_LIB_DIR: /usr/local/lib
-- Found RUBY_VERSION: "2.0.0" , short: "2.0", nodot: "20"
-- _RUBY_REQUIRED_VARS: RUBY_EXECUTABLE;RUBY_INCLUDE_DIR;RUBY_LIBRARY;RUBY_CONFIG_INCLUDE_DIR
-- RUBY_EXECUTABLE: /usr/local/bin/ruby20
-- RUBY_LIBRARY: /usr/local/lib/libruby20.so.1.0
-- RUBY_INCLUDE_DIR: /usr/local/include/ruby-2.0
-- RUBY_CONFIG_INCLUDE_DIR: /usr/local/include/ruby-2.0/x86_64-openbsd
-- --------------------
-- Found Ruby: /usr/local/bin/ruby20 (found suitable version "2.0.0", minimum required is "2.0")

Use "find_package(Ruby 2.0)" or "find_package(Ruby 2.0 EXACT)"
No tags attached.
patch 0001-Fix-FindRuby-find_package-with-version.patch (917) 2015-01-12 09:19
https://public.kitware.com/Bug/file/5342/0001-Fix-FindRuby-find_package-with-version.patch
Issue History
2015-01-12 07:43David CoppaNew Issue
2015-01-12 08:42Rolf Eike BeerNote Added: 0037670
2015-01-12 08:45Brad KingTarget Version => CMake 3.1.1
2015-01-12 09:19David CoppaFile Added: 0001-Fix-FindRuby-find_package-with-version.patch
2015-01-12 11:45Ben BoeckelNote Added: 0037671
2015-01-12 12:28Rolf Eike BeerNote Added: 0037672
2015-01-12 13:31Rolf Eike BeerNote Added: 0037673
2015-01-12 13:31Rolf Eike BeerAssigned To => Rolf Eike Beer
2015-01-12 13:31Rolf Eike BeerStatusnew => resolved
2015-01-12 13:31Rolf Eike BeerResolutionopen => fixed
2015-01-12 13:31Rolf Eike BeerCategoryCMake => Modules
2015-01-12 13:31Rolf Eike BeerFixed in Version => CMake 3.1.1
2015-06-01 08:38Robert MaynardNote Added: 0038835
2015-06-01 08:38Robert MaynardStatusresolved => closed

Notes
(0037670)
Rolf Eike Beer   
2015-01-12 08:42   
Thanks, I will look into this later. It would be helpful if you could attach a git patch to give you proper attribution.
(0037671)
Ben Boeckel   
2015-01-12 11:45   
@Rolf, there's the '--author=John Doe <foo@example.com>' argument to 'git commit' as well.
(0037672)
Rolf Eike Beer   
2015-01-12 12:28   
Sure, but I'm not allowed to see his email address in Mantis.
(0037673)
Rolf Eike Beer   
2015-01-12 13:31   
Fix pushed to next:

  http://www.cmake.org/gitweb?p=cmake.git;a=commitdiff;h=dd5d2eb156b7e45ded53f694a12a1e00d19f6cd6 [^]

Fix is based on release, so it can go into 3.1.1.
(0038835)
Robert Maynard   
2015-06-01 08:38   
Closing resolved issues that have not been updated in more than 4 months.