FindRuby.cmake 19 KB

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