1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmFindProgramCommand.cxx,v $
6 Date: $Date: 2002-05-12 15:31:45 $
7 Version: $Revision: 1.23 $
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 "cmFindProgramCommand.h"
18 #include "cmCacheManager.h"
23 // cmFindProgramCommand
24 bool cmFindProgramCommand::InitialPass(std::vector
<std::string
> const& argsIn
)
26 if(argsIn
.size() < 2 )
28 this->SetError("called with incorrect number of arguments");
31 std::string doc
= "Path to a program.";
32 size_t size
= argsIn
.size();
33 std::vector
<std::string
> argst
;
34 for(unsigned int j
= 0; j
< size
; ++j
)
36 if(argsIn
[j
] != "DOC")
38 argst
.push_back(argsIn
[j
]);
49 std::vector
<std::string
> args
;
50 cmSystemTools::ExpandListArguments(argst
, args
);
53 std::vector
<std::string
>::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"))
67 cmCacheManager::CacheEntry
* e
=
68 cmCacheManager::GetInstance()->GetCacheEntry(args
[0].c_str());
71 doc
= e
->m_HelpString
;
74 std::vector
<std::string
> path
;
75 std::vector
<std::string
> names
;
76 bool foundName
= false;
77 bool foundPath
= false;
78 bool doingNames
= true;
79 bool no_system_path
= false;
80 for (unsigned int j
= 1; j
< args
.size(); ++j
)
82 if(args
[j
] == "NAMES")
87 else if (args
[j
] == "PATHS")
92 else if (args
[j
] == "NO_SYSTEM_PATH")
94 no_system_path
= true;
100 names
.push_back(args
[j
]);
104 cmSystemTools::ExpandRegistryValues(args
[j
]);
105 // Glob the entry in case of wildcards.
106 cmSystemTools::GlobDirs(args
[j
].c_str(), path
);
110 // if it is not in the cache, then search the system path
111 // add any user specified paths
112 if(!foundPath
&& !foundName
)
116 names
.push_back(args
[1]);
117 for (unsigned int j
= 2; j
< args
.size(); j
++)
120 std::string exp
= args
[j
];
121 cmSystemTools::ExpandRegistryValues(exp
);
123 // Glob the entry in case of wildcards.
124 cmSystemTools::GlobDirs(exp
.c_str(), path
);
127 for(std::vector
<std::string
>::iterator i
= names
.begin();
128 i
!= names
.end() ; ++i
)
130 // Try to find the program.
131 std::string result
= cmSystemTools::FindProgram(i
->c_str(),
136 // Save the value in the cache
137 m_Makefile
->AddCacheDefinition(define
,
140 cmCacheManager::FILEPATH
);
145 m_Makefile
->AddCacheDefinition(args
[0].c_str(),
148 cmCacheManager::FILEPATH
);