ENH: mark some vars as advanced (and resort the list)
[cmake.git] / Source / cmFindFileCommand.cxx
blob9313581aa263176b7d237a916d6519beb8a92d61
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmFindFileCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-03-29 19:20:18 $
7 Version: $Revision: 1.17 $
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 "cmFindFileCommand.h"
18 #include "cmCacheManager.h"
19 #include <stdlib.h>
20 #include <stdio.h>
23 // cmFindFileCommand
24 bool cmFindFileCommand::InitialPass(std::vector<std::string> const& argsIn)
26 if(argsIn.size() < 2)
28 this->SetError("called with incorrect number of arguments");
29 return false;
31 std::string helpString = "Where can the ";
32 helpString += argsIn[1] + " file be found";
33 size_t size = argsIn.size();
34 std::vector<std::string> argst;
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 std::vector<std::string>::const_iterator i = args.begin();
54 // Use the first argument as the name of something to be defined
55 const char* define = (*i).c_str();
56 i++; // move iterator to next arg
57 // Now check and see if the value has been stored in the cache
58 // already, if so use that value and don't look for the program
59 const char* cacheValue
60 = m_Makefile->GetDefinition(define);
61 if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
63 return true;
65 // if it is not in the cache, then search the system path
66 std::vector<std::string> path;
68 // add any user specified paths
69 for (unsigned int j = 2; j < args.size(); j++)
71 // Glob the entry in case of wildcards.
72 cmSystemTools::GlobDirs(args[j].c_str(), path);
75 // add the standard path
76 cmSystemTools::GetPath(path);
77 for(unsigned int k=0; k < path.size(); k++)
79 std::string tryPath = path[k];
80 tryPath += "/";
81 tryPath += *i;
82 if(cmSystemTools::FileExists(tryPath.c_str()))
84 // Save the value in the cache
85 m_Makefile->AddCacheDefinition(define,
86 tryPath.c_str(),
87 helpString.c_str(),
88 cmCacheManager::FILEPATH);
89 return true;
92 m_Makefile->AddCacheDefinition(args[0].c_str(),
93 "NOTFOUND",
94 helpString.c_str(),
95 cmCacheManager::FILEPATH);
96 return true;