FindRuby.cmake 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # - Find Ruby
  2. # This module finds if Ruby is installed and determines where the include files
  3. # and libraries are. It also determines what the name of the library is. This
  4. # code sets the following variables:
  5. #
  6. # RUBY_INCLUDE_PATH = path to where ruby.h can be found
  7. # RUBY_EXECUTABLE = full path to the ruby binary
  8. # RUBY_LIBRARY = full path to the ruby library
  9. # Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  10. # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  11. # RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
  12. # RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
  13. # RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
  14. # RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
  15. # RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
  16. FIND_PROGRAM(RUBY_EXECUTABLE NAMES ruby ruby1.8 ruby18 ruby1.9 ruby19)
  17. IF(RUBY_EXECUTABLE AND NOT RUBY_ARCH_DIR)
  18. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['archdir']"
  19. OUTPUT_VARIABLE RUBY_ARCH_DIR)
  20. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['libdir']"
  21. OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR)
  22. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubylibdir']"
  23. OUTPUT_VARIABLE RUBY_RUBY_LIB_DIR)
  24. # site_ruby
  25. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']"
  26. OUTPUT_VARIABLE RUBY_SITEARCH_DIR)
  27. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitelibdir']"
  28. OUTPUT_VARIABLE RUBY_SITELIB_DIR)
  29. # vendor_ruby available ?
  30. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
  31. OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET)
  32. IF(RUBY_HAS_VENDOR_RUBY)
  33. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']"
  34. OUTPUT_VARIABLE RUBY_VENDORLIB_DIR)
  35. EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']"
  36. OUTPUT_VARIABLE RUBY_VENDORARCH_DIR)
  37. ENDIF(RUBY_HAS_VENDOR_RUBY)
  38. # save the results in the cache so we don't have to run ruby the next time again
  39. SET(RUBY_ARCH_DIR ${RUBY_ARCH_DIR} CACHE PATH "The Ruby arch dir")
  40. SET(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir")
  41. SET(RUBY_RUBY_LIB_DIR ${RUBY_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir")
  42. SET(RUBY_SITEARCH_DIR ${RUBY_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir")
  43. SET(RUBY_SITELIB_DIR ${RUBY_SITELIB_DIR} CACHE PATH "The Ruby site lib dir")
  44. SET(RUBY_HAS_VENDOR_RUBY ${RUBY_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available")
  45. SET(RUBY_VENDORARCH_DIR ${RUBY_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir")
  46. SET(RUBY_VENDORLIB_DIR ${RUBY_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir")
  47. ENDIF(RUBY_EXECUTABLE AND NOT RUBY_ARCH_DIR)
  48. # for compatibility
  49. SET(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR})
  50. SET(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR})
  51. FIND_PATH(RUBY_INCLUDE_PATH
  52. NAMES ruby.h
  53. PATHS
  54. ${RUBY_ARCH_DIR}
  55. /usr/lib/ruby/1.8/i586-linux-gnu/ )
  56. # search the ruby library, the version for MSVC can have the "msvc" prefix and the "static" suffix
  57. FIND_LIBRARY(RUBY_LIBRARY
  58. NAMES ruby ruby1.8 ruby1.9
  59. msvcrt-ruby18 msvcrt-ruby19 msvcrt-ruby18-static msvcrt-ruby19-static
  60. PATHS ${RUBY_POSSIBLE_LIB_DIR}
  61. )
  62. MARK_AS_ADVANCED(
  63. RUBY_EXECUTABLE
  64. RUBY_LIBRARY
  65. RUBY_INCLUDE_PATH
  66. RUBY_ARCH_DIR
  67. RUBY_POSSIBLE_LIB_DIR
  68. RUBY_RUBY_LIB_DIR
  69. RUBY_SITEARCH_DIR
  70. RUBY_SITELIB_DIR
  71. RUBY_HAS_VENDOR_RUBY
  72. RUBY_VENDORARCH_DIR
  73. RUBY_VENDORLIB_DIR
  74. )