FindRuby

Finds Ruby installation and the locations of its include files and libraries:

find_package(Ruby [<version>] [...])

Ruby is a general-purpose programming language. This module supports Ruby 1.8 through 3.4. Virtual environments, such as RVM or RBENV, are also supported.

Result Variables

This module defines the following variables:

Ruby_FOUND

Boolean indicating whether (the requested version of) ruby is found.

Ruby_VERSION

The version of ruby which was found, e.g. 3.2.6.

Ruby_VERSION_MAJOR

Ruby major version.

Ruby_VERSION_MINOR

Ruby minor version.

Ruby_VERSION_PATCH

Ruby patch version.

Ruby_EXECUTABLE

The full path to the ruby binary.

Ruby_INCLUDE_DIRS

Include dirs to be used when using the ruby library.

Ruby_LIBRARIES

Added in version 3.18.

Libraries needed to use ruby from C.

Changed in version 3.18: Previous versions of CMake used the RUBY_ prefix for all variables.

Hints

This module accepts the following variables:

Ruby_FIND_VIRTUALENV

Added in version 3.18.

This variable defines the handling of virtual environments. It can be left empty or be set to one of the following values:

  • FIRST: Virtual Ruby environments are searched for first,

    then the system Ruby installation. This is the default.

  • ONLY: Only virtual environments are searched

  • STANDARD: Only the system Ruby installation is searched.

Virtual environments may be provided by:

rvm

Requires that the MY_RUBY_HOME environment environment is defined.

rbenv

Requires that rbenv is installed in ~/.rbenv/bin or that the RBENV_ROOT environment variable is defined.

Deprecated Variables

The following variables are provided for backward compatibility:

Deprecated since version 4.0: The following variables are deprecated. See policy CMP0185.

RUBY_FOUND

Same as Ruby_FOUND.

RUBY_VERSION

Same as Ruby_VERSION.

RUBY_EXECUTABLE

Same as Ruby_EXECUTABLE.

RUBY_INCLUDE_DIRS

Same as Ruby_INCLUDE_DIRS.

RUBY_INCLUDE_PATH

Same as Ruby_INCLUDE_DIRS.

RUBY_LIBRARY

Same as Ruby_LIBRARY.

Examples

Finding Ruby and specifying the minimum required version:

find_package(Ruby 3.2.6 EXACT REQUIRED)
# or
find_package(Ruby 3.2)