FindRuby.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file LICENSE.rst or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FindRuby
  5. --------
  6. Finds Ruby installation and the locations of its include files and libraries:
  7. .. code-block:: cmake
  8. find_package(Ruby [<version>] [...])
  9. Ruby is a general-purpose programming language. This module supports Ruby
  10. 1.8 through 3.4. Virtual environments, such as RVM or RBENV, are also
  11. supported.
  12. Result Variables
  13. ^^^^^^^^^^^^^^^^
  14. This module defines the following variables:
  15. ``Ruby_FOUND``
  16. .. versionadded:: 3.3
  17. Boolean indicating whether (the requested version of) ruby was found.
  18. ``Ruby_VERSION``
  19. The version of ruby which was found, e.g. ``3.2.6``.
  20. ``Ruby_VERSION_MAJOR``
  21. Ruby major version.
  22. ``Ruby_VERSION_MINOR``
  23. Ruby minor version.
  24. ``Ruby_VERSION_PATCH``
  25. Ruby patch version.
  26. ``Ruby_EXECUTABLE``
  27. The full path to the ruby binary.
  28. ``Ruby_INCLUDE_DIRS``
  29. Include dirs to be used when using the ruby library.
  30. ``Ruby_LIBRARIES``
  31. .. versionadded:: 3.18
  32. Libraries needed to use ruby from C.
  33. .. versionchanged:: 3.18
  34. Previous versions of CMake used the ``RUBY_`` prefix for all variables.
  35. Hints
  36. ^^^^^
  37. This module accepts the following variables:
  38. ``Ruby_FIND_VIRTUALENV``
  39. .. versionadded:: 3.18
  40. This variable defines the handling of virtual environments.
  41. It can be left empty or be set to one of the following values:
  42. * ``FIRST``: Virtual Ruby environments are searched for first,
  43. then the system Ruby installation.
  44. This is the default.
  45. * ``ONLY``: Only virtual environments are searched
  46. * ``STANDARD``: Only the system Ruby installation is searched.
  47. Virtual environments may be provided by:
  48. ``rvm``
  49. Requires that the ``MY_RUBY_HOME`` environment is defined.
  50. ``rbenv``
  51. Requires that ``rbenv`` is installed in ``~/.rbenv/bin``
  52. or that the ``RBENV_ROOT`` environment variable is defined.
  53. Deprecated Variables
  54. ^^^^^^^^^^^^^^^^^^^^
  55. The following variables are provided for backward compatibility:
  56. .. deprecated:: 4.0
  57. The following variables are deprecated. See policy :policy:`CMP0185`.
  58. ``RUBY_FOUND``
  59. Same as ``Ruby_FOUND``.
  60. ``RUBY_VERSION``
  61. Same as ``Ruby_VERSION``.
  62. ``RUBY_EXECUTABLE``
  63. Same as ``Ruby_EXECUTABLE``.
  64. ``RUBY_INCLUDE_DIRS``
  65. Same as ``Ruby_INCLUDE_DIRS``.
  66. ``RUBY_INCLUDE_PATH``
  67. Same as ``Ruby_INCLUDE_DIRS``.
  68. ``RUBY_LIBRARY``
  69. Same as ``Ruby_LIBRARY``.
  70. Examples
  71. ^^^^^^^^
  72. Finding Ruby and specifying the minimum required version:
  73. .. code-block:: cmake
  74. find_package(Ruby 3.2.6 EXACT REQUIRED)
  75. # or
  76. find_package(Ruby 3.2)
  77. #]=======================================================================]
  78. cmake_policy(GET CMP0185 _Ruby_CMP0185)
  79. if(NOT _Ruby_CMP0185 STREQUAL "NEW")
  80. # Backwards compatibility
  81. # Define camel case versions of input variables
  82. foreach (UPPER
  83. RUBY_EXECUTABLE
  84. RUBY_LIBRARY
  85. RUBY_INCLUDE_DIR
  86. RUBY_CONFIG_INCLUDE_DIR)
  87. if (DEFINED ${UPPER})
  88. string(REPLACE "RUBY_" "Ruby_" Camel ${UPPER})
  89. if (NOT DEFINED ${Camel})
  90. set(${Camel} ${${UPPER}})
  91. endif ()
  92. endif ()
  93. endforeach ()
  94. endif()
  95. # Uncomment the following line to get debug output for this file
  96. # set(CMAKE_MESSAGE_LOG_LEVEL DEBUG)
  97. # Determine the list of possible names of the ruby executable depending
  98. # on which version of ruby is required
  99. set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby)
  100. # If the user has not specified a Ruby version, create a list of Ruby versions
  101. # to check going from 1.8 to 4.0
  102. if (NOT Ruby_FIND_VERSION_EXACT)
  103. foreach (_ruby_version RANGE 40 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: ruby3.4 ruby34)
  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. # Validate the found Ruby interpreter to make sure that it is
  119. # callable and that its version matches the requested version
  120. function(_RUBY_VALIDATE_INTERPRETER result_var path)
  121. # Get the interpreter version
  122. execute_process(COMMAND "${path}" -e "puts RUBY_VERSION"
  123. RESULT_VARIABLE result
  124. OUTPUT_VARIABLE version
  125. ERROR_QUIET
  126. OUTPUT_STRIP_TRAILING_WHITESPACE)
  127. if (NOT result EQUAL 0)
  128. set(_Ruby_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${path}\"")
  129. set(${result_var} FALSE PARENT_SCOPE)
  130. return()
  131. endif ()
  132. if (Ruby_FIND_VERSION)
  133. if (Ruby_FIND_VERSION_EXACT AND NOT version VERSION_EQUAL Ruby_FIND_VERSION)
  134. message(DEBUG "Incorrect Ruby found. Requested: ${Ruby_FIND_VERSION}. Found: ${version}. Path: \"${path}\"")
  135. set(${result_var} FALSE PARENT_SCOPE)
  136. return()
  137. elseif (version VERSION_LESS Ruby_FIND_VERSION)
  138. message(DEBUG "Ruby version is too old. Minimum: ${Ruby_FIND_VERSION}. Found: ${version}. Path: \"${path}\"")
  139. set(${result_var} FALSE PARENT_SCOPE)
  140. return()
  141. endif ()
  142. endif ()
  143. # Found valid Ruby interpreter!
  144. set(${result_var} TRUE PARENT_SCOPE)
  145. endfunction()
  146. # Query Ruby RBConfig module for the specified variable (_RUBY_CONFIG_VAR)
  147. function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
  148. execute_process(COMMAND "${Ruby_EXECUTABLE}" -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']"
  149. RESULT_VARIABLE _Ruby_SUCCESS
  150. OUTPUT_VARIABLE _Ruby_OUTPUT
  151. ERROR_QUIET)
  152. # Config was deprecated in Ruby 1.9 and then removed in Ruby 2 - so this is for ancient code
  153. if (_Ruby_SUCCESS OR _Ruby_OUTPUT STREQUAL "")
  154. execute_process(COMMAND "${Ruby_EXECUTABLE}" -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
  155. RESULT_VARIABLE _Ruby_SUCCESS
  156. OUTPUT_VARIABLE _Ruby_OUTPUT
  157. ERROR_QUIET)
  158. endif ()
  159. set(${OUTVAR} "${_Ruby_OUTPUT}" PARENT_SCOPE)
  160. endfunction()
  161. # Check for RVM virtual environments
  162. function(_RUBY_CHECK_RVM)
  163. if (NOT DEFINED ENV{MY_RUBY_HOME})
  164. return()
  165. endif ()
  166. find_program(Ruby_EXECUTABLE
  167. NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
  168. NAMES_PER_DIR
  169. PATHS ENV MY_RUBY_HOME
  170. PATH_SUFFIXES bin Scripts
  171. VALIDATOR _RUBY_VALIDATE_INTERPRETER
  172. NO_CMAKE_PATH
  173. NO_CMAKE_ENVIRONMENT_PATH
  174. NO_SYSTEM_ENVIRONMENT_PATH
  175. NO_CMAKE_SYSTEM_PATH)
  176. if (Ruby_EXECUTABLE)
  177. set(Ruby_ENV "RVM" CACHE INTERNAL "Ruby environment")
  178. endif ()
  179. endfunction()
  180. # Check for RBENV virtual environments
  181. function(_RUBY_CHECK_RBENV)
  182. find_program(Ruby_RBENV_EXECUTABLE
  183. NAMES rbenv
  184. NAMES_PER_DIR
  185. PATHS "$ENV{HOME}/.rbenv/bin/rbenv" ENV RBENV_ROOT
  186. PATH_SUFFIXES bin Scripts
  187. NO_CACHE
  188. NO_CMAKE_PATH
  189. NO_CMAKE_ENVIRONMENT_PATH
  190. NO_CMAKE_SYSTEM_PATH)
  191. execute_process(COMMAND "${Ruby_RBENV_EXECUTABLE}" "which" "ruby"
  192. RESULT_VARIABLE result
  193. OUTPUT_VARIABLE ruby_exe
  194. ERROR_QUIET
  195. OUTPUT_STRIP_TRAILING_WHITESPACE)
  196. if (NOT result EQUAL 0)
  197. return()
  198. endif ()
  199. cmake_path(GET ruby_exe PARENT_PATH ruby_dir)
  200. find_program(Ruby_EXECUTABLE
  201. NAMES ruby
  202. NAMES_PER_DIR
  203. PATHS ${ruby_dir}
  204. VALIDATOR _RUBY_VALIDATE_INTERPRETER
  205. NO_DEFAULT_PATH)
  206. if (Ruby_EXECUTABLE)
  207. set(Ruby_ENV "RBENV" CACHE INTERNAL "Ruby environment")
  208. endif ()
  209. endfunction()
  210. # Check Ruby installed via Homebrew on macOS
  211. function(_RUBY_CHECK_BREW)
  212. # Try to locate brew in common locations and in PATH
  213. find_program(_BREW_EXECUTABLE
  214. NAMES brew
  215. NAMES_PER_DIR
  216. PATHS
  217. /opt/homebrew/bin # Apple Silicon default
  218. /usr/local/bin # Intel default
  219. ENV PATH
  220. NO_CACHE
  221. )
  222. if (NOT _BREW_EXECUTABLE)
  223. return()
  224. endif ()
  225. MESSAGE(DEBUG "Found brew at: ${_BREW_EXECUTABLE}")
  226. # Query Homebrew for the prefix of the 'ruby' formula.
  227. # If Ruby is not installed via Homebrew, this will fail.
  228. execute_process(
  229. COMMAND "${_BREW_EXECUTABLE}" --prefix ruby
  230. RESULT_VARIABLE _Ruby_BREW_RESULT
  231. OUTPUT_VARIABLE _Ruby_BREW_DIR
  232. ERROR_QUIET
  233. OUTPUT_STRIP_TRAILING_WHITESPACE
  234. )
  235. MESSAGE(DEBUG "Ruby BREW is: ${_Ruby_BREW_DIR}")
  236. if (NOT _Ruby_BREW_RESULT EQUAL 0 OR _Ruby_BREW_DIR STREQUAL "")
  237. # No 'ruby' formula installed in Homebrew
  238. return()
  239. endif ()
  240. find_program(Ruby_EXECUTABLE
  241. NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
  242. NAMES_PER_DIR
  243. PATHS "${_Ruby_BREW_DIR}/bin"
  244. VALIDATOR _RUBY_VALIDATE_INTERPRETER
  245. NO_DEFAULT_PATH
  246. )
  247. if (Ruby_EXECUTABLE)
  248. set(Ruby_ENV "BREW" CACHE INTERNAL "Ruby environment")
  249. endif ()
  250. endfunction()
  251. # Check system installed Ruby
  252. function(_RUBY_CHECK_SYSTEM)
  253. find_program(Ruby_EXECUTABLE
  254. NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
  255. NAMES_PER_DIR
  256. VALIDATOR _RUBY_VALIDATE_INTERPRETER)
  257. if (Ruby_EXECUTABLE)
  258. set(Ruby_ENV "Standard" CACHE INTERNAL "Ruby environment")
  259. endif ()
  260. endfunction()
  261. # Find Ruby
  262. if (NOT Ruby_EXECUTABLE AND Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  263. # First check for RVM virtual environments
  264. _RUBY_CHECK_RVM()
  265. # Second check for RBENV virtual environments
  266. if (NOT Ruby_EXECUTABLE)
  267. _RUBY_CHECK_RBENV()
  268. endif ()
  269. endif ()
  270. # Check for Homebrew Ruby (non-virtualenv, common on MacOS)
  271. if (NOT Ruby_EXECUTABLE AND NOT Ruby_FIND_VIRTUALENV STREQUAL "ONLY")
  272. _RUBY_CHECK_BREW()
  273. endif ()
  274. # Fallback to system installed Ruby
  275. if (NOT Ruby_EXECUTABLE AND NOT Ruby_FIND_VIRTUALENV STREQUAL "ONLY")
  276. _RUBY_CHECK_SYSTEM()
  277. endif ()
  278. # We found a new Ruby or a Ruby that is different than the last one we found.
  279. # So reload a number of variables by querying the Ruby interpreter.
  280. if (Ruby_EXECUTABLE AND NOT Ruby_EXECUTABLE STREQUAL "${_Ruby_EXECUTABLE_LAST_QUERIED}")
  281. # query the ruby version
  282. _RUBY_CONFIG_VAR("MAJOR" Ruby_VERSION_MAJOR)
  283. _RUBY_CONFIG_VAR("MINOR" Ruby_VERSION_MINOR)
  284. _RUBY_CONFIG_VAR("TEENY" Ruby_VERSION_PATCH)
  285. # Ruby extensions information
  286. _RUBY_CONFIG_VAR("arch" Ruby_ARCH) # x86_64-linux, arm64-darwin, x64-mswin64_140, etc
  287. # Extension directory where so/bundle files are stored
  288. _RUBY_CONFIG_VAR("archdir" Ruby_ARCH_DIR)
  289. # Extension suffix
  290. _RUBY_CONFIG_VAR("DLEXT" _Ruby_DLEXT) # so, bundle, *not* dll
  291. # Headers
  292. _RUBY_CONFIG_VAR("rubyhdrdir" Ruby_HDR_DIR)
  293. _RUBY_CONFIG_VAR("rubyarchhdrdir" Ruby_ARCHHDR_DIR)
  294. # Ruby library information
  295. _RUBY_CONFIG_VAR("libdir" _Ruby_POSSIBLE_LIB_DIR) # /usr/lib64
  296. _RUBY_CONFIG_VAR("RUBY_SO_NAME" _Ruby_SO_NAME) # ruby, x64-vcruntime140-ruby340, etc.
  297. # Ruby directory for ruby files (*.rb). TODO - not relevant should be removed
  298. _RUBY_CONFIG_VAR("rubylibdir" Ruby_RUBY_LIB_DIR)
  299. # site_ruby - TODO - not relevant and should be removed
  300. _RUBY_CONFIG_VAR("sitearchdir" Ruby_SITEARCH_DIR)
  301. _RUBY_CONFIG_VAR("sitelibdir" Ruby_SITELIB_DIR)
  302. # vendor_ruby - TODO - Not relevant and should be removed.
  303. execute_process(COMMAND "${Ruby_EXECUTABLE}" -r vendor-specific -e "print 'true'"
  304. OUTPUT_VARIABLE Ruby_HAS_VENDOR_RUBY ERROR_QUIET)
  305. if (Ruby_HAS_VENDOR_RUBY)
  306. _RUBY_CONFIG_VAR("vendorlibdir" Ruby_VENDORLIB_DIR)
  307. _RUBY_CONFIG_VAR("vendorarchdir" Ruby_VENDORARCH_DIR)
  308. endif ()
  309. # save the results in the cache so we don't have to run ruby the next time again
  310. set(_Ruby_EXECUTABLE_LAST_QUERIED "${Ruby_EXECUTABLE}" CACHE INTERNAL "The ruby executable last queried for version and path info")
  311. set(Ruby_VERSION_MAJOR ${Ruby_VERSION_MAJOR} CACHE STRING "The Ruby major version" FORCE)
  312. set(Ruby_VERSION_MINOR ${Ruby_VERSION_MINOR} CACHE STRING "The Ruby minor version" FORCE)
  313. set(Ruby_VERSION_PATCH ${Ruby_VERSION_PATCH} CACHE STRING "The Ruby patch version" FORCE)
  314. set(Ruby_ARCH_DIR ${Ruby_ARCH_DIR} CACHE INTERNAL "The Ruby arch dir" FORCE)
  315. set(Ruby_HDR_DIR ${Ruby_HDR_DIR} CACHE INTERNAL "The Ruby header dir (1.9+)" FORCE)
  316. set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE INTERNAL "The Ruby arch header dir (2.0+)" FORCE)
  317. set(_Ruby_POSSIBLE_LIB_DIR ${_Ruby_POSSIBLE_LIB_DIR} CACHE INTERNAL "The Ruby lib dir" FORCE)
  318. set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE INTERNAL "The Ruby ruby-lib dir" FORCE)
  319. set(_Ruby_SO_NAME ${_Ruby_SO_NAME} CACHE PATH "The Ruby shared library name" FORCE)
  320. set(_Ruby_DLEXT ${_Ruby_DLEXT} CACHE PATH "Ruby extensions extension" FORCE)
  321. set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE INTERNAL "The Ruby site arch dir" FORCE)
  322. set(Ruby_SITELIB_DIR ${Ruby_SITELIB_DIR} CACHE INTERNAL "The Ruby site lib dir" FORCE)
  323. set(Ruby_HAS_VENDOR_RUBY ${Ruby_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
  324. set(Ruby_VENDORARCH_DIR ${Ruby_VENDORARCH_DIR} CACHE INTERNAL "The Ruby vendor arch dir" FORCE)
  325. set(Ruby_VENDORLIB_DIR ${Ruby_VENDORLIB_DIR} CACHE INTERNAL "The Ruby vendor lib dir" FORCE)
  326. mark_as_advanced(
  327. Ruby_ARCH_DIR
  328. Ruby_ARCH
  329. Ruby_HDR_DIR
  330. Ruby_ARCHHDR_DIR
  331. _Ruby_POSSIBLE_LIB_DIR
  332. Ruby_RUBY_LIB_DIR
  333. _Ruby_SO_NAME
  334. _Ruby_DLEXT
  335. Ruby_SITEARCH_DIR
  336. Ruby_SITELIB_DIR
  337. Ruby_HAS_VENDOR_RUBY
  338. Ruby_VENDORARCH_DIR
  339. Ruby_VENDORLIB_DIR
  340. Ruby_VERSION_MAJOR
  341. Ruby_VERSION_MINOR
  342. Ruby_VERSION_PATCH
  343. )
  344. endif ()
  345. if (Ruby_VERSION_MAJOR)
  346. set(Ruby_VERSION "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}.${Ruby_VERSION_PATCH}")
  347. set(_Ruby_VERSION_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}${Ruby_VERSION_PATCH}")
  348. set(_Ruby_VERSION_NODOT_ZERO_PATCH "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}0")
  349. set(_Ruby_VERSION_SHORT "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}")
  350. set(_Ruby_VERSION_SHORT_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}")
  351. endif ()
  352. # FIXME: Currently we require both the interpreter and development components to be found
  353. # in order to use either. See issue #20474.
  354. # Save CMAKE_FIND_FRAMEWORK
  355. set(_Ruby_CMAKE_FIND_FRAMEWORK_ORIGINAL ${CMAKE_FIND_FRAMEWORK})
  356. # Avoid finding the ancient Ruby framework included in macOS.
  357. set(CMAKE_FIND_FRAMEWORK LAST)
  358. find_path(Ruby_INCLUDE_DIR
  359. NAMES ruby.h
  360. HINTS ${Ruby_HDR_DIR})
  361. find_path(Ruby_CONFIG_INCLUDE_DIR
  362. NAMES ruby/config.h config.h
  363. HINTS ${Ruby_ARCHHDR_DIR})
  364. set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR} ${Ruby_CONFIG_INCLUDE_DIR})
  365. # Determine the list of possible names for the ruby library
  366. set(_Ruby_POSSIBLE_LIB_NAMES
  367. ruby
  368. ruby-static
  369. ruby-${Ruby_VERSION}
  370. ruby${_Ruby_VERSION_NODOT}
  371. ruby${_Ruby_VERSION_NODOT_ZERO_PATCH}
  372. ruby-${_Ruby_VERSION_SHORT}
  373. ruby${_Ruby_VERSION_SHORT}
  374. ruby${_Ruby_VERSION_SHORT_NODOT}
  375. )
  376. if (WIN32)
  377. set(_Ruby_POSSIBLE_RUNTIMES "ucrt;msvcrt;vcruntime140;vcruntime140_1;vcruntime${MSVC_TOOLSET_VERSION}")
  378. set(_Ruby_POSSIBLE_VERSION_SUFFIXES "${_Ruby_VERSION_NODOT};${_Ruby_VERSION_NODOT_ZERO_PATCH}")
  379. if (CMAKE_SIZEOF_VOID_P EQUAL 8)
  380. set(_Ruby_POSSIBLE_ARCH_PREFIXES "libx64-;x64-")
  381. else ()
  382. set(_Ruby_POSSIBLE_ARCH_PREFIXES "lib")
  383. endif ()
  384. foreach (_Ruby_RUNTIME ${_Ruby_POSSIBLE_RUNTIMES})
  385. foreach (_Ruby_VERSION_SUFFIX ${_Ruby_POSSIBLE_VERSION_SUFFIXES})
  386. foreach (_Ruby_ARCH_PREFIX ${_Ruby_POSSIBLE_ARCH_PREFIXES})
  387. list(APPEND _Ruby_POSSIBLE_LIB_NAMES
  388. "${_Ruby_ARCH_PREFIX}${_Ruby_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}"
  389. "${_Ruby_ARCH_PREFIX}${_Ruby_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}-static")
  390. endforeach ()
  391. endforeach ()
  392. endforeach ()
  393. endif ()
  394. find_library(Ruby_LIBRARY
  395. NAMES ${_Ruby_POSSIBLE_LIB_NAMES}
  396. HINTS ${_Ruby_POSSIBLE_LIB_DIR})
  397. set(_Ruby_REQUIRED_VARS Ruby_EXECUTABLE Ruby_INCLUDE_DIR Ruby_LIBRARY)
  398. if (_Ruby_VERSION_SHORT_NODOT GREATER 18)
  399. list(APPEND _Ruby_REQUIRED_VARS Ruby_CONFIG_INCLUDE_DIR)
  400. endif ()
  401. # Restore CMAKE_FIND_FRAMEWORK
  402. set(CMAKE_FIND_FRAMEWORK ${_Ruby_CMAKE_FIND_FRAMEWORK_ORIGINAL})
  403. message(DEBUG "--------FindRuby.cmake debug------------")
  404. message(DEBUG "_Ruby_POSSIBLE_EXECUTABLE_NAMES: ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}")
  405. message(DEBUG "_Ruby_POSSIBLE_LIB_DIR: ${_Ruby_POSSIBLE_LIB_DIR}")
  406. message(DEBUG "Ruby_LIBRUBY_SO: ${_Ruby_SO_NAME}")
  407. message(DEBUG "_Ruby_DLEXT: ${_Ruby_DLEXT}")
  408. message(DEBUG "Ruby_FIND_VIRTUALENV=${Ruby_FIND_VIRTUALENV}")
  409. message(DEBUG "Ruby_ENV: ${Ruby_ENV}")
  410. message(DEBUG "Found Ruby_VERSION: \"${Ruby_VERSION}\"")
  411. message(DEBUG "Ruby_EXECUTABLE: ${Ruby_EXECUTABLE}")
  412. message(DEBUG "Ruby_LIBRARY: ${Ruby_LIBRARY}")
  413. message(DEBUG "Ruby_INCLUDE_DIR: ${Ruby_INCLUDE_DIR}")
  414. message(DEBUG "Ruby_CONFIG_INCLUDE_DIR: ${Ruby_CONFIG_INCLUDE_DIR}")
  415. message(DEBUG "Ruby_HDR_DIR: ${Ruby_HDR_DIR}")
  416. message(DEBUG "Ruby_ARCH_DIR: ${Ruby_ARCH_DIR}")
  417. message(DEBUG "Ruby_ARCHHDR_DIR: ${Ruby_ARCHHDR_DIR}")
  418. message(DEBUG "--------------------")
  419. include(FindPackageHandleStandardArgs)
  420. find_package_handle_standard_args(Ruby REQUIRED_VARS ${_Ruby_REQUIRED_VARS}
  421. VERSION_VAR Ruby_VERSION)
  422. if (Ruby_FOUND)
  423. set(Ruby_LIBRARIES ${Ruby_LIBRARY})
  424. endif ()
  425. mark_as_advanced(
  426. Ruby_EXECUTABLE
  427. Ruby_LIBRARY
  428. Ruby_INCLUDE_DIR
  429. Ruby_CONFIG_INCLUDE_DIR
  430. )
  431. if(NOT _Ruby_CMP0185 STREQUAL "NEW")
  432. # Set some variables for compatibility with previous version of this file (no need to provide a CamelCase version of that...)
  433. set(RUBY_POSSIBLE_LIB_PATH ${_Ruby_POSSIBLE_LIB_DIR})
  434. set(RUBY_RUBY_LIB_PATH ${Ruby_RUBY_LIB_DIR})
  435. set(RUBY_INCLUDE_PATH ${Ruby_INCLUDE_DIRS})
  436. # Backwards compatibility
  437. # Define upper case versions of output variables
  438. foreach (Camel
  439. Ruby_EXECUTABLE
  440. Ruby_INCLUDE_DIRS
  441. Ruby_LIBRARY
  442. Ruby_VERSION
  443. Ruby_VERSION_MAJOR
  444. Ruby_VERSION_MINOR
  445. Ruby_VERSION_PATCH
  446. Ruby_ARCH_DIR
  447. Ruby_ARCH
  448. Ruby_HDR_DIR
  449. Ruby_ARCHHDR_DIR
  450. Ruby_RUBY_LIB_DIR
  451. Ruby_SITEARCH_DIR
  452. Ruby_SITELIB_DIR
  453. Ruby_HAS_VENDOR_RUBY
  454. Ruby_VENDORARCH_DIR
  455. Ruby_VENDORLIB_DIR)
  456. string(TOUPPER ${Camel} UPPER)
  457. set(${UPPER} ${${Camel}})
  458. endforeach ()
  459. endif()