diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2012-02-17 17:06:07 (GMT) |
---|---|---|
committer | Rolf Eike Beer <eike@sf-mail.de> | 2012-02-17 17:06:07 (GMT) |
commit | 854e76237ce3e8f03d9cabcad1f8f37e04992ad3 (patch) | |
tree | 8182348a80536f54728f4a58df8660f462cca9a7 /Modules/FindRuby.cmake | |
parent | d03606a19cc05872baf23269ae8ec61d2e0719e8 (diff) | |
download | CMake-854e76237ce3e8f03d9cabcad1f8f37e04992ad3.zip CMake-854e76237ce3e8f03d9cabcad1f8f37e04992ad3.tar.gz CMake-854e76237ce3e8f03d9cabcad1f8f37e04992ad3.tar.bz2 |
FindRuby: clean up querying variables from Ruby
Newer Ruby versions (from 1.9 onward) seem to warn if you query Config::CONFIG
and print a warning to use RbConfig instead. RbConfig seems to also work in
older versions, at least in 1.8. Use a macro to query RbConfig first and only
if that doesn't give anything fall back to Config.
Diffstat (limited to 'Modules/FindRuby.cmake')
-rw-r--r-- | Modules/FindRuby.cmake | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/Modules/FindRuby.cmake b/Modules/FindRuby.cmake index c4adfd1..5e973e4 100644 --- a/Modules/FindRuby.cmake +++ b/Modules/FindRuby.cmake @@ -61,49 +61,44 @@ FIND_PROGRAM(RUBY_EXECUTABLE NAMES ${_RUBY_POSSIBLE_EXECUTABLE_NAMES}) IF(RUBY_EXECUTABLE AND NOT RUBY_VERSION_MAJOR) - # query the ruby version - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MAJOR']" - OUTPUT_VARIABLE RUBY_VERSION_MAJOR) + FUNCTION(_RUBY_CONFIG_VAR RBVAR OUTVAR) + EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['${RBVAR}']" + RESULT_VARIABLE _RUBY_SUCCESS + OUTPUT_VARIABLE _RUBY_OUTPUT + ERROR_QUIET) + IF(_RUBY_SUCCESS OR NOT _RUBY_OUTPUT) + EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['${RBVAR}']" + RESULT_VARIABLE _RUBY_SUCCESS + OUTPUT_VARIABLE _RUBY_OUTPUT + ERROR_QUIET) + ENDIF(_RUBY_SUCCESS OR NOT _RUBY_OUTPUT) + SET(${OUTVAR} "${_RUBY_OUTPUT}" PARENT_SCOPE) + ENDFUNCTION(_RUBY_CONFIG_VAR) - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['MINOR']" - OUTPUT_VARIABLE RUBY_VERSION_MINOR) - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['TEENY']" - OUTPUT_VARIABLE RUBY_VERSION_PATCH) + # query the ruby version + _RUBY_CONFIG_VAR("MAJOR" RUBY_VERSION_MAJOR) + _RUBY_CONFIG_VAR("MINOR" RUBY_VERSION_MINOR) + _RUBY_CONFIG_VAR("TEENY" RUBY_VERSION_PATCH) # query the different directories - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['archdir']" - OUTPUT_VARIABLE RUBY_ARCH_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['arch']" - OUTPUT_VARIABLE RUBY_ARCH) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubyhdrdir']" - OUTPUT_VARIABLE RUBY_HDR_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['libdir']" - OUTPUT_VARIABLE RUBY_POSSIBLE_LIB_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['rubylibdir']" - OUTPUT_VARIABLE RUBY_RUBY_LIB_DIR) + _RUBY_CONFIG_VAR("archdir" RUBY_ARCH_DIR) + _RUBY_CONFIG_VAR("arch" RUBY_ARCH) + _RUBY_CONFIG_VAR("rubyhdrdir" RUBY_HDR_DIR) + _RUBY_CONFIG_VAR("libdir" RUBY_POSSIBLE_LIB_DIR) + _RUBY_CONFIG_VAR("rubylibdir" RUBY_RUBY_LIB_DIR) # site_ruby - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitearchdir']" - OUTPUT_VARIABLE RUBY_SITEARCH_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['sitelibdir']" - OUTPUT_VARIABLE RUBY_SITELIB_DIR) + _RUBY_CONFIG_VAR("sitearchdir" RUBY_SITEARCH_DIR) + _RUBY_CONFIG_VAR("sitelibdir" RUBY_SITELIB_DIR) # vendor_ruby available ? EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r vendor-specific -e "print 'true'" OUTPUT_VARIABLE RUBY_HAS_VENDOR_RUBY ERROR_QUIET) IF(RUBY_HAS_VENDOR_RUBY) - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorlibdir']" - OUTPUT_VARIABLE RUBY_VENDORLIB_DIR) - - EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print Config::CONFIG['vendorarchdir']" - OUTPUT_VARIABLE RUBY_VENDORARCH_DIR) + _RUBY_CONFIG_VAR("vendorlibdir" RUBY_VENDORLIB_DIR) + _RUBY_CONFIG_VAR("vendorarchdir" RUBY_VENDORARCH_DIR) ENDIF(RUBY_HAS_VENDOR_RUBY) # save the results in the cache so we don't have to run ruby the next time again |