1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmFindLibraryCommand.cxx,v $
6 Date: $Date: 2002-06-14 14:37:59 $
7 Version: $Revision: 1.28 $
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 "cmFindLibraryCommand.h"
18 #include "cmCacheManager.h"
20 // cmFindLibraryCommand
21 bool cmFindLibraryCommand::InitialPass(std::vector
<std::string
> const& argsIn
)
25 this->SetError("called with incorrect number of arguments");
28 std::string helpString
;
29 size_t size
= argsIn
.size();
30 std::vector
<std::string
> argst
;
31 for(unsigned int j
= 0; j
< size
; ++j
)
33 if(argsIn
[j
] != "DOC")
35 argst
.push_back(argsIn
[j
]);
41 helpString
= argsIn
[j
+1];
46 std::vector
<std::string
> args
;
47 cmSystemTools::ExpandListArguments(argst
, args
);
49 std::vector
<std::string
> path
;
50 std::vector
<std::string
> names
;
51 bool foundName
= false;
52 bool foundPath
= false;
53 bool doingNames
= true;
54 for (unsigned int j
= 1; j
< args
.size(); ++j
)
56 if(args
[j
] == "NAMES")
61 else if (args
[j
] == "PATHS")
70 names
.push_back(args
[j
]);
74 // Glob the entry in case of wildcards.
75 cmSystemTools::GlobDirs(args
[j
].c_str(), path
);
79 // old style name path1 path2 path3
80 if(!foundPath
&& !foundName
)
84 names
.push_back(args
[1]);
85 // add any user specified paths
86 for (unsigned int j
= 2; j
< args
.size(); j
++)
89 std::string exp
= args
[j
];
90 cmSystemTools::ExpandRegistryValues(exp
);
92 // Glob the entry in case of wildcards.
93 cmSystemTools::GlobDirs(exp
.c_str(), path
);
96 if(helpString
.size() == 0)
98 helpString
= "Where can ";
99 if (names
.size() == 0)
101 helpString
+= "the (unknown) library be found";
103 else if (names
.size() == 1)
105 helpString
+= "the " + names
[0] + " library be found";
109 helpString
+= "one of the " + names
[0];
110 for (unsigned int j
= 1; j
< names
.size() - 1; ++j
)
112 helpString
+= ", " + names
[j
];
114 helpString
+= " or " + names
[names
.size() - 1] + " libraries be found";
118 const char* cacheValue
119 = m_Makefile
->GetDefinition(args
[0].c_str());
120 if(cacheValue
&& strcmp(cacheValue
, "NOTFOUND"))
126 for(std::vector
<std::string
>::iterator i
= names
.begin();
127 i
!= names
.end() ; ++i
)
129 library
= cmSystemTools::FindLibrary(i
->c_str(),
134 m_Makefile
->AddCacheDefinition(args
[0].c_str(),
137 cmCacheManager::FILEPATH
);
141 m_Makefile
->AddCacheDefinition(args
[0].c_str(),
144 cmCacheManager::FILEPATH
);