FindRuby.cmake 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindRuby
  5. --------
  6. This module determines if Ruby is installed and finds the locations of its
  7. include files and libraries. Ruby 1.8 through 3.4 are supported.
  8. The minimum required version of Ruby can be specified using the
  9. standard syntax, e.g.
  10. .. code-block:: cmake
  11. find_package(Ruby 3.2.6 EXACT REQUIRED)
  12. # OR
  13. find_package(Ruby 3.2)
  14. Virtual environments, such as RVM or RBENV, are supported.
  15. Result Variables
  16. ^^^^^^^^^^^^^^^^
  17. This module will set the following variables in your project:
  18. ``Ruby_FOUND``
  19. set to true if ruby was found successfully
  20. ``Ruby_EXECUTABLE``
  21. full path to the ruby binary
  22. ``Ruby_INCLUDE_DIRS``
  23. include dirs to be used when using the ruby library
  24. ``Ruby_LIBRARIES``
  25. .. versionadded:: 3.18
  26. libraries needed to use ruby from C.
  27. ``Ruby_VERSION``
  28. the version of ruby which was found, e.g. "3.2.6"
  29. ``Ruby_VERSION_MAJOR``
  30. Ruby major version.
  31. ``Ruby_VERSION_MINOR``
  32. Ruby minor version.
  33. ``Ruby_VERSION_PATCH``
  34. Ruby patch version.
  35. .. versionchanged:: 3.18
  36. Previous versions of CMake used the ``RUBY_`` prefix for all variables.
  37. The following variables are provided for compatibility reasons,
  38. don't use them in new code:
  39. ``RUBY_EXECUTABLE``
  40. same as Ruby_EXECUTABLE.
  41. ``RUBY_INCLUDE_DIRS``
  42. same as Ruby_INCLUDE_DIRS.
  43. ``RUBY_INCLUDE_PATH``
  44. same as Ruby_INCLUDE_DIRS.
  45. ``RUBY_LIBRARY``
  46. same as Ruby_LIBRARY.
  47. ``RUBY_VERSION``
  48. same as Ruby_VERSION.
  49. ``RUBY_FOUND``
  50. same as Ruby_FOUND.
  51. Hints
  52. ^^^^^
  53. ``Ruby_FIND_VIRTUALENV``
  54. .. versionadded:: 3.18
  55. This variable defines the handling of virtual environments.
  56. It can be left empty or be set to one of the following values:
  57. * ``FIRST``: Virtual Ruby environments are searched for first,
  58. then the system Ruby installation.
  59. This is the default.
  60. * ``ONLY``: Only virtual environments are searched
  61. * ``STANDARD``: Only the system Ruby installation is searched.
  62. Virtual environments may be provided by:
  63. ``rvm``
  64. Requires that the ``MY_RUBY_HOME`` environment environment is defined.
  65. ``rbenv``
  66. Requires that ``rbenv`` is installed in ``~/.rbenv/bin``
  67. or that the ``RBENV_ROOT`` environment variable is defined.
  68. #]=======================================================================]
  69. # Backwards compatibility
  70. # Define camel case versions of input variables
  71. foreach (UPPER
  72. RUBY_EXECUTABLE
  73. RUBY_LIBRARY
  74. RUBY_INCLUDE_DIR
  75. RUBY_CONFIG_INCLUDE_DIR)
  76. if (DEFINED ${UPPER})
  77. string(REPLACE "RUBY_" "Ruby_" Camel ${UPPER})
  78. if (NOT DEFINED ${Camel})
  79. set(${Camel} ${${UPPER}})
  80. endif ()
  81. endif ()
  82. endforeach ()
  83. # Ruby_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
  84. # Ruby_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
  85. # Ruby_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
  86. # Ruby_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
  87. # Ruby_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
  88. # uncomment the following line to get debug output for this file
  89. # set(_Ruby_DEBUG_OUTPUT TRUE)
  90. # Determine the list of possible names of the ruby executable depending
  91. # on which version of ruby is required
  92. set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby)
  93. # Set name of possible executables, ignoring the minor
  94. # Eg:
  95. # 3.2.6 => from ruby34 to ruby32 included
  96. # 3.2 => from ruby34 to ruby32 included
  97. # 3 => from ruby34 to ruby30 included
  98. # empty => from ruby34 to ruby18 included
  99. if (NOT Ruby_FIND_VERSION_EXACT)
  100. foreach (_ruby_version RANGE 34 18 -1)
  101. string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version)
  102. string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version)
  103. # Append both rubyX.Y and rubyXY (eg: ruby2.7 ruby27)
  104. list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby${_ruby_major_version}.${_ruby_minor_version} ruby${_ruby_major_version}${_ruby_minor_version})
  105. endforeach ()
  106. endif ()
  107. # Virtual environment handling
  108. if (DEFINED Ruby_FIND_VIRTUALENV AND NOT Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY|STANDARD)$")
  109. message(AUTHOR_WARNING "FindRuby: ${Ruby_FIND_VIRTUALENV}: invalid value for 'Ruby_FIND_VIRTUALENV'. 'FIRST', 'ONLY' or 'STANDARD' expected. 'FIRST' will be used instead.")
  110. set(Ruby_FIND_VIRTUALENV "FIRST")
  111. elseif (NOT DEFINED Ruby_FIND_VIRTUALENV)
  112. # Default is to search for virtual environments first
  113. set(Ruby_FIND_VIRTUALENV "FIRST")
  114. endif ()
  115. function(_RUBY_VALIDATE_INTERPRETER result_var path)
  116. # Get the interpreter version
  117. execute_process(COMMAND "${path}" -e "puts RUBY_VERSION"
  118. RESULT_VARIABLE result
  119. OUTPUT_VARIABLE version
  120. ERROR_QUIET
  121. OUTPUT_STRIP_TRAILING_WHITESPACE)
  122. if (NOT result EQUAL 0)
  123. set(_Ruby_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${path}\"")
  124. set(${result_var} FALSE PARENT_SCOPE)
  125. return()
  126. endif ()
  127. if (Ruby_FIND_VERSION)
  128. if (Ruby_FIND_VERSION_EXACT AND NOT version VERSION_EQUAL Ruby_FIND_VERSION)
  129. message(DEBUG "Incorrect Ruby found. Requested: ${Ruby_FIND_VERSION}. Found: ${version}. Path: \"${path}\"")
  130. set(${result_var} FALSE PARENT_SCOPE)
  131. return()
  132. elseif (version VERSION_LESS Ruby_FIND_VERSION)
  133. message(DEBUG "Ruby version is too old. Minimum: ${Ruby_FIND_VERSION}. Found: ${version}. Path: \"${path}\"")
  134. set(${result_var} FALSE PARENT_SCOPE)
  135. return()
  136. endif ()
  137. endif ()
  138. # Found valid Ruby interpreter!
  139. set(${result_var} TRUE PARENT_SCOPE)
  140. endfunction()
  141. function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
  142. execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']"
  143. RESULT_VARIABLE _Ruby_SUCCESS
  144. OUTPUT_VARIABLE _Ruby_OUTPUT
  145. ERROR_QUIET)
  146. if (_Ruby_SUCCESS OR _Ruby_OUTPUT STREQUAL "")
  147. execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
  148. RESULT_VARIABLE _Ruby_SUCCESS
  149. OUTPUT_VARIABLE _Ruby_OUTPUT
  150. ERROR_QUIET)
  151. endif ()
  152. set(${OUTVAR} "${_Ruby_OUTPUT}" PARENT_SCOPE)
  153. endfunction()
  154. #### Check RVM virtual environment ###
  155. function(_RUBY_CHECK_RVM)
  156. if (NOT DEFINED ENV{MY_RUBY_HOME})
  157. return()
  158. endif ()
  159. find_program(Ruby_EXECUTABLE
  160. NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
  161. NAMES_PER_DIR
  162. PATHS ENV MY_RUBY_HOME
  163. PATH_SUFFIXES bin Scripts
  164. VALIDATOR _RUBY_VALIDATE_INTERPRETER
  165. NO_CMAKE_PATH
  166. NO_CMAKE_ENVIRONMENT_PATH
  167. NO_SYSTEM_ENVIRONMENT_PATH
  168. NO_CMAKE_SYSTEM_PATH)
  169. if (Ruby_EXECUTABLE)
  170. set(Ruby_ENV "RVM" CACHE INTERNAL "Ruby environment")
  171. endif ()
  172. endfunction()
  173. #### Check RBENV virtual environment ###
  174. function(_RUBY_CHECK_RBENV)
  175. find_program(Ruby_RBENV_EXECUTABLE
  176. NAMES rbenv
  177. NAMES_PER_DIR
  178. PATHS "$ENV{HOME}/.rbenv/bin/rbenv" ENV RBENV_ROOT
  179. PATH_SUFFIXES bin Scripts
  180. NO_CACHE
  181. NO_CMAKE_PATH
  182. NO_CMAKE_ENVIRONMENT_PATH
  183. NO_CMAKE_SYSTEM_PATH)
  184. execute_process(COMMAND "${Ruby_RBENV_EXECUTABLE}" "which" "ruby"
  185. RESULT_VARIABLE result
  186. OUTPUT_VARIABLE ruby_exe
  187. ERROR_QUIET
  188. OUTPUT_STRIP_TRAILING_WHITESPACE)
  189. if (NOT result EQUAL 0)
  190. return()
  191. endif ()
  192. cmake_path(GET ruby_exe PARENT_PATH ruby_dir)
  193. find_program(Ruby_EXECUTABLE
  194. NAMES ruby
  195. NAMES_PER_DIR
  196. PATHS ${ruby_dir}
  197. VALIDATOR _RUBY_VALIDATE_INTERPRETER
  198. NO_DEFAULT_PATH)
  199. if (Ruby_EXECUTABLE)
  200. set(Ruby_ENV "RBENV" CACHE INTERNAL "Ruby environment")
  201. endif ()
  202. endfunction()
  203. #### Check system installed Ruby ###
  204. function(_RUBY_CHECK_SYSTEM)
  205. find_program(Ruby_EXECUTABLE
  206. NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
  207. NAMES_PER_DIR
  208. VALIDATOR _RUBY_VALIDATE_INTERPRETER)
  209. if (Ruby_EXECUTABLE)
  210. set(Ruby_ENV "Standard" CACHE INTERNAL "Ruby environment")
  211. endif ()
  212. endfunction()
  213. # Find Ruby
  214. if (NOT Ruby_EXECUTABLE AND Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  215. # First check for RVM virtual environments
  216. _RUBY_CHECK_RVM()
  217. # Second check for RBENV virtual environments
  218. if (NOT Ruby_EXECUTABLE)
  219. _RUBY_CHECK_RBENV()
  220. endif ()
  221. endif ()
  222. # Check for system installed Ruby
  223. if (NOT Ruby_EXECUTABLE AND NOT Ruby_FIND_VIRTUALENV STREQUAL "ONLY")
  224. _RUBY_CHECK_SYSTEM()
  225. endif ()
  226. if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QUERIED}")
  227. # query the ruby version
  228. _RUBY_CONFIG_VAR("MAJOR" Ruby_VERSION_MAJOR)
  229. _RUBY_CONFIG_VAR("MINOR" Ruby_VERSION_MINOR)
  230. _RUBY_CONFIG_VAR("TEENY" Ruby_VERSION_PATCH)
  231. # query the different directories
  232. _RUBY_CONFIG_VAR("archdir" Ruby_ARCH_DIR)
  233. _RUBY_CONFIG_VAR("arch" Ruby_ARCH)
  234. _RUBY_CONFIG_VAR("rubyhdrdir" Ruby_HDR_DIR)
  235. _RUBY_CONFIG_VAR("rubyarchhdrdir" Ruby_ARCHHDR_DIR)
  236. _RUBY_CONFIG_VAR("libdir" _Ruby_POSSIBLE_LIB_DIR)
  237. _RUBY_CONFIG_VAR("rubylibdir" Ruby_RUBY_LIB_DIR)
  238. # site_ruby
  239. _RUBY_CONFIG_VAR("sitearchdir" Ruby_SITEARCH_DIR)
  240. _RUBY_CONFIG_VAR("sitelibdir" Ruby_SITELIB_DIR)
  241. # vendor_ruby available ?
  242. execute_process(COMMAND ${Ruby_EXECUTABLE} -r vendor-specific -e "print 'true'"
  243. OUTPUT_VARIABLE Ruby_HAS_VENDOR_RUBY ERROR_QUIET)
  244. if (Ruby_HAS_VENDOR_RUBY)
  245. _RUBY_CONFIG_VAR("vendorlibdir" Ruby_VENDORLIB_DIR)
  246. _RUBY_CONFIG_VAR("vendorarchdir" Ruby_VENDORARCH_DIR)
  247. endif ()
  248. # save the results in the cache so we don't have to run ruby the next time again
  249. set(_Ruby_EXECUTABLE_LAST_QUERIED "${Ruby_EXECUTABLE}" CACHE INTERNAL "The ruby executable last queried for version and path info")
  250. set(Ruby_VERSION_MAJOR ${Ruby_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
  251. set(Ruby_VERSION_MINOR ${Ruby_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
  252. set(Ruby_VERSION_PATCH ${Ruby_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
  253. set(Ruby_ARCH_DIR ${Ruby_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
  254. set(Ruby_HDR_DIR ${Ruby_HDR_DIR} CACHE PATH "The Ruby header dir (1.9+)" FORCE)
  255. set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE PATH "The Ruby arch header dir (2.0+)" FORCE)
  256. set(_Ruby_POSSIBLE_LIB_DIR ${_Ruby_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
  257. set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
  258. set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
  259. set(Ruby_SITELIB_DIR ${Ruby_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
  260. set(Ruby_HAS_VENDOR_RUBY ${Ruby_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
  261. set(Ruby_VENDORARCH_DIR ${Ruby_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
  262. set(Ruby_VENDORLIB_DIR ${Ruby_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
  263. mark_as_advanced(
  264. Ruby_ARCH_DIR
  265. Ruby_ARCH
  266. Ruby_HDR_DIR
  267. Ruby_ARCHHDR_DIR
  268. _Ruby_POSSIBLE_LIB_DIR
  269. Ruby_RUBY_LIB_DIR
  270. Ruby_SITEARCH_DIR
  271. Ruby_SITELIB_DIR
  272. Ruby_HAS_VENDOR_RUBY
  273. Ruby_VENDORARCH_DIR
  274. Ruby_VENDORLIB_DIR
  275. Ruby_VERSION_MAJOR
  276. Ruby_VERSION_MINOR
  277. Ruby_VERSION_PATCH
  278. )
  279. endif ()
  280. # In case Ruby_EXECUTABLE could not be executed (e.g. cross compiling)
  281. # try to detect which version we found. This is not too good.
  282. if (Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR)
  283. # by default assume 1.8.0
  284. set(Ruby_VERSION_MAJOR 1)
  285. set(Ruby_VERSION_MINOR 8)
  286. set(Ruby_VERSION_PATCH 0)
  287. # check whether we found 1.9.x
  288. if (${Ruby_EXECUTABLE} MATCHES "ruby1\\.?9")
  289. set(Ruby_VERSION_MAJOR 1)
  290. set(Ruby_VERSION_MINOR 9)
  291. endif ()
  292. # check whether we found 2.[0-7].x
  293. if (${Ruby_EXECUTABLE} MATCHES "ruby2")
  294. set(Ruby_VERSION_MAJOR 2)
  295. string(REGEX_REPLACE ${Ruby_EXECUTABLE} "ruby2\\.?([0-7])" "\\1" Ruby_VERSION_MINOR)
  296. endif ()
  297. # check whether we found 3.[0-1].x
  298. if (${Ruby_EXECUTABLE} MATCHES "ruby3")
  299. set(Ruby_VERSION_MAJOR 3)
  300. string(REGEX_REPLACE ${Ruby_EXECUTABLE} "ruby3\\.?([0-1])" "\\1" Ruby_VERSION_MINOR)
  301. endif ()
  302. endif ()
  303. if (Ruby_VERSION_MAJOR)
  304. set(Ruby_VERSION "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}.${Ruby_VERSION_PATCH}")
  305. set(_Ruby_VERSION_SHORT "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}")
  306. set(_Ruby_VERSION_SHORT_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}")
  307. set(_Ruby_NODOT_VERSION "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}${Ruby_VERSION_PATCH}")
  308. set(_Ruby_NODOT_VERSION_ZERO_PATCH "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}0")
  309. endif ()
  310. # FIXME: Currently we require both the interpreter and development components to be found
  311. # in order to use either. See issue #20474.
  312. find_path(Ruby_INCLUDE_DIR
  313. NAMES ruby.h
  314. HINTS
  315. ${Ruby_HDR_DIR}
  316. ${Ruby_ARCH_DIR}
  317. /usr/lib/ruby/${_Ruby_VERSION_SHORT}/i586-linux-gnu/
  318. )
  319. set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR})
  320. # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
  321. if (Ruby_FIND_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_HDR_DIR)
  322. find_path(Ruby_CONFIG_INCLUDE_DIR
  323. NAMES ruby/config.h config.h
  324. HINTS
  325. ${Ruby_HDR_DIR}/${Ruby_ARCH}
  326. ${Ruby_ARCH_DIR}
  327. ${Ruby_ARCHHDR_DIR}
  328. )
  329. set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIRS} ${Ruby_CONFIG_INCLUDE_DIR})
  330. endif ()
  331. # Determine the list of possible names for the ruby library
  332. set(_Ruby_POSSIBLE_LIB_NAMES ruby ruby-static ruby${_Ruby_VERSION_SHORT} ruby${_Ruby_VERSION_SHORT_NODOT} ruby${_Ruby_NODOT_VERSION} ruby-${_Ruby_VERSION_SHORT} ruby-${Ruby_VERSION})
  333. if (WIN32)
  334. set(_Ruby_POSSIBLE_MSVC_RUNTIMES "ucrt;msvcrt;vcruntime140;vcruntime140_1")
  335. if (MSVC_TOOLSET_VERSION)
  336. list(APPEND _Ruby_POSSIBLE_MSVC_RUNTIMES "msvcr${MSVC_TOOLSET_VERSION}")
  337. else ()
  338. list(APPEND _Ruby_POSSIBLE_MSVC_RUNTIMES "msvcr")
  339. endif ()
  340. set(_Ruby_POSSIBLE_VERSION_SUFFICES "${_Ruby_NODOT_VERSION};${_Ruby_NODOT_VERSION_ZERO_PATCH}")
  341. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  342. set(_Ruby_POSSIBLE_ARCH_PREFIXS "libx64-;x64-")
  343. else ()
  344. set(_Ruby_POSSIBLE_ARCH_PREFIXS "lib")
  345. endif ()
  346. foreach (_Ruby_MSVC_RUNTIME ${_Ruby_POSSIBLE_MSVC_RUNTIMES})
  347. foreach (_Ruby_VERSION_SUFFIX ${_Ruby_POSSIBLE_VERSION_SUFFICES})
  348. foreach (_Ruby_ARCH_PREFIX ${_Ruby_POSSIBLE_ARCH_PREFIXS})
  349. list(APPEND _Ruby_POSSIBLE_LIB_NAMES
  350. "${_Ruby_ARCH_PREFIX}${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}"
  351. "${_Ruby_ARCH_PREFIX}${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}-static")
  352. endforeach ()
  353. endforeach ()
  354. endforeach ()
  355. endif ()
  356. find_library(Ruby_LIBRARY NAMES ${_Ruby_POSSIBLE_LIB_NAMES} HINTS ${_Ruby_POSSIBLE_LIB_DIR})
  357. set(_Ruby_REQUIRED_VARS Ruby_EXECUTABLE Ruby_INCLUDE_DIR Ruby_LIBRARY)
  358. if (_Ruby_VERSION_SHORT_NODOT GREATER 18)
  359. list(APPEND _Ruby_REQUIRED_VARS Ruby_CONFIG_INCLUDE_DIR)
  360. endif ()
  361. if (_Ruby_DEBUG_OUTPUT)
  362. message(STATUS "--------FindRuby.cmake debug------------")
  363. message(STATUS "_Ruby_POSSIBLE_EXECUTABLE_NAMES: ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}")
  364. message(STATUS "_Ruby_POSSIBLE_LIB_DIR: ${_Ruby_POSSIBLE_LIB_DIR}")
  365. message(STATUS "_Ruby_POSSIBLE_LIB_NAMES: ${_Ruby_POSSIBLE_LIB_NAMES}")
  366. message(STATUS "Ruby_FIND_VIRTUALENV=${Ruby_FIND_VIRTUALENV}")
  367. message(STATUS "Ruby_ENV: ${Ruby_ENV}")
  368. message(STATUS "Found Ruby_VERSION: \"${Ruby_VERSION}\"")
  369. message(STATUS "Ruby_EXECUTABLE: ${Ruby_EXECUTABLE}")
  370. message(STATUS "Ruby_LIBRARY: ${Ruby_LIBRARY}")
  371. message(STATUS "Ruby_INCLUDE_DIR: ${Ruby_INCLUDE_DIR}")
  372. message(STATUS "Ruby_CONFIG_INCLUDE_DIR: ${Ruby_CONFIG_INCLUDE_DIR}")
  373. message(STATUS "Ruby_HDR_DIR: ${Ruby_HDR_DIR}")
  374. message(STATUS "Ruby_ARCH_DIR: ${Ruby_ARCH_DIR}")
  375. message(STATUS "--------------------")
  376. endif ()
  377. include(FindPackageHandleStandardArgs)
  378. find_package_handle_standard_args(Ruby REQUIRED_VARS ${_Ruby_REQUIRED_VARS}
  379. VERSION_VAR Ruby_VERSION)
  380. if (Ruby_FOUND)
  381. set(Ruby_LIBRARIES ${Ruby_LIBRARY})
  382. endif ()
  383. mark_as_advanced(
  384. Ruby_EXECUTABLE
  385. Ruby_LIBRARY
  386. Ruby_INCLUDE_DIR
  387. Ruby_CONFIG_INCLUDE_DIR
  388. )
  389. # Set some variables for compatibility with previous version of this file (no need to provide a CamelCase version of that...)
  390. set(RUBY_POSSIBLE_LIB_PATH ${_Ruby_POSSIBLE_LIB_DIR})
  391. set(RUBY_RUBY_LIB_PATH ${Ruby_RUBY_LIB_DIR})
  392. set(RUBY_INCLUDE_PATH ${Ruby_INCLUDE_DIRS})
  393. # Backwards compatibility
  394. # Define upper case versions of output variables
  395. foreach (Camel
  396. Ruby_EXECUTABLE
  397. Ruby_INCLUDE_DIRS
  398. Ruby_LIBRARY
  399. Ruby_VERSION
  400. Ruby_VERSION_MAJOR
  401. Ruby_VERSION_MINOR
  402. Ruby_VERSION_PATCH
  403. Ruby_ARCH_DIR
  404. Ruby_ARCH
  405. Ruby_HDR_DIR
  406. Ruby_ARCHHDR_DIR
  407. Ruby_RUBY_LIB_DIR
  408. Ruby_SITEARCH_DIR
  409. Ruby_SITELIB_DIR
  410. Ruby_HAS_VENDOR_RUBY
  411. Ruby_VENDORARCH_DIR
  412. Ruby_VENDORLIB_DIR)
  413. string(TOUPPER ${Camel} UPPER)
  414. set(${UPPER} ${${Camel}})
  415. endforeach ()