Introduce "generator expressions" to add_test()
[cmake.git] / Modules / FindRuby.cmake
blobea604f9b2b406d91baa06e47bc9c1c5640bb6b22
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:
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
10 # Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
11 # See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
14 #   RUBY_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
15 #   RUBY_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
16 #   RUBY_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
17 #   RUBY_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
18 #   RUBY_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
20 FIND_PROGRAM(RUBY_EXECUTABLE NAMES ruby ruby1.8 ruby18 ruby1.9 ruby19)
23 IF(RUBY_EXECUTABLE  AND NOT  RUBY_ARCH_DIR)
24    EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['archdir']"
25       OUTPUT_VARIABLE RUBY_ARCH_DIR)
27    EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['libdir']"
28       OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR)
30    EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubylibdir']"
31       OUTPUT_VARIABLE RUBY_RUBY_LIB_DIR)
33    # site_ruby
34    EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']"
35       OUTPUT_VARIABLE RUBY_SITEARCH_DIR)
37    EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitelibdir']"
38       OUTPUT_VARIABLE RUBY_SITELIB_DIR)
40    # vendor_ruby available ?
41    EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'"
42       OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY  ERROR_QUIET)
44    IF(RUBY_HAS_VENDOR_RUBY)
45       EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']"
46          OUTPUT_VARIABLE RUBY_VENDORLIB_DIR)
48       EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']"
49          OUTPUT_VARIABLE RUBY_VENDORARCH_DIR)
50    ENDIF(RUBY_HAS_VENDOR_RUBY)
52    # save the results in the cache so we don't have to run ruby the next time again
53    SET(RUBY_ARCH_DIR         ${RUBY_ARCH_DIR}         CACHE PATH "The Ruby arch dir")
54    SET(RUBY_POSSIBLE_LIB_DIR ${RUBY_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir")
55    SET(RUBY_RUBY_LIB_DIR     ${RUBY_RUBY_LIB_DIR}     CACHE PATH "The Ruby ruby-lib dir")
56    SET(RUBY_SITEARCH_DIR     ${RUBY_SITEARCH_DIR}     CACHE PATH "The Ruby site arch dir")
57    SET(RUBY_SITELIB_DIR      ${RUBY_SITELIB_DIR}      CACHE PATH "The Ruby site lib dir")
58    SET(RUBY_HAS_VENDOR_RUBY  ${RUBY_HAS_VENDOR_RUBY}  CACHE BOOL "Vendor Ruby is available")
59    SET(RUBY_VENDORARCH_DIR   ${RUBY_VENDORARCH_DIR}   CACHE PATH "The Ruby vendor arch dir")
60    SET(RUBY_VENDORLIB_DIR    ${RUBY_VENDORLIB_DIR}    CACHE PATH "The Ruby vendor lib dir")
62 ENDIF(RUBY_EXECUTABLE  AND NOT  RUBY_ARCH_DIR)
64 # for compatibility
65 SET(RUBY_POSSIBLE_LIB_PATH ${RUBY_POSSIBLE_LIB_DIR})
66 SET(RUBY_RUBY_LIB_PATH ${RUBY_RUBY_LIB_DIR})
69 FIND_PATH(RUBY_INCLUDE_PATH
70    NAMES ruby.h
71    PATHS
72    ${RUBY_ARCH_DIR}
73   /usr/lib/ruby/1.8/i586-linux-gnu/ )
75 # search the ruby library, the version for MSVC can have the "msvc" prefix and the "static" suffix
76 FIND_LIBRARY(RUBY_LIBRARY
77   NAMES ruby ruby1.8 ruby1.9
78         msvcrt-ruby18 msvcrt-ruby19 msvcrt-ruby18-static msvcrt-ruby19-static
79   PATHS ${RUBY_POSSIBLE_LIB_DIR}
80   )
82 MARK_AS_ADVANCED(
83   RUBY_EXECUTABLE
84   RUBY_LIBRARY
85   RUBY_INCLUDE_PATH
86   RUBY_ARCH_DIR
87   RUBY_POSSIBLE_LIB_DIR
88   RUBY_RUBY_LIB_DIR
89   RUBY_SITEARCH_DIR
90   RUBY_SITELIB_DIR
91   RUBY_HAS_VENDOR_RUBY
92   RUBY_VENDORARCH_DIR
93   RUBY_VENDORLIB_DIR
94   )