CMake/Modules/FindRuby.cmake

244 lines
10 KiB
CMake
Raw Normal View History

# - Find Ruby
# This module finds if Ruby is installed and determines where the include files
# and libraries are. Ruby 1.8 and 1.9 are supported.
#
# The minimum required version of Ruby can be specified using the
# standard syntax, e.g. FIND_PACKAGE(Ruby 1.8)
#
# It also determines what the name of the library is. This
# code sets the following variables:
#
2005-12-15 22:17:43 +03:00
# RUBY_EXECUTABLE = full path to the ruby binary
# RUBY_INCLUDE_DIRS = include dirs to be used when using the ruby library
# RUBY_LIBRARY = full path to the ruby library
# RUBY_VERSION = the version of ruby which was found, e.g. "1.8.7"
# 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
#=============================================================================
# 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.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# 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"@:>@)'`
# uncomment the following line to get debug output for this file
# SET(_RUBY_DEBUG_OUTPUT TRUE)
# Determine the list of possible names of the ruby executable depending
# on which version of ruby is required
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(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
SET(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${RUBY_FIND_VERSION_MINOR}")
ELSE(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
SET(Ruby_FIND_VERSION_SHORT_NODOT "18")
ENDIF(Ruby_FIND_VERSION_MAJOR AND Ruby_FIND_VERSION_MINOR)
SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.9 ruby19)
# if we want a version below 1.9, also look for ruby 1.8
IF("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
SET(_RUBY_POSSIBLE_EXECUTABLE_NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES} ruby1.8 ruby18)
ENDIF("${Ruby_FIND_VERSION_SHORT_NODOT}" VERSION_LESS "19")
FIND_PROGRAM(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES})
IF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
# query the ruby version
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MAJOR']"
OUTPUT_VARIABLE RUBY_VERSION_MAJOR)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MINOR']"
OUTPUT_VARIABLE RUBY_VERSION_MINOR)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['TEENY']"
OUTPUT_VARIABLE RUBY_VERSION_PATCH)
# query the different directories
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['archdir']"
OUTPUT_VARIABLE RUBY_ARCH_DIR)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['arch']"
OUTPUT_VARIABLE RUBY_ARCH)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubyhdrdir']"
OUTPUT_VARIABLE RUBY_HDR_DIR)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['libdir']"
OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubylibdir']"
OUTPUT_VARIABLE RUBY_RUBY_LIB_DIR)
# site_ruby
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']"
OUTPUT_VARIABLE RUBY_SITEARCH_DIR)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitelibdir']"
OUTPUT_VARIABLE RUBY_SITELIB_DIR)
# vendor_ruby available ?
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET)
IF(RUBY_HAS_VENDOR_RUBY)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']"
OUTPUT_VARIABLE RUBY_VENDORLIB_DIR)
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']"
OUTPUT_VARIABLE RUBY_VENDORARCH_DIR)
ENDIF(RUBY_HAS_VENDOR_RUBY)
# save the results in the cache so we don't have to run ruby the next time again
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(
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
)
ENDIF(RUBY_EXECUTABLE AND NOT RUBY_MAJOR_VERSION)
# In case RUBY_EXECUTABLE could not be executed (e.g. cross compiling)
# try to detect which version we found. This is not too good.
IF(NOT RUBY_VERSION_MAJOR)
# by default assume 1.8.0
SET(RUBY_VERSION_MAJOR 1)
SET(RUBY_VERSION_MINOR 8)
SET(RUBY_VERSION_PATCH 0)
# check whether we found 1.9.x
IF(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
SET(RUBY_VERSION_MAJOR 1)
SET(RUBY_VERSION_MINOR 9)
ENDIF(${RUBY_EXECUTABLE} MATCHES "ruby1.?9" OR RUBY_HDR_DIR)
ENDIF(NOT 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}")
FIND_PATH(RUBY_INCLUDE_DIR
NAMES ruby.h
HINTS
${RUBY_HDR_DIR}
${RUBY_ARCH_DIR}
/usr/lib/ruby/${_RUBY_VERSION_SHORT}/i586-linux-gnu/ )
SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIR} )
# if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
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
NAMES ruby/config.h config.h
HINTS
${RUBY_HDR_DIR}/${RUBY_ARCH}
${RUBY_ARCH_DIR}
)
SET(RUBY_INCLUDE_DIRS ${RUBY_INCLUDE_DIRS} ${RUBY_CONFIG_INCLUDE_DIR} )
ENDIF( ${Ruby_FIND_VERSION_SHORT_NODOT} GREATER 18 OR ${_RUBY_VERSION_SHORT_NODOT} GREATER 18 OR RUBY_HDR_DIR)
# Determine the list of possible names for the ruby library
SET(_RUBY_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_RUBY_VERSION_SHORT})
IF(WIN32)
SET( _RUBY_MSVC_RUNTIME "" )
IF( MSVC60 )
SET( _RUBY_MSVC_RUNTIME "60" )
ENDIF( MSVC60 )
IF( MSVC70 )
SET( _RUBY_MSVC_RUNTIME "70" )
ENDIF( MSVC70 )
IF( MSVC71 )
SET( _RUBY_MSVC_RUNTIME "71" )
ENDIF( MSVC71 )
IF( MSVC80 )
SET( _RUBY_MSVC_RUNTIME "80" )
ENDIF( MSVC80 )
IF( MSVC90 )
SET( _RUBY_MSVC_RUNTIME "90" )
ENDIF( MSVC90 )
LIST(APPEND _RUBY_POSSIBLE_LIB_NAMES
"msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}"
"msvcr${_RUBY_MSVC_RUNTIME}-ruby${_RUBY_NODOT_VERSION}-static"
"msvcrt-ruby${_RUBY_NODOT_VERSION}"
"msvcrt-ruby${_RUBY_NODOT_VERSION}-static" )
ENDIF(WIN32)
FIND_LIBRARY(RUBY_LIBRARY NAMES ${_RUBY_POSSIBLE_LIB_NAMES} HINTS ${RUBY_POSSIBLE_LIB_DIR} )
Modules: Include builtin FindPackageHandleStandardArgs directly The FindPackageHandleStandardArgs module was originally created outside of CMake. It was added for CMake 2.6.0 by commit e118a627 (add a macro FIND_PACKAGE_HANDLE_STANDARD_ARGS..., 2007-07-18). However, it also proliferated into a number of other projects that at the time required only CMake 2.4 and thus could not depend on CMake to provide the module. CMake's own find modules started using the module in commit b5f656e0 (use the new FIND_PACKAGE_HANDLE_STANDARD_ARGS in some of the FindXXX modules..., 2007-07-18). Then commit d358cf5c (add 2nd, more powerful mode to find_package_handle_standard_args, 2010-07-29) added a new feature to the interface of the module that was fully optional and backward compatible with all existing users of the module. Later commit 5f183caa (FindZLIB: use the FPHSA version mode, 2010-08-04) and others shortly thereafter started using the new interface in CMake's own find modules. This change was also backward compatible because it was only an implementation detail within each module. Unforutnately these changes introduced a problem for projects that still have an old copy of FindPackageHandleStandardArgs in CMAKE_MODULE_PATH. When any such project uses one of CMake's builtin find modules the line include(FindPackageHandleStandardArgs) loads the copy from the project which does not have the new interface! Then the including find module tries to use the new interface with the old module and fails. Whether this breakage can be considered a backward incompatible change in CMake is debatable. The situation is analagous to copying a standard library header from one version of a compiler into a project and then observing problems when the next version of the compiler reports errors in its other headers that depend on its new version of the original header. Nevertheless it is a change to CMake that causes problems for projects that worked with previous versions. This problem was discovered during the 2.8.3 release candidate cycle. It is an instance of a more general problem with projects that provide their own versions of CMake modules when other CMake modules depend on them. At the time we resolved this instance of the problem with commit b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake everywhere, 2010-09-28) for the 2.8.3 release. In order to address the more general problem we introduced policy CMP0017 in commit db44848f (Prefer files from CMAKE_ROOT when including from CMAKE_ROOT, 2010-11-17). That change was followed by commit ce28737c (Remove usage of CMAKE_CURRENT_LIST_DIR now that we have CMP0017, 2010-12-20) which reverted the original workaround in favor of using the policy. However, existing project releases do not set the policy behavior to NEW and therefore still exhibit the problem. We introduced in commit a364daf1 (Allow users to specify defaults for unset policies, 2011-01-03) an option for users to build existing projects by adding -DCMAKE_POLICY_DEFAULT_CMP0017=NEW to the command line. Unfortunately this solution still does not allow such projects to build out of the box, and there is no good way to suggest the use of the new option. The only remaining solution to keep existing projects that exhibit this problem building is to restore the change originally made in commit b0118402 (Use absolute path to FindPackageHandleStandardArgs.cmake everywhere, 2010-09-28). This also avoids policy CMP0017 warnings for this particular instance of the problem the policy addresses.
2011-01-20 18:56:49 +03:00
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)
ENDIF(_RUBY_VERSION_SHORT_NODOT GREATER 18)
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 "--------------------")
ENDIF(_RUBY_DEBUG_OUTPUT)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_RUBY_REQUIRED_VARS}
VERSION_VAR RUBY_VERSION )
MARK_AS_ADVANCED(
RUBY_EXECUTABLE
RUBY_LIBRARY
RUBY_INCLUDE_DIR
RUBY_CONFIG_INCLUDE_DIR
)
# Set some variables for compatibility with previous version of this file
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})