2006-10-04 23:54:25 +04:00
|
|
|
# - Find Ruby
|
|
|
|
# This module finds if Ruby is installed and determines where the include files
|
2010-08-08 00:08:51 +04:00
|
|
|
# and libraries are. Ruby 1.8 and 1.9 are supported.
|
|
|
|
#
|
|
|
|
# The minimum required version of Ruby can be specified using the
|
2012-08-13 21:47:32 +04:00
|
|
|
# standard syntax, e.g. find_package(Ruby 1.8)
|
2010-08-08 00:08:51 +04:00
|
|
|
#
|
2009-09-12 14:25:58 +04:00
|
|
|
# It also determines what the name of the library is. This
|
2004-04-30 20:11:02 +04:00
|
|
|
# code sets the following variables:
|
|
|
|
#
|
2005-12-15 22:17:43 +03:00
|
|
|
# RUBY_EXECUTABLE = full path to the ruby binary
|
2009-09-12 14:25:58 +04:00
|
|
|
# RUBY_INCLUDE_DIRS = include dirs to be used when using the ruby library
|
2008-01-02 20:32:17 +03:00
|
|
|
# RUBY_LIBRARY = full path to the ruby library
|
2009-09-26 13:08:20 +04:00
|
|
|
# RUBY_VERSION = the version of ruby which was found, e.g. "1.8.7"
|
2009-09-12 14:25:58 +04:00
|
|
|
# RUBY_FOUND = set to true if ruby ws found successfully
|
|
|
|
#
|
|
|
|
# RUBY_INCLUDE_PATH = same as RUBY_INCLUDE_DIRS, only provided for compatibility reasons, don't use it
|
2004-04-30 20:11:02 +04:00
|
|
|
|
2009-09-28 19:45:50 +04:00
|
|
|
#=============================================================================
|
|
|
|
# Copyright 2004-2009 Kitware, Inc.
|
|
|
|
# Copyright 2008-2009 Alexander Neundorf <neundorf@kde.org>
|
|
|
|
#
|
|
|
|
# Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
# see accompanying file Copyright.txt for details.
|
|
|
|
#
|
|
|
|
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
# See the License for more information.
|
|
|
|
#=============================================================================
|
2010-08-07 04:48:47 +04:00
|
|
|
# (To distribute this file outside of CMake, substitute the full
|
2009-09-28 19:45:50 +04:00
|
|
|
# License text for the above reference.)
|
2004-04-30 20:11:02 +04:00
|
|
|
|
2006-10-04 23:54:25 +04:00
|
|
|
# RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
|
|
|
|
# RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
|
|
|
|
# RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
|
|
|
|
# RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
|
|
|
|
# RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
|
|
|
|
|
2009-09-12 14:25:58 +04:00
|
|
|
# uncomment the following line to get debug output for this file
|
2012-08-13 21:47:32 +04:00
|
|
|
# set(_RUBY_DEBUG_OUTPUT TRUE)
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
# Determine the list of possible names of the ruby executable depending
|
|
|
|
# on which version of ruby is required
|
2012-08-13 21:47:32 +04:00
|
|
|
set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ruby)
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
# if 1.9 is required, don't look for ruby18 and ruby1.8, default to version 1.8
|
2012-08-13 21:47:32 +04:00
|
|
|
if(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
|
|
|
|
set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${RUBY_FIND_VERSION_MINOR}")
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
set(Ruby_FIND_VERSION_SHORT_NODOT "18")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2009-09-12 14:25:58 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.9 ruby19)
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
# if we want a version below 1.9, also look for ruby 1.8
|
2012-08-13 21:47:32 +04:00
|
|
|
if("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
|
|
|
|
set(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.8 ruby18)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2006-10-04 23:54:25 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
find_program(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})
|
2006-10-04 23:54:25 +04:00
|
|
|
|
2009-09-12 14:25:58 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
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}']"
|
2012-02-17 21:06:07 +04:00
|
|
|
RESULT_VARIABLE _RUBY_SUCCESS
|
|
|
|
OUTPUT_VARIABLE _RUBY_OUTPUT
|
|
|
|
ERROR_QUIET)
|
2012-08-13 21:47:32 +04:00
|
|
|
if(_RUBY_SUCCESS OR NOT _RUBY_OUTPUT)
|
|
|
|
execute_process(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
|
2012-02-17 21:06:07 +04:00
|
|
|
RESULT_VARIABLE _RUBY_SUCCESS
|
|
|
|
OUTPUT_VARIABLE _RUBY_OUTPUT
|
|
|
|
ERROR_QUIET)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
set(${OUTVAR} "${_RUBY_OUTPUT}" PARENT_SCOPE)
|
2012-08-13 21:50:14 +04:00
|
|
|
endfunction()
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
|
2012-02-17 21:06:07 +04:00
|
|
|
# query the ruby version
|
|
|
|
_RUBY_CONFIG_VAR("MAJOR" RUBY_VERSION_MAJOR)
|
|
|
|
_RUBY_CONFIG_VAR("MINOR" RUBY_VERSION_MINOR)
|
|
|
|
_RUBY_CONFIG_VAR("TEENY" RUBY_VERSION_PATCH)
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
# query the different directories
|
2012-02-17 21:06:07 +04:00
|
|
|
_RUBY_CONFIG_VAR("archdir" RUBY_ARCH_DIR)
|
|
|
|
_RUBY_CONFIG_VAR("arch" RUBY_ARCH)
|
|
|
|
_RUBY_CONFIG_VAR("rubyhdrdir" RUBY_HDR_DIR)
|
|
|
|
_RUBY_CONFIG_VAR("libdir" RUBY_POSSIBLE_LIB_DIR)
|
|
|
|
_RUBY_CONFIG_VAR("rubylibdir" RUBY_RUBY_LIB_DIR)
|
2008-01-02 20:32:17 +03:00
|
|
|
|
|
|
|
# site_ruby
|
2012-02-17 21:06:07 +04:00
|
|
|
_RUBY_CONFIG_VAR("sitearchdir" RUBY_SITEARCH_DIR)
|
|
|
|
_RUBY_CONFIG_VAR("sitelibdir" RUBY_SITELIB_DIR)
|
2008-01-02 20:32:17 +03:00
|
|
|
|
|
|
|
# vendor_ruby available ?
|
2012-08-13 21:47:32 +04:00
|
|
|
execute_process(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
|
2008-01-02 20:32:17 +03:00
|
|
|
OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(RUBY_HAS_VENDOR_RUBY)
|
2012-02-17 21:06:07 +04:00
|
|
|
_RUBY_CONFIG_VAR("vendorlibdir" RUBY_VENDORLIB_DIR)
|
|
|
|
_RUBY_CONFIG_VAR("vendorarchdir" RUBY_VENDORARCH_DIR)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2006-10-04 23:54:25 +04:00
|
|
|
|
2008-01-02 20:32:17 +03:00
|
|
|
# save the results in the cache so we don't have to run ruby the next time again
|
2012-08-13 21:47:32 +04:00
|
|
|
set(RUBY_VERSION_MAJOR ${RUBY_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
|
|
|
|
set(RUBY_VERSION_MINOR ${RUBY_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
|
|
|
|
set(RUBY_VERSION_PATCH ${RUBY_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
|
|
|
|
set(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
|
|
|
|
set(RUBY_HDR_DIR ${RUBY_HDR_DIR} CACHE PATH "The Ruby header dir (1.9)" FORCE)
|
|
|
|
set(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
|
|
|
|
set(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
|
|
|
|
set(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
|
|
|
|
set(RUBY_SITELIB_DIR ${RUBY_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
|
|
|
|
set(RUBY_HAS_VENDOR_RUBY ${RUBY_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
|
|
|
|
set(RUBY_VENDORARCH_DIR ${RUBY_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
|
|
|
|
set(RUBY_VENDORLIB_DIR ${RUBY_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
|
|
|
|
|
|
|
|
mark_as_advanced(
|
2009-09-12 14:25:58 +04:00
|
|
|
RUBY_ARCH_DIR
|
|
|
|
RUBY_ARCH
|
|
|
|
RUBY_HDR_DIR
|
|
|
|
RUBY_POSSIBLE_LIB_DIR
|
|
|
|
RUBY_RUBY_LIB_DIR
|
|
|
|
RUBY_SITEARCH_DIR
|
|
|
|
RUBY_SITELIB_DIR
|
|
|
|
RUBY_HAS_VENDOR_RUBY
|
|
|
|
RUBY_VENDORARCH_DIR
|
|
|
|
RUBY_VENDORLIB_DIR
|
|
|
|
RUBY_VERSION_MAJOR
|
|
|
|
RUBY_VERSION_MINOR
|
|
|
|
RUBY_VERSION_PATCH
|
|
|
|
)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2009-09-12 14:25:58 +04:00
|
|
|
|
2011-10-13 01:05:30 +04:00
|
|
|
# In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling)
|
2009-09-12 14:25:58 +04:00
|
|
|
# try to detect which version we found. This is not too good.
|
2012-08-13 21:47:32 +04:00
|
|
|
if(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR)
|
2009-09-12 14:25:58 +04:00
|
|
|
# by default assume 1.8.0
|
2012-08-13 21:47:32 +04:00
|
|
|
set(RUBY_VERSION_MAJOR 1)
|
|
|
|
set(RUBY_VERSION_MINOR 8)
|
|
|
|
set(RUBY_VERSION_PATCH 0)
|
2009-09-12 14:25:58 +04:00
|
|
|
# check whether we found 1.9.x
|
2012-08-13 21:47:32 +04:00
|
|
|
if(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
|
|
|
|
set(RUBY_VERSION_MAJOR 1)
|
|
|
|
set(RUBY_VERSION_MINOR 9)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
|
|
|
|
if(RUBY_VERSION_MAJOR)
|
|
|
|
set(RUBY_VERSION "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}.${RUBY_VERSION_PATCH}")
|
|
|
|
set(_RUBY_VERSION_SHORT "${RUBY_VERSION_MAJOR}.${RUBY_VERSION_MINOR}")
|
|
|
|
set(_RUBY_VERSION_SHORT_NODOT "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}")
|
|
|
|
set(_RUBY_NODOT_VERSION "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}${RUBY_VERSION_PATCH}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
|
|
|
|
find_path(RUBY_INCLUDE_DIR
|
2006-10-04 23:54:25 +04:00
|
|
|
NAMES ruby.h
|
2009-09-12 12:38:11 +04:00
|
|
|
HINTS
|
2009-09-12 14:25:58 +04:00
|
|
|
${RUBY_HDR_DIR}
|
2006-10-04 23:54:25 +04:00
|
|
|
${RUBY_ARCH_DIR}
|
2009-09-12 14:25:58 +04:00
|
|
|
/usr/lib/ruby/${_RUBY_VERSION_SHORT}/i586-linux-gnu/ )
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} )
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
# if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
|
2012-08-13 21:47:32 +04:00
|
|
|
if( "${Ruby_FIND_VERSION_SHORT_NODOT}" GREATER 18 OR "${_RUBY_VERSION_SHORT_NODOT}" GREATER 18 OR RUBY_HDR_DIR)
|
|
|
|
find_path(RUBY_CONFIG_INCLUDE_DIR
|
2009-09-12 14:25:58 +04:00
|
|
|
NAMES ruby/config.h config.h
|
2011-10-13 01:05:30 +04:00
|
|
|
HINTS
|
2009-09-12 14:25:58 +04:00
|
|
|
${RUBY_HDR_DIR}/${RUBY_ARCH}
|
2011-10-13 01:05:30 +04:00
|
|
|
${RUBY_ARCH_DIR}
|
2009-09-12 14:25:58 +04:00
|
|
|
)
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} )
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
|
|
|
|
# Determine the list of possible names for the ruby library
|
2012-08-13 21:47:32 +04:00
|
|
|
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( MSVC60 )
|
|
|
|
set( _RUBY_MSVC_RUNTIME "60" )
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if( MSVC70 )
|
|
|
|
set( _RUBY_MSVC_RUNTIME "70" )
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if( MSVC71 )
|
|
|
|
set( _RUBY_MSVC_RUNTIME "71" )
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if( MSVC80 )
|
|
|
|
set( _RUBY_MSVC_RUNTIME "80" )
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
if( MSVC90 )
|
|
|
|
set( _RUBY_MSVC_RUNTIME "90" )
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
|
|
|
|
list(APPEND _RUBY_POSSIBLE_LIB_NAMES
|
2010-01-03 22:21:17 +03:00
|
|
|
"msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}"
|
2011-10-13 01:05:30 +04:00
|
|
|
"msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}-static"
|
2010-01-03 22:21:17 +03:00
|
|
|
"msvcrt-ruby${_RUBY_NODOT_VERSION}"
|
|
|
|
"msvcrt-ruby${_RUBY_NODOT_VERSION}-static" )
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
|
|
|
|
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)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2012-08-13 21:47:32 +04:00
|
|
|
|
|
|
|
if(_RUBY_DEBUG_OUTPUT)
|
|
|
|
message(STATUS "--------FindRuby.cmake debug------------")
|
|
|
|
message(STATUS "_RUBY_POSSIBLE_EXECUTABLE_NAMES: ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}")
|
|
|
|
message(STATUS "_RUBY_POSSIBLE_LIB_NAMES: ${_RUBY_POSSIBLE_LIB_NAMES}")
|
|
|
|
message(STATUS "RUBY_ARCH_DIR: ${RUBY_ARCH_DIR}")
|
|
|
|
message(STATUS "RUBY_HDR_DIR: ${RUBY_HDR_DIR}")
|
|
|
|
message(STATUS "RUBY_POSSIBLE_LIB_DIR: ${RUBY_POSSIBLE_LIB_DIR}")
|
|
|
|
message(STATUS "Found RUBY_VERSION: \"${RUBY_VERSION}\" , short: \"${_RUBY_VERSION_SHORT}\", nodot: \"${_RUBY_VERSION_SHORT_NODOT}\"")
|
|
|
|
message(STATUS "_RUBY_REQUIRED_VARS: ${_RUBY_REQUIRED_VARS}")
|
|
|
|
message(STATUS "RUBY_EXECUTABLE: ${RUBY_EXECUTABLE}")
|
|
|
|
message(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}")
|
|
|
|
message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}")
|
|
|
|
message(STATUS "RUBY_CONFIG_INCLUDE_DIR: ${RUBY_CONFIG_INCLUDE_DIR}")
|
|
|
|
message(STATUS "--------------------")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2009-09-12 14:25:58 +04:00
|
|
|
|
2010-08-08 00:08:51 +04:00
|
|
|
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_RUBY_REQUIRED_VARS}
|
|
|
|
VERSION_VAR RUBY_VERSION )
|
2004-04-30 20:11:02 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
mark_as_advanced(
|
2004-04-30 20:11:02 +04:00
|
|
|
RUBY_EXECUTABLE
|
|
|
|
RUBY_LIBRARY
|
2009-09-12 14:25:58 +04:00
|
|
|
RUBY_INCLUDE_DIR
|
|
|
|
RUBY_CONFIG_INCLUDE_DIR
|
2004-04-30 20:11:02 +04:00
|
|
|
)
|
2009-09-12 14:25:58 +04:00
|
|
|
|
|
|
|
# Set some variables for compatibility with previous version of this file
|
2012-08-13 21:47:32 +04:00
|
|
|
set(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR})
|
|
|
|
set(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR})
|
|
|
|
set(RUBY_INCLUDE_PATH ${RUBY_INCLUDE_DIRS})
|