FindRuby.cmake 18 KB

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