FindRuby.cmake 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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 are handled as well, by passing
  15. the argument ``Ruby_FIND_VIRTUALENV``
  16. Result Variables
  17. ^^^^^^^^^^^^^^^^
  18. This module will set the following variables in your project:
  19. ``Ruby_FOUND``
  20. set to true if ruby was found successfully
  21. ``Ruby_EXECUTABLE``
  22. full path to the ruby binary
  23. ``Ruby_INCLUDE_DIRS``
  24. include dirs to be used when using the ruby library
  25. ``Ruby_LIBRARIES``
  26. .. versionadded:: 3.18
  27. libraries needed to use ruby from C.
  28. ``Ruby_VERSION``
  29. the version of ruby which was found, e.g. "3.2.6"
  30. ``Ruby_VERSION_MAJOR``
  31. Ruby major version.
  32. ``Ruby_VERSION_MINOR``
  33. Ruby minor version.
  34. ``Ruby_VERSION_PATCH``
  35. Ruby patch version.
  36. .. versionchanged:: 3.18
  37. Previous versions of CMake used the ``RUBY_`` prefix for all variables.
  38. The following variables are provided for compatibility reasons,
  39. don't use them in new code:
  40. ``RUBY_EXECUTABLE``
  41. same as Ruby_EXECUTABLE.
  42. ``RUBY_INCLUDE_DIRS``
  43. same as Ruby_INCLUDE_DIRS.
  44. ``RUBY_INCLUDE_PATH``
  45. same as Ruby_INCLUDE_DIRS.
  46. ``RUBY_LIBRARY``
  47. same as Ruby_LIBRARY.
  48. ``RUBY_VERSION``
  49. same as Ruby_VERSION.
  50. ``RUBY_FOUND``
  51. same as Ruby_FOUND.
  52. Hints
  53. ^^^^^
  54. .. versionadded:: 3.18
  55. ``Ruby_FIND_VIRTUALENV``
  56. This variable defines the handling of virtual environments managed by
  57. ``rvm``. It is meaningful only when a virtual environment
  58. is active (i.e. the ``rvm`` script has been evaluated or at least the
  59. ``MY_RUBY_HOME`` environment variable is set).
  60. The ``Ruby_FIND_VIRTUALENV`` variable can be set to empty or
  61. one of the following:
  62. * ``FIRST``: The virtual environment is used before any other standard
  63. paths to look-up for the interpreter. This is the default.
  64. * ``ONLY``: Only the virtual environment is used to look-up for the
  65. interpreter.
  66. * ``STANDARD``: The virtual environment is not used to look-up for the
  67. interpreter (assuming it isn't still in the PATH...)
  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. )
  77. if (DEFINED ${UPPER})
  78. string(REPLACE "RUBY_" "Ruby_" Camel ${UPPER})
  79. if (NOT DEFINED ${Camel})
  80. set(${Camel} ${${UPPER}})
  81. endif()
  82. endif()
  83. endforeach()
  84. # Ruby_ARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"archdir"@:>@)'`
  85. # Ruby_SITEARCHDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitearchdir"@:>@)'`
  86. # Ruby_SITEDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"sitelibdir"@:>@)'`
  87. # Ruby_LIBDIR=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"libdir"@:>@)'`
  88. # Ruby_LIBRUBYARG=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"LIBRUBYARG_SHARED"@:>@)'`
  89. # uncomment the following line to get debug output for this file
  90. # set(_Ruby_DEBUG_OUTPUT TRUE)
  91. # Determine the list of possible names of the ruby executable depending
  92. # on which version of ruby is required
  93. set(_Ruby_POSSIBLE_EXECUTABLE_NAMES ruby)
  94. # If not specified, allow everything as far back as 1.8.0
  95. if(NOT DEFINED Ruby_FIND_VERSION_MAJOR)
  96. set(Ruby_FIND_VERSION "1.8.0")
  97. set(Ruby_FIND_VERSION_MAJOR 1)
  98. set(Ruby_FIND_VERSION_MINOR 8)
  99. set(Ruby_FIND_VERSION_PATCH 0)
  100. endif()
  101. if(_Ruby_DEBUG_OUTPUT)
  102. message("Ruby_FIND_VERSION=${Ruby_FIND_VERSION}")
  103. message("Ruby_FIND_VERSION_MAJOR=${Ruby_FIND_VERSION_MAJOR}")
  104. message("Ruby_FIND_VERSION_MINOR=${Ruby_FIND_VERSION_MINOR}")
  105. message("Ruby_FIND_VERSION_PATCH=${Ruby_FIND_VERSION_PATCH}")
  106. endif()
  107. set(Ruby_FIND_VERSION_SHORT_NODOT "${Ruby_FIND_VERSION_MAJOR}${Ruby_FIND_VERSION_MINOR}")
  108. # Set name of possible executables, ignoring the minor
  109. # Eg:
  110. # 3.2.6 => from ruby34 to ruby32 included
  111. # 3.2 => from ruby34 to ruby32 included
  112. # 3 => from ruby34 to ruby30 included
  113. # empty => from ruby34 to ruby18 included
  114. if(NOT Ruby_FIND_VERSION_EXACT)
  115. foreach(_ruby_version RANGE 34 18 -1)
  116. string(SUBSTRING "${_ruby_version}" 0 1 _ruby_major_version)
  117. string(SUBSTRING "${_ruby_version}" 1 1 _ruby_minor_version)
  118. if(NOT "${_ruby_major_version}${_ruby_minor_version}" VERSION_LESS ${Ruby_FIND_VERSION_SHORT_NODOT})
  119. # Append both rubyX.Y and rubyXY (eg: ruby2.7 ruby27)
  120. list(APPEND _Ruby_POSSIBLE_EXECUTABLE_NAMES ruby${_ruby_major_version}.${_ruby_minor_version} ruby${_ruby_major_version}${_ruby_minor_version})
  121. else()
  122. break()
  123. endif()
  124. endforeach()
  125. list(REMOVE_DUPLICATES _Ruby_POSSIBLE_EXECUTABLE_NAMES)
  126. endif()
  127. # virtual environments handling (eg RVM)
  128. if (DEFINED ENV{MY_RUBY_HOME})
  129. if(_Ruby_DEBUG_OUTPUT)
  130. message("My ruby home is defined: $ENV{MY_RUBY_HOME}")
  131. endif()
  132. if (DEFINED Ruby_FIND_VIRTUALENV)
  133. if (NOT Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY|STANDARD)$")
  134. message (AUTHOR_WARNING "FindRuby: ${Ruby_FIND_VIRTUALENV}: invalid value for 'Ruby_FIND_VIRTUALENV'. 'FIRST', 'ONLY' or 'STANDARD' expected. 'FIRST' will be used instead.")
  135. set (_Ruby_FIND_VIRTUALENV "FIRST")
  136. else()
  137. set (_Ruby_FIND_VIRTUALENV ${Ruby_FIND_VIRTUALENV})
  138. endif()
  139. else()
  140. set (_Ruby_FIND_VIRTUALENV FIRST)
  141. endif()
  142. else()
  143. if (DEFINED Ruby_FIND_VIRTUALENV)
  144. message("Environment variable MY_RUBY_HOME isn't set, defaulting back to Ruby_FIND_VIRTUALENV=STANDARD")
  145. endif()
  146. set (_Ruby_FIND_VIRTUALENV STANDARD)
  147. endif()
  148. if(_Ruby_DEBUG_OUTPUT)
  149. message("_Ruby_POSSIBLE_EXECUTABLE_NAMES=${_Ruby_POSSIBLE_EXECUTABLE_NAMES}")
  150. message("_Ruby_FIND_VIRTUALENV=${_Ruby_FIND_VIRTUALENV}")
  151. endif()
  152. function (_RUBY_VALIDATE_INTERPRETER)
  153. if (NOT Ruby_EXECUTABLE)
  154. return()
  155. endif()
  156. cmake_parse_arguments (PARSE_ARGV 0 _RVI "EXACT;CHECK_EXISTS" "" "")
  157. if (_RVI_UNPARSED_ARGUMENTS)
  158. set (expected_version ${_RVI_UNPARSED_ARGUMENTS})
  159. else()
  160. unset (expected_version)
  161. endif()
  162. if (_RVI_CHECK_EXISTS AND NOT EXISTS "${Ruby_EXECUTABLE}")
  163. # interpreter does not exist anymore
  164. set (_Ruby_Interpreter_REASON_FAILURE "Cannot find the interpreter \"${Ruby_EXECUTABLE}\"")
  165. set_property (CACHE Ruby_EXECUTABLE PROPERTY VALUE "Ruby_EXECUTABLE-NOTFOUND")
  166. return()
  167. endif()
  168. # Check the version it returns
  169. # executable found must have a specific version
  170. execute_process (COMMAND "${Ruby_EXECUTABLE}" -e "puts RUBY_VERSION"
  171. RESULT_VARIABLE result
  172. OUTPUT_VARIABLE version
  173. ERROR_QUIET
  174. OUTPUT_STRIP_TRAILING_WHITESPACE)
  175. if (result OR (_RVI_EXACT AND NOT version VERSION_EQUAL expected_version) OR (version VERSION_LESS expected_version))
  176. # interpreter not usable or has wrong major version
  177. if (result)
  178. set (_Ruby_Interpreter_REASON_FAILURE "Cannot use the interpreter \"${Ruby_EXECUTABLE}\"")
  179. else()
  180. set (_Ruby_Interpreter_REASON_FAILURE "Wrong major version for the interpreter \"${Ruby_EXECUTABLE}\"")
  181. endif()
  182. set_property (CACHE Ruby_EXECUTABLE PROPERTY VALUE "Ruby_EXECUTABLE-NOTFOUND")
  183. return()
  184. endif()
  185. endfunction()
  186. while(1)
  187. # Virtual environments handling
  188. if(_Ruby_FIND_VIRTUALENV MATCHES "^(FIRST|ONLY)$")
  189. if(_Ruby_DEBUG_OUTPUT)
  190. message("Inside Matches")
  191. endif()
  192. find_program (Ruby_EXECUTABLE
  193. NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
  194. NAMES_PER_DIR
  195. PATHS ENV MY_RUBY_HOME
  196. PATH_SUFFIXES bin Scripts
  197. NO_CMAKE_PATH
  198. NO_CMAKE_ENVIRONMENT_PATH
  199. NO_SYSTEM_ENVIRONMENT_PATH
  200. NO_CMAKE_SYSTEM_PATH)
  201. if(_Ruby_DEBUG_OUTPUT)
  202. message("Ruby_EXECUTABLE=${Ruby_EXECUTABLE}")
  203. endif()
  204. _RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION}})
  205. if(Ruby_EXECUTABLE)
  206. break()
  207. endif()
  208. if(NOT _Ruby_FIND_VIRTUALENV STREQUAL "ONLY")
  209. break()
  210. endif()
  211. elseif(_Ruby_DEBUG_OUTPUT)
  212. message("_Ruby_FIND_VIRTUALENV doesn't match: ${_Ruby_FIND_VIRTUALENV}")
  213. endif()
  214. # try using standard paths
  215. find_program (Ruby_EXECUTABLE
  216. NAMES ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}
  217. NAMES_PER_DIR)
  218. _RUBY_VALIDATE_INTERPRETER (${Ruby_FIND_VERSION})
  219. if (Ruby_EXECUTABLE)
  220. break()
  221. else()
  222. # Remove first entry from names list.
  223. LIST(REMOVE_AT _Ruby_POSSIBLE_EXECUTABLE_NAMES 0)
  224. # If the list is now empty, abort.
  225. if (NOT _Ruby_POSSIBLE_EXECUTABLE_NAMES)
  226. break()
  227. else()
  228. # Otherwise, continue with the remaining list. Make sure that we clear
  229. # the cached variable.
  230. unset(Ruby_EXECUTABLE CACHE)
  231. endif()
  232. endif()
  233. endwhile()
  234. if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR)
  235. function(_RUBY_CONFIG_VAR RBVAR OUTVAR)
  236. execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']"
  237. RESULT_VARIABLE _Ruby_SUCCESS
  238. OUTPUT_VARIABLE _Ruby_OUTPUT
  239. ERROR_QUIET)
  240. if(_Ruby_SUCCESS OR _Ruby_OUTPUT STREQUAL "")
  241. execute_process(COMMAND ${Ruby_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']"
  242. RESULT_VARIABLE _Ruby_SUCCESS
  243. OUTPUT_VARIABLE _Ruby_OUTPUT
  244. ERROR_QUIET)
  245. endif()
  246. set(${OUTVAR} "${_Ruby_OUTPUT}" PARENT_SCOPE)
  247. endfunction()
  248. # query the ruby version
  249. _RUBY_CONFIG_VAR("MAJOR" Ruby_VERSION_MAJOR)
  250. _RUBY_CONFIG_VAR("MINOR" Ruby_VERSION_MINOR)
  251. _RUBY_CONFIG_VAR("TEENY" Ruby_VERSION_PATCH)
  252. # query the different directories
  253. _RUBY_CONFIG_VAR("archdir" Ruby_ARCH_DIR)
  254. _RUBY_CONFIG_VAR("arch" Ruby_ARCH)
  255. _RUBY_CONFIG_VAR("rubyhdrdir" Ruby_HDR_DIR)
  256. _RUBY_CONFIG_VAR("rubyarchhdrdir" Ruby_ARCHHDR_DIR)
  257. _RUBY_CONFIG_VAR("libdir" Ruby_POSSIBLE_LIB_DIR)
  258. _RUBY_CONFIG_VAR("rubylibdir" Ruby_RUBY_LIB_DIR)
  259. # site_ruby
  260. _RUBY_CONFIG_VAR("sitearchdir" Ruby_SITEARCH_DIR)
  261. _RUBY_CONFIG_VAR("sitelibdir" Ruby_SITELIB_DIR)
  262. # vendor_ruby available ?
  263. execute_process(COMMAND ${Ruby_EXECUTABLE} -r vendor-specific -e "print 'true'"
  264. OUTPUT_VARIABLE Ruby_HAS_VENDOR_RUBY ERROR_QUIET)
  265. if(Ruby_HAS_VENDOR_RUBY)
  266. _RUBY_CONFIG_VAR("vendorlibdir" Ruby_VENDORLIB_DIR)
  267. _RUBY_CONFIG_VAR("vendorarchdir" Ruby_VENDORARCH_DIR)
  268. endif()
  269. # save the results in the cache so we don't have to run ruby the next time again
  270. set(Ruby_VERSION_MAJOR ${Ruby_VERSION_MAJOR} CACHE PATH "The Ruby major version" FORCE)
  271. set(Ruby_VERSION_MINOR ${Ruby_VERSION_MINOR} CACHE PATH "The Ruby minor version" FORCE)
  272. set(Ruby_VERSION_PATCH ${Ruby_VERSION_PATCH} CACHE PATH "The Ruby patch version" FORCE)
  273. set(Ruby_ARCH_DIR ${Ruby_ARCH_DIR} CACHE PATH "The Ruby arch dir" FORCE)
  274. set(Ruby_HDR_DIR ${Ruby_HDR_DIR} CACHE PATH "The Ruby header dir (1.9+)" FORCE)
  275. set(Ruby_ARCHHDR_DIR ${Ruby_ARCHHDR_DIR} CACHE PATH "The Ruby arch header dir (2.0+)" FORCE)
  276. set(Ruby_POSSIBLE_LIB_DIR ${Ruby_POSSIBLE_LIB_DIR} CACHE PATH "The Ruby lib dir" FORCE)
  277. set(Ruby_RUBY_LIB_DIR ${Ruby_RUBY_LIB_DIR} CACHE PATH "The Ruby ruby-lib dir" FORCE)
  278. set(Ruby_SITEARCH_DIR ${Ruby_SITEARCH_DIR} CACHE PATH "The Ruby site arch dir" FORCE)
  279. set(Ruby_SITELIB_DIR ${Ruby_SITELIB_DIR} CACHE PATH "The Ruby site lib dir" FORCE)
  280. set(Ruby_HAS_VENDOR_RUBY ${Ruby_HAS_VENDOR_RUBY} CACHE BOOL "Vendor Ruby is available" FORCE)
  281. set(Ruby_VENDORARCH_DIR ${Ruby_VENDORARCH_DIR} CACHE PATH "The Ruby vendor arch dir" FORCE)
  282. set(Ruby_VENDORLIB_DIR ${Ruby_VENDORLIB_DIR} CACHE PATH "The Ruby vendor lib dir" FORCE)
  283. mark_as_advanced(
  284. Ruby_ARCH_DIR
  285. Ruby_ARCH
  286. Ruby_HDR_DIR
  287. Ruby_ARCHHDR_DIR
  288. Ruby_POSSIBLE_LIB_DIR
  289. Ruby_RUBY_LIB_DIR
  290. Ruby_SITEARCH_DIR
  291. Ruby_SITELIB_DIR
  292. Ruby_HAS_VENDOR_RUBY
  293. Ruby_VENDORARCH_DIR
  294. Ruby_VENDORLIB_DIR
  295. Ruby_VERSION_MAJOR
  296. Ruby_VERSION_MINOR
  297. Ruby_VERSION_PATCH
  298. )
  299. endif()
  300. # In case Ruby_EXECUTABLE could not be executed (e.g. cross compiling)
  301. # try to detect which version we found. This is not too good.
  302. if(Ruby_EXECUTABLE AND NOT Ruby_VERSION_MAJOR)
  303. # by default assume 1.8.0
  304. set(Ruby_VERSION_MAJOR 1)
  305. set(Ruby_VERSION_MINOR 8)
  306. set(Ruby_VERSION_PATCH 0)
  307. # check whether we found 1.9.x
  308. if(${Ruby_EXECUTABLE} MATCHES "ruby1\\.?9")
  309. set(Ruby_VERSION_MAJOR 1)
  310. set(Ruby_VERSION_MINOR 9)
  311. endif()
  312. # check whether we found 2.[0-7].x
  313. if(${Ruby_EXECUTABLE} MATCHES "ruby2")
  314. set(Ruby_VERSION_MAJOR 2)
  315. string(REGEX_REPLACE ${Ruby_EXECUTABLE} "ruby2\\.?([0-7])" "\\1" Ruby_VERSION_MINOR)
  316. endif()
  317. # check whether we found 3.[0-1].x
  318. if(${Ruby_EXECUTABLE} MATCHES "ruby3")
  319. set(Ruby_VERSION_MAJOR 3)
  320. string(REGEX_REPLACE ${Ruby_EXECUTABLE} "ruby3\\.?([0-1])" "\\1" Ruby_VERSION_MINOR)
  321. endif()
  322. endif()
  323. if(Ruby_VERSION_MAJOR)
  324. set(Ruby_VERSION "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}.${Ruby_VERSION_PATCH}")
  325. set(_Ruby_VERSION_SHORT "${Ruby_VERSION_MAJOR}.${Ruby_VERSION_MINOR}")
  326. set(_Ruby_VERSION_SHORT_NODOT "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}")
  327. set(_Ruby_NODOT_VERSION "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}${Ruby_VERSION_PATCH}")
  328. set(_Ruby_NODOT_VERSION_ZERO_PATCH "${Ruby_VERSION_MAJOR}${Ruby_VERSION_MINOR}0")
  329. endif()
  330. # FIXME: Currently we require both the interpreter and development components to be found
  331. # in order to use either. See issue #20474.
  332. find_path(Ruby_INCLUDE_DIR
  333. NAMES ruby.h
  334. HINTS
  335. ${Ruby_HDR_DIR}
  336. ${Ruby_ARCH_DIR}
  337. /usr/lib/ruby/${_Ruby_VERSION_SHORT}/i586-linux-gnu/
  338. )
  339. set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIR})
  340. # if ruby > 1.8 is required or if ruby > 1.8 was found, search for the config.h dir
  341. if( Ruby_FIND_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_VERSION VERSION_GREATER_EQUAL "1.9" OR Ruby_HDR_DIR)
  342. find_path(Ruby_CONFIG_INCLUDE_DIR
  343. NAMES ruby/config.h config.h
  344. HINTS
  345. ${Ruby_HDR_DIR}/${Ruby_ARCH}
  346. ${Ruby_ARCH_DIR}
  347. ${Ruby_ARCHHDR_DIR}
  348. )
  349. set(Ruby_INCLUDE_DIRS ${Ruby_INCLUDE_DIRS} ${Ruby_CONFIG_INCLUDE_DIR} )
  350. endif()
  351. # Determine the list of possible names for the ruby library
  352. 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})
  353. if(WIN32)
  354. set(_Ruby_POSSIBLE_MSVC_RUNTIMES "ucrt;msvcrt;vcruntime140;vcruntime140_1")
  355. if(MSVC_TOOLSET_VERSION)
  356. list(APPEND _Ruby_POSSIBLE_MSVC_RUNTIMES "msvcr${MSVC_TOOLSET_VERSION}")
  357. else()
  358. list(APPEND _Ruby_POSSIBLE_MSVC_RUNTIMES "msvcr")
  359. endif()
  360. set(_Ruby_POSSIBLE_VERSION_SUFFICES "${_Ruby_NODOT_VERSION};${_Ruby_NODOT_VERSION_ZERO_PATCH}")
  361. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  362. set(_Ruby_POSSIBLE_ARCH_PREFIXS "libx64-;x64-")
  363. else()
  364. set(_Ruby_POSSIBLE_ARCH_PREFIXS "lib")
  365. endif()
  366. foreach(_Ruby_MSVC_RUNTIME ${_Ruby_POSSIBLE_MSVC_RUNTIMES})
  367. foreach(_Ruby_VERSION_SUFFIX ${_Ruby_POSSIBLE_VERSION_SUFFICES})
  368. foreach(_Ruby_ARCH_PREFIX ${_Ruby_POSSIBLE_ARCH_PREFIXS})
  369. list(APPEND _Ruby_POSSIBLE_LIB_NAMES
  370. "${_Ruby_ARCH_PREFIX}${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}"
  371. "${_Ruby_ARCH_PREFIX}${_Ruby_MSVC_RUNTIME}-ruby${_Ruby_VERSION_SUFFIX}-static")
  372. endforeach()
  373. endforeach()
  374. endforeach()
  375. endif()
  376. find_library(Ruby_LIBRARY NAMES ${_Ruby_POSSIBLE_LIB_NAMES} HINTS ${Ruby_POSSIBLE_LIB_DIR} )
  377. set(_Ruby_REQUIRED_VARS Ruby_EXECUTABLE Ruby_INCLUDE_DIR Ruby_LIBRARY)
  378. if(_Ruby_VERSION_SHORT_NODOT GREATER 18)
  379. list(APPEND _Ruby_REQUIRED_VARS Ruby_CONFIG_INCLUDE_DIR)
  380. endif()
  381. if(_Ruby_DEBUG_OUTPUT)
  382. message(STATUS "--------FindRuby.cmake debug------------")
  383. message(STATUS "_Ruby_POSSIBLE_EXECUTABLE_NAMES: ${_Ruby_POSSIBLE_EXECUTABLE_NAMES}")
  384. message(STATUS "_Ruby_POSSIBLE_LIB_NAMES: ${_Ruby_POSSIBLE_LIB_NAMES}")
  385. message(STATUS "Ruby_ARCH_DIR: ${Ruby_ARCH_DIR}")
  386. message(STATUS "Ruby_HDR_DIR: ${Ruby_HDR_DIR}")
  387. message(STATUS "Ruby_POSSIBLE_LIB_DIR: ${Ruby_POSSIBLE_LIB_DIR}")
  388. message(STATUS "Found Ruby_VERSION: \"${Ruby_VERSION}\" , short: \"${_Ruby_VERSION_SHORT}\", nodot: \"${_Ruby_VERSION_SHORT_NODOT}\"")
  389. message(STATUS "_Ruby_REQUIRED_VARS: ${_Ruby_REQUIRED_VARS}")
  390. message(STATUS "Ruby_EXECUTABLE: ${Ruby_EXECUTABLE}")
  391. message(STATUS "Ruby_LIBRARY: ${Ruby_LIBRARY}")
  392. message(STATUS "Ruby_INCLUDE_DIR: ${Ruby_INCLUDE_DIR}")
  393. message(STATUS "Ruby_CONFIG_INCLUDE_DIR: ${Ruby_CONFIG_INCLUDE_DIR}")
  394. message(STATUS "--------------------")
  395. endif()
  396. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  397. FIND_PACKAGE_HANDLE_STANDARD_ARGS(Ruby REQUIRED_VARS ${_Ruby_REQUIRED_VARS}
  398. VERSION_VAR Ruby_VERSION )
  399. if(Ruby_FOUND)
  400. set(Ruby_LIBRARIES ${Ruby_LIBRARY})
  401. endif()
  402. mark_as_advanced(
  403. Ruby_EXECUTABLE
  404. Ruby_LIBRARY
  405. Ruby_INCLUDE_DIR
  406. Ruby_CONFIG_INCLUDE_DIR
  407. )
  408. # Set some variables for compatibility with previous version of this file (no need to provide a CamelCase version of that...)
  409. set(RUBY_POSSIBLE_LIB_PATH ${Ruby_POSSIBLE_LIB_DIR})
  410. set(RUBY_RUBY_LIB_PATH ${Ruby_RUBY_LIB_DIR})
  411. set(RUBY_INCLUDE_PATH ${Ruby_INCLUDE_DIRS})
  412. # Backwards compatibility
  413. # Define upper case versions of output variables
  414. foreach(Camel
  415. Ruby_EXECUTABLE
  416. Ruby_INCLUDE_DIRS
  417. Ruby_LIBRARY
  418. Ruby_VERSION
  419. Ruby_VERSION_MAJOR
  420. Ruby_VERSION_MINOR
  421. Ruby_VERSION_PATCH
  422. Ruby_ARCH_DIR
  423. Ruby_ARCH
  424. Ruby_HDR_DIR
  425. Ruby_ARCHHDR_DIR
  426. Ruby_POSSIBLE_LIB_DIR
  427. Ruby_RUBY_LIB_DIR
  428. Ruby_SITEARCH_DIR
  429. Ruby_SITELIB_DIR
  430. Ruby_HAS_VENDOR_RUBY
  431. Ruby_VENDORARCH_DIR
  432. Ruby_VENDORLIB_DIR
  433. )
  434. string(TOUPPER ${Camel} UPPER)
  435. set(${UPPER} ${${Camel}})
  436. endforeach()