FindRuby.cmake 17 KB

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