cmFindLibraryCommand.cxx 3.79 KB
Newer Older
1 2
/*=========================================================================

3
  Program:   CMake - Cross-Platform Makefile Generator
4 5 6 7 8
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

9 10
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
11

Will Schroeder's avatar
Will Schroeder committed
12 13 14
     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.
15 16

=========================================================================*/
17
#include "cmFindLibraryCommand.h"
18
#include "cmCacheManager.h"
19

20
// cmFindLibraryCommand
21
bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
22
{
23
  if(argsIn.size() < 2)
24 25 26
    {
    this->SetError("called with incorrect number of arguments");
    return false;
27 28
    } 
  std::string helpString;
29
  size_t size = argsIn.size();
30
  std::vector<std::string> args;
31 32 33 34
  for(unsigned int j = 0; j < size; ++j)
    {
    if(argsIn[j] != "DOC")
      {
35
      args.push_back(argsIn[j]);
36 37 38 39 40 41 42 43 44
      }
    else
      {
      if(j+1 < size)
        {
        helpString = argsIn[j+1];
        }
      break;
      }
45
    }
46

47
  std::vector<std::string> path;
48 49 50 51 52
  std::vector<std::string> names;
  bool foundName = false;
  bool foundPath = false;
  bool doingNames = true;
  for (unsigned int j = 1; j < args.size(); ++j)
53
    {
54
    if(args[j] == "NAMES")
Ken Martin's avatar
Ken Martin committed
55
      {
56 57
      doingNames = true;
      foundName = true;
Ken Martin's avatar
Ken Martin committed
58
      }
59
    else if (args[j] == "PATHS")
Ken Martin's avatar
Ken Martin committed
60
      {
61 62 63 64 65 66 67 68 69 70 71
      doingNames = false;
      foundPath = true;
      }
    else
      { 
      if(doingNames)
        {
        names.push_back(args[j]);
        }
      else
        {
72
        cmSystemTools::ExpandRegistryValues(args[j]);
73 74
        // Glob the entry in case of wildcards.
        cmSystemTools::GlobDirs(args[j].c_str(), path);
75
        }
Ken Martin's avatar
Ken Martin committed
76
      }
77 78 79 80 81 82 83 84 85
    }
  // old style name path1 path2 path3
  if(!foundPath && !foundName)
    {
    names.clear();
    path.clear();
    names.push_back(args[1]);
    // add any user specified paths
    for (unsigned int j = 2; j < args.size(); j++)
Ken Martin's avatar
Ken Martin committed
86
      {
87 88
      // expand variables
      std::string exp = args[j];
89
      cmSystemTools::ExpandRegistryValues(exp);
90 91 92
      
      // Glob the entry in case of wildcards.
      cmSystemTools::GlobDirs(exp.c_str(), path);
93 94
      }
    }
95
  if(helpString.size() == 0)
96
    {
97 98 99 100 101 102 103 104 105 106
    helpString = "Where can ";
    if (names.size() == 0)
      {
      helpString += "the (unknown) library be found";
      }
    else if (names.size() == 1)
      {
      helpString += "the " + names[0] + " library be found";
      }
    else
107
      {
108 109 110 111 112 113
      helpString += "one of the " + names[0];
      for (unsigned int j = 1; j < names.size() - 1; ++j)
        {
        helpString += ", " + names[j];
        }
      helpString += " or " + names[names.size() - 1] + " libraries be found";
114 115
      }
    }
116
  
117
  const char* cacheValue
118
    = m_Makefile->GetDefinition(args[0].c_str());
Bill Hoffman's avatar
Bill Hoffman committed
119
  if(cacheValue && !cmSystemTools::IsNOTFOUND(cacheValue))
120 121 122 123
    { 
    return true;
    }

124 125 126 127
  std::string library;
  for(std::vector<std::string>::iterator i = names.begin();
      i != names.end() ; ++i)
    {
128
    library = m_Makefile->FindLibrary(i->c_str(), path);
129 130
    if(library != "")
      {  
131 132 133 134
      m_Makefile->AddCacheDefinition(args[0].c_str(),
                                     library.c_str(),
                                     helpString.c_str(),
                                     cmCacheManager::FILEPATH);
Ken Martin's avatar
Ken Martin committed
135
      return true;
136
      } 
137
    }
138
  std::string s = args[0] + "-NOTFOUND";
139
  m_Makefile->AddCacheDefinition(args[0].c_str(),
140
                                 s.c_str(),
141 142
                                 helpString.c_str(),
                                 cmCacheManager::FILEPATH);
143
  return true;
144 145
}