2 # This module finds if Ruby is installed and determines where the include files
3 # and libraries are. Ruby 1.8 and 1.9 are supported.
5 # The minimum required version of Ruby can be specified using the
6 # standard syntax, e.g. find_package(Ruby 1.8)
8 # It also determines what the name of the library is. This
9 # code sets the following variables:
11 # RUBY_EXECUTABLE = full path to the ruby binary
12 # RUBY_INCLUDE_DIRS = include dirs to be used when using the ruby library
13 # RUBY_LIBRARY = full path to the ruby library
14 # RUBY_VERSION = the version of ruby which was found, e.g. "1.8.7"
15 # RUBY_FOUND = set to true if ruby ws found successfully
17 # RUBY_INCLUDE_PATH = same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
19 #=============================================================================
20 # Copyright 2004-2009 Kitware, Inc.
21 # Copyright 2008-2009 Alexander Neundorf <neundorf@kde.org>
23 # Distributed under the OSI-approved BSD License (the "License");
24 # see accompanying file Copyright.txt for details.
26 # This software is distributed WITHOUT ANY WARRANTY; without even the
27 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 # See the License for more information.
29 #=============================================================================
30 # (To distribute this file outside of CMake, substitute the full
31 # License text for the above reference.)
33 # RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
34 # RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
35 # RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
36 # RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
37 # RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
39 # uncomment the following line to get debug output for this file
40 # set(_RUBY_DEBUG_OUTPUT TRUE)
42 # Determine the list of possible names of the ruby executable depending
43 # on which version of ruby is required
44 set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ruby)
46 # if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8
47 if(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
48 set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${RUBY_FIND_VERSION_MINOR}")
50 set(Ruby_FIND_VERSION_SHORT_NODOT "18")
53 set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.9 ruby19)
55 # if we want a version below 1.9, also look for ruby 1.8
56 if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
57 set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.8 ruby18)
60 find_program(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})
63 if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR)
64 function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
65 execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']"
66 RESULT_VARIABLE _RUBY_SUCCESS
67 OUTPUT_VARIABLE _RUBY_OUTPUT
69 if(_RUBY_SUCCESS OR NOT _RUBY_OUTPUT)
70 execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
71 RESULT_VARIABLE _RUBY_SUCCESS
72 OUTPUT_VARIABLE _RUBY_OUTPUT
75 set(${OUTVAR} "${_RUBY_OUTPUT}" PARENT_SCOPE)
79 # query the ruby version
80 _RUBY_CONFIG_VAR("MAJOR" RUBY_VERSION_MAJOR)
81 _RUBY_CONFIG_VAR("MINOR" RUBY_VERSION_MINOR)
82 _RUBY_CONFIG_VAR("TEENY" RUBY_VERSION_PATCH)
84 # query the different directories
85 _RUBY_CONFIG_VAR("archdir" RUBY_ARCH_DIR)
86 _RUBY_CONFIG_VAR("arch" RUBY_ARCH)
87 _RUBY_CONFIG_VAR("rubyhdrdir" RUBY_HDR_DIR)
88 _RUBY_CONFIG_VAR("libdir" RUBY_POSSIBLE_LIB_DIR)
89 _RUBY_CONFIG_VAR("rubylibdir" RUBY_RUBY_LIB_DIR)
92 _RUBY_CONFIG_VAR("sitearchdir" RUBY_SITEARCH_DIR)
93 _RUBY_CONFIG_VAR("sitelibdir" RUBY_SITELIB_DIR)
95 # vendor_ruby available ?
96 execute_process(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
97 OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET)
99 if(RUBY_HAS_VENDOR_RUBY)
100 _RUBY_CONFIG_VAR("vendorlibdir" RUBY_VENDORLIB_DIR)
101 _RUBY_CONFIG_VAR("vendorarchdir" RUBY_VENDORARCH_DIR)
104 # save the results in the cache so we don't have to run ruby the next time again
105 set(RUBY_VERSION_MAJOR ${RUBY_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
106 set(RUBY_VERSION_MINOR ${RUBY_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
107 set(RUBY_VERSION_PATCH ${RUBY_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
108 set(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
109 set(RUBY_HDR_DIR ${RUBY_HDR_DIR} CACHE PATH "The Ruby header dir (1.9)" FORCE)
110 set(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
111 set(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
112 set(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
113 set(RUBY_SITELIB_DIR ${RUBY_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
114 set(RUBY_HAS_VENDOR_RUBY ${RUBY_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
115 set(RUBY_VENDORARCH_DIR ${RUBY_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
116 set(RUBY_VENDORLIB_DIR ${RUBY_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
122 RUBY_POSSIBLE_LIB_DIR
135 # In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling)
136 # try to detect which version we found. This is not too good.
137 if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR)
138 # by default assume 1.8.0
139 set(RUBY_VERSION_MAJOR 1)
140 set(RUBY_VERSION_MINOR 8)
141 set(RUBY_VERSION_PATCH 0)
142 # check whether we found 1.9.x
143 if(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
144 set(RUBY_VERSION_MAJOR 1)
145 set(RUBY_VERSION_MINOR 9)
149 if(RUBY_VERSION_MAJOR)
150 set(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}")
151 set(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}")
152 set(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}")
153 set(_RUBY_NODOT_VERSION "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}")
156 find_path(RUBY_INCLUDE_DIR
161 /usr/lib/ruby/${_RUBY_VERSION_SHORT}/i586-linux-gnu/ )
163 set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} )
165 # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
166 if( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_RUBY_VERSION_SHORT_NODOT}" GREATER 18 OR RUBY_HDR_DIR)
167 find_path(RUBY_CONFIG_INCLUDE_DIR
168 NAMES ruby/config.h config.h
170 ${RUBY_HDR_DIR}/${RUBY_ARCH}
174 set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} )
178 # Determine the list of possible names for the ruby library
179 set(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT} ruby${_RUBY_VERSION_SHORT_NODOT} ruby-${_RUBY_VERSION_SHORT} ruby-${RUBY_VERSION})
182 set( _RUBY_MSVC_RUNTIME "" )
184 set( _RUBY_MSVC_RUNTIME "60" )
187 set( _RUBY_MSVC_RUNTIME "70" )
190 set( _RUBY_MSVC_RUNTIME "71" )
193 set( _RUBY_MSVC_RUNTIME "80" )
196 set( _RUBY_MSVC_RUNTIME "90" )
199 list(APPEND _RUBY_POSSIBLE_LIB_NAMES
200 "msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}"
201 "msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}-static"
202 "msvcrt-ruby${_RUBY_NODOT_VERSION}"
203 "msvcrt-ruby${_RUBY_NODOT_VERSION}-static" )
206 find_library(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} )
208 include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
209 set(_RUBY_REQUIRED_VARS RUBY_EXECUTABLE RUBY_INCLUDE_DIR RUBY_LIBRARY)
210 if(_RUBY_VERSION_SHORT_NODOT GREATER 18)
211 list(APPEND _RUBY_REQUIRED_VARS RUBY_CONFIG_INCLUDE_DIR)
214 if(_RUBY_DEBUG_OUTPUT)
215 message(STATUS "--------FindRuby.cmake debug------------")
216 message(STATUS "_RUBY_POSSIBLE_EXECUTABLE_NAMES: ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}")
217 message(STATUS "_RUBY_POSSIBLE_LIB_NAMES: ${_RUBY_POSSIBLE_LIB_NAMES}")
218 message(STATUS "RUBY_ARCH_DIR: ${RUBY_ARCH_DIR}")
219 message(STATUS "RUBY_HDR_DIR: ${RUBY_HDR_DIR}")
220 message(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}")
221 message(STATUS "Found RUBY_VERSION: \"${RUBY_VERSION}\" , short: \"${_RUBY_VERSION_SHORT}\", nodot: \"${_RUBY_VERSION_SHORT_NODOT}\"")
222 message(STATUS "_RUBY_REQUIRED_VARS: ${_RUBY_REQUIRED_VARS}")
223 message(STATUS "RUBY_EXECUTABLE: ${RUBY_EXECUTABLE}")
224 message(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}")
225 message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}")
226 message(STATUS "RUBY_CONFIG_INCLUDE_DIR: ${RUBY_CONFIG_INCLUDE_DIR}")
227 message(STATUS "--------------------")
230 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_RUBY_REQUIRED_VARS}
231 VERSION_VAR RUBY_VERSION )
237 RUBY_CONFIG_INCLUDE_DIR
240 # Set some variables for compatibility with previous version of this file
241 set(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR})
242 set(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR})
243 set(RUBY_INCLUDE_PATH ${RUBY_INCLUDE_DIRS})