1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmFindFileCommand.cxx,v $
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"
24 bool cmFindFileCommand::InitialPass(std::vector
<std::string
> const& argsIn
)
28 this->SetError("called with incorrect number of arguments");
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
]);
45 helpString
= argsIn
[j
+1];
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"))
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
];
82 if(cmSystemTools::FileExists(tryPath
.c_str()))
84 // Save the value in the cache
85 m_Makefile
->AddCacheDefinition(define
,
88 cmCacheManager::FILEPATH
);
92 m_Makefile
->AddCacheDefinition(args
[0].c_str(),
95 cmCacheManager::FILEPATH
);