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. The minimum required version
4 # specified in the find_package() command is honored.
5 # It also determines what the name of the library is. This
6 # code sets the following variables:
8 # RUBY_EXECUTABLE = full path to the ruby binary
9 # RUBY_INCLUDE_DIRS = include dirs to be used when using the ruby library
10 # RUBY_LIBRARY = full path to the ruby library
11 # RUBY_FOUND = set to true if ruby ws found successfully
13 # RUBY_INCLUDE_PATH = same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
15 # Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
16 # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
19 # RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
20 # RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
21 # RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
22 # RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
23 # RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
25 # uncomment the following line to get debug output for this file
26 # SET(_RUBY_DEBUG_OUTPUT TRUE)
28 # Determine the list of possible names of the ruby executable depending
29 # on which version of ruby is required
30 SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ruby)
32 # if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8
33 IF(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
34 SET(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${RUBY_FIND_VERSION_MINOR}")
35 ELSE(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
36 SET(Ruby_FIND_VERSION_SHORT_NODOT "18")
37 ENDIF(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
39 SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.9 ruby19)
41 # if we want a version below 1.9, also look for ruby 1.8
42 IF("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
43 SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.8 ruby18)
44 ENDIF("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
46 FIND_PROGRAM(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})
49 IF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
50 # query the ruby version
51 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MAJOR']"
52 OUTPUT_VARIABLE RUBY_VERSION_MAJOR)
54 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MINOR']"
55 OUTPUT_VARIABLE RUBY_VERSION_MINOR)
57 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['TEENY']"
58 OUTPUT_VARIABLE RUBY_VERSION_PATCH)
60 # query the different directories
61 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['archdir']"
62 OUTPUT_VARIABLE RUBY_ARCH_DIR)
64 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['arch']"
65 OUTPUT_VARIABLE RUBY_ARCH)
67 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubyhdrdir']"
68 OUTPUT_VARIABLE RUBY_HDR_DIR)
70 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['libdir']"
71 OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR)
73 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubylibdir']"
74 OUTPUT_VARIABLE RUBY_RUBY_LIB_DIR)
77 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']"
78 OUTPUT_VARIABLE RUBY_SITEARCH_DIR)
80 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitelibdir']"
81 OUTPUT_VARIABLE RUBY_SITELIB_DIR)
83 # vendor_ruby available ?
84 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
85 OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET)
87 IF(RUBY_HAS_VENDOR_RUBY)
88 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']"
89 OUTPUT_VARIABLE RUBY_VENDORLIB_DIR)
91 EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']"
92 OUTPUT_VARIABLE RUBY_VENDORARCH_DIR)
93 ENDIF(RUBY_HAS_VENDOR_RUBY)
95 # save the results in the cache so we don't have to run ruby the next time again
96 SET(RUBY_VERSION_MAJOR ${RUBY_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
97 SET(RUBY_VERSION_MINOR ${RUBY_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
98 SET(RUBY_VERSION_PATCH ${RUBY_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
99 SET(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
100 SET(RUBY_HDR_DIR ${RUBY_HDR_DIR} CACHE PATH "The Ruby header dir (1.9)" FORCE)
101 SET(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
102 SET(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
103 SET(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
104 SET(RUBY_SITELIB_DIR ${RUBY_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
105 SET(RUBY_HAS_VENDOR_RUBY ${RUBY_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
106 SET(RUBY_VENDORARCH_DIR ${RUBY_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
107 SET(RUBY_VENDORLIB_DIR ${RUBY_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
113 RUBY_POSSIBLE_LIB_DIR
124 ENDIF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
126 # In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling)
127 # try to detect which version we found. This is not too good.
128 IF(NOT RUBY_VERSION_MAJOR)
129 # by default assume 1.8.0
130 SET(RUBY_VERSION_MAJOR 1)
131 SET(RUBY_VERSION_MINOR 8)
132 SET(RUBY_VERSION_PATCH 0)
133 # check whether we found 1.9.x
134 IF(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
135 SET(RUBY_VERSION_MAJOR 1)
136 SET(RUBY_VERSION_MINOR 9)
137 ENDIF(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
138 ENDIF(NOT RUBY_VERSION_MAJOR)
141 SET(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}")
142 SET(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}")
143 SET(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}")
145 # Now we know which version we found
146 IF(Ruby_FIND_VERSION)
147 IF(${RUBY_VERSION} VERSION_LESS ${Ruby_FIND_VERSION})
148 # force running ruby the next time again
149 SET(RUBY_VERSION_MAJOR "" CACHE PATH "The Ruby major version" FORCE)
150 IF(Ruby_FIND_REQUIRED)
151 MESSAGE(FATAL_ERROR "Ruby version ${Ruby_FIND_VERSION} required, but only version ${RUBY_VERSION} found.")
152 ELSE(Ruby_FIND_REQUIRED)
153 IF(NOT Ruby_FIND_QUIETLY)
154 MESSAGE(STATUS "Ruby version ${Ruby_FIND_VERSION} required, but only version ${RUBY_VERSION} found.")
155 ENDIF(NOT Ruby_FIND_QUIETLY)
157 ENDIF(Ruby_FIND_REQUIRED)
158 ENDIF(${RUBY_VERSION} VERSION_LESS ${Ruby_FIND_VERSION})
159 ENDIF(Ruby_FIND_VERSION)
161 FIND_PATH(RUBY_INCLUDE_DIR
166 /usr/lib/ruby/${_RUBY_VERSION_SHORT}/i586-linux-gnu/ )
168 SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} )
170 # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
171 IF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR)
172 message(STATUS "lookign for config.h")
173 FIND_PATH(RUBY_CONFIG_INCLUDE_DIR
174 NAMES ruby/config.h config.h
176 ${RUBY_HDR_DIR}/${RUBY_ARCH}
180 SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} )
181 ENDIF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR)
184 # Determine the list of possible names for the ruby library
185 SET(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT})
188 SET( _RUBY_MSVC_RUNTIME "" )
190 SET( _RUBY_MSVC_RUNTIME "60" )
193 SET( _RUBY_MSVC_RUNTIME "70" )
196 SET( _RUBY_MSVC_RUNTIME "71" )
199 SET( _RUBY_MSVC_RUNTIME "80" )
202 SET( _RUBY_MSVC_RUNTIME "90" )
205 LIST(APPEND _RUBY_POSSIBLE_LIB_NAMES
206 "msvcr${_RUBY_MSVC_RUNTIME}-ruby${RUBY_NODOT_VERSION}"
207 "msvcr${_RUBY_MSVC_RUNTIME}-ruby${RUBY_NODOT_VERSION}-static"
208 "msvcrt-ruby${RUBY_NODOT_VERSION}"
209 "msvcrt-ruby${RUBY_NODOT_VERSION}-static" )
212 FIND_LIBRARY(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} )
214 INCLUDE(FindPackageHandleStandardArgs)
215 SET(_RUBY_REQUIRED_VARS RUBY_EXECUTABLE RUBY_INCLUDE_DIR RUBY_LIBRARY)
216 IF(_RUBY_VERSION_SHORT_NODOT GREATER 18)
217 LIST(APPEND _RUBY_REQUIRED_VARS RUBY_CONFIG_INCLUDE_DIR)
218 ENDIF(_RUBY_VERSION_SHORT_NODOT GREATER 18)
220 IF(_RUBY_DEBUG_OUTPUT)
221 MESSAGE(STATUS "--------FindRuby.cmake debug------------")
222 MESSAGE(STATUS "_RUBY_POSSIBLE_EXECUTABLE_NAMES: ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}")
223 MESSAGE(STATUS "_RUBY_POSSIBLE_LIB_NAMES: ${_RUBY_POSSIBLE_LIB_NAMES}")
224 MESSAGE(STATUS "RUBY_ARCH_DIR: ${RUBY_ARCH_DIR}")
225 MESSAGE(STATUS "RUBY_HDR_DIR: ${RUBY_HDR_DIR}")
226 MESSAGE(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}")
227 MESSAGE(STATUS "Found RUBY_VERSION: \"${RUBY_VERSION}\" , short: \"${_RUBY_VERSION_SHORT}\", nodot: \"${_RUBY_VERSION_SHORT_NODOT}\"")
228 MESSAGE(STATUS "_RUBY_REQUIRED_VARS: ${_RUBY_REQUIRED_VARS}")
229 MESSAGE(STATUS "--------------------")
230 ENDIF(_RUBY_DEBUG_OUTPUT)
232 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby DEFAULT_MSG ${_RUBY_REQUIRED_VARS})
238 RUBY_CONFIG_INCLUDE_DIR
241 # Set some variables for compatibility with previous version of this file
242 SET(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR})
243 SET(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR})
244 SET(RUBY_INCLUDE_PATH ${RUBY_INCLUDE_DIRS})