How to cancel installation of my module if requirements are not met
You can do this in hook_requirements, from the documentation:


  During the 'install' phase, modules can for example assert that
  library or server versions are available or sufficient. Note that the
  installation of a module can happen during installation of Drupal
  itself (by install.php) with an installation profile or later by hand.
  As a consequence, install-time requirements must be checked without
  access to the full Drupal API, because it is not available during
  install.php. For localization you should for example use $t = get_t()
  to retrieve the appropriate localization function name (t() or st()).
  If a requirement has a severity of REQUIREMENT_ERROR, install.php will
  abort or at least the module will not install. Other severity levels
  have no effect on the installation. Module dependencies do not belong
  to these installation requirements, but should be defined in the
  module's .info file.


After your check, you return array (see docs again) with REQUIREMENT_ERROR.

function example_requirements($phase) {
  $requirements = array();
  // Ensure translations do not break at install time
  $t = get_t();

  $requirements['example'] = array(
    'title' =&gt; $t('Example Library'),
  );

  $libraries = libraries_get_libraries();
  if (isset($libraries['example'])) {
    $requirements['example']['value'] = $t('Installed');
    $requirements['example']['severity'] = REQUIREMENT_OK;
  }
  else {
    $requirements['example']['value'] = $t('Not Installed');
    $requirements['example']['severity'] = REQUIREMENT_ERROR;
    $requirements['example']['description'] = $t('Please install the example library %url.', array('%url' =&gt; 'http://example.com'));
  }

  return $requirements;
}


You can check this code example here.