FindRuby.cmake 17 KB

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