FIX: stupid pb fixed (close to being medieval'ed by The Ken)
[cmake.git] / Source / cmFindPathCommand.cxx
blob8e779ca08c946ab47827260dbf7276f47ee9b303
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmFindPathCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-03-29 19:20:18 $
7 Version: $Revision: 1.16 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmFindPathCommand.h"
18 #include "cmCacheManager.h"
20 // cmFindPathCommand
21 bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
23 if(argsIn.size() < 2)
25 this->SetError("called with incorrect number of arguments");
26 return false;
29 // Now check and see if the value has been stored in the cache
30 // already, if so use that value and don't look for the program
31 std::string helpString = "What is the path where the file ";
32 helpString += argsIn[1] + " can be found";
33 std::vector<std::string> argst;
34 size_t size = argsIn.size();
35 for(unsigned int j = 0; j < size; ++j)
37 if(argsIn[j] != "DOC")
39 argst.push_back(argsIn[j]);
41 else
43 if(j+1 < size)
45 helpString = argsIn[j+1];
47 break;
50 std::vector<std::string> args;
51 cmSystemTools::ExpandListArguments(argst, args);
53 const char* cacheValue
54 = m_Makefile->GetDefinition(args[0].c_str());
55 if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
57 return true;
59 if(cacheValue)
61 cmCacheManager::CacheEntry* e =
62 cmCacheManager::GetInstance()->GetCacheEntry(args[0].c_str());
63 if(e)
65 helpString = e->m_HelpString;
68 std::vector<std::string> path;
69 // add any user specified paths
70 for (unsigned int j = 2; j < args.size(); j++)
72 // expand variables
73 std::string exp = args[j];
74 cmSystemTools::ExpandRegistryValues(exp);
76 // Glob the entry in case of wildcards.
77 cmSystemTools::GlobDirs(exp.c_str(), path);
80 // add the standard path
81 cmSystemTools::GetPath(path);
82 unsigned int k;
83 for(k=0; k < path.size(); k++)
85 std::string tryPath = path[k];
86 tryPath += "/";
87 tryPath += args[1];
88 if(cmSystemTools::FileExists(tryPath.c_str()))
90 path[k] = cmSystemTools::CollapseFullPath(path[k].c_str());
91 m_Makefile->AddCacheDefinition(args[0].c_str(),
92 path[k].c_str(),
93 helpString.c_str(),
94 cmCacheManager::PATH);
95 return true;
99 m_Makefile->AddCacheDefinition(args[0].c_str(),
100 "NOTFOUND",
101 helpString.c_str(),
102 cmCacheManager::PATH);
103 return true;