summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBill Hoffman <bill.hoffman@kitware.com>2001-05-09 18:53:32 (GMT)
committerBill Hoffman <bill.hoffman@kitware.com>2001-05-09 18:53:32 (GMT)
commitf07ee5b8177e9e08f290e3acdff6c31d6b694bf6 (patch)
tree7d08c74e73010dfe3bd735b592fd64f09de5ab9c /Source
parent1dc7ae38ead50498b9e813d7c6e96f9d850b45ea (diff)
downloadCMake-f07ee5b8177e9e08f290e3acdff6c31d6b694bf6.zip
CMake-f07ee5b8177e9e08f290e3acdff6c31d6b694bf6.tar.gz
CMake-f07ee5b8177e9e08f290e3acdff6c31d6b694bf6.tar.bz2
ENH: change find library and find program to look for more than one name
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCommand.h2
-rw-r--r--Source/cmFindLibraryCommand.cxx113
-rw-r--r--Source/cmFindLibraryCommand.h4
-rw-r--r--Source/cmFindProgramCommand.cxx87
-rw-r--r--Source/cmSystemTools.cxx60
-rw-r--r--Source/cmSystemTools.h10
-rw-r--r--Source/cmUnixMakefileGenerator.cxx31
7 files changed, 211 insertions, 96 deletions
diff --git a/Source/cmCommand.h b/Source/cmCommand.h
index 5156d46..aeb3a72 100644
--- a/Source/cmCommand.h
+++ b/Source/cmCommand.h
@@ -148,7 +148,7 @@ public:
{
if(m_Error.length() == 0)
{
- std::string m_Error = this->GetName();
+ m_Error = this->GetName();
m_Error += " uknown error.";
}
return m_Error.c_str();
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index 6d2df8f..e60d4ed 100644
--- a/Source/cmFindLibraryCommand.cxx
+++ b/Source/cmFindLibraryCommand.cxx
@@ -57,78 +57,79 @@ bool cmFindLibraryCommand::Invoke(std::vector<std::string>& args)
= cmCacheManager::GetInstance()->GetCacheValue(args[0].c_str());
if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
{
- m_Makefile->AddDefinition(args[0].c_str(), cacheValue);
- cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
- cacheValue,
- helpString.c_str(),
- cmCacheManager::PATH);
+ m_Makefile->AddDefinition(args[0].c_str(), cacheValue);
+ cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
+ cacheValue,
+ helpString.c_str(),
+ cmCacheManager::FILEPATH);
return true;
}
-
std::vector<std::string> path;
- // add any user specified paths
- for (unsigned int j = 2; j < args.size(); j++)
- {
- // expand variables
- std::string exp = args[j];
- m_Makefile->ExpandVariablesInString(exp);
- path.push_back(exp);
- }
-
- // add the standard path
- cmSystemTools::GetPath(path);
- unsigned int k;
- for(k=0; k < path.size(); k++)
+ std::vector<std::string> names;
+ bool namePathStyle = false;
+ bool foundName = false;
+ bool foundPath = false;
+ bool doingNames = true;
+ for (unsigned int j = 1; j < args.size(); ++j)
{
- std::string tryPath = path[k];
- tryPath += "/";
- std::string testF;
- testF = tryPath + args[1] + ".lib";
- if(cmSystemTools::FileExists(testF.c_str()))
+ if(args[j] == "NAMES")
{
- m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
- cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
- path[k].c_str(),
- helpString.c_str(),
- cmCacheManager::PATH);
- return true;
+ doingNames = true;
+ foundName = true;
}
- testF = tryPath + "lib" + args[1] + ".so";
- if(cmSystemTools::FileExists(testF.c_str()))
+ else if (args[j] == "PATHS")
{
- m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
- cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
- path[k].c_str(),
- helpString.c_str(),
- cmCacheManager::PATH);
- return true;
+ doingNames = false;
+ foundPath = true;
+ }
+ else
+ {
+ m_Makefile->ExpandVariablesInString(args[j]);
+ if(doingNames)
+ {
+ names.push_back(args[j]);
+ }
+ else
+ {
+ path.push_back(args[j]);
+ }
}
- testF = tryPath + "lib" + args[1] + ".a";
- if(cmSystemTools::FileExists(testF.c_str()))
+ }
+ // old style name path1 path2 path3
+ if(!foundPath && !foundName)
+ {
+ names.clear();
+ path.clear();
+ names.push_back(args[1]);
+ // add any user specified paths
+ for (unsigned int j = 2; j < args.size(); j++)
{
- m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
+ // expand variables
+ std::string exp = args[j];
+ m_Makefile->ExpandVariablesInString(exp);
+ path.push_back(exp);
+ }
+ }
+ std::string library;
+ for(std::vector<std::string>::iterator i = names.begin();
+ i != names.end() ; ++i)
+ {
+ library = cmSystemTools::FindLibrary(i->c_str(),
+ path);
+ if(library != "")
+ {
+ m_Makefile->AddDefinition(args[0].c_str(), library.c_str());
cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
- path[k].c_str(),
+ library.c_str(),
helpString.c_str(),
- cmCacheManager::PATH);
+ cmCacheManager::FILEPATH);
return true;
- }
- testF = tryPath + "lib" + args[1] + ".sl";
- if(cmSystemTools::FileExists(testF.c_str()))
- {
- m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
- cmCacheManager::GetInstance()->
- AddCacheEntry(args[0].c_str(),
- path[k].c_str(),
- helpString.c_str(),
- cmCacheManager::PATH);
- return true;
- }
+ }
}
cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
"NOTFOUND",
helpString.c_str(),
- cmCacheManager::PATH);
+ cmCacheManager::FILEPATH);
return true;
}
diff --git a/Source/cmFindLibraryCommand.h b/Source/cmFindLibraryCommand.h
index 2953647..5562dc4 100644
--- a/Source/cmFindLibraryCommand.h
+++ b/Source/cmFindLibraryCommand.h
@@ -94,8 +94,8 @@ public:
virtual const char* GetFullDocumentation()
{
return
- "FIND_LIBRARY(DEFINE_PATH libraryName path1 path2 path3...)\n"
- "If the library is found, then DEFINE_PATH is set to the path where it was found";
+ "FIND_LIBRARY(DEFINE_PATH libraryName [NAMES] name1 name2 name3 [PATHS path1 path2 path3...])\n"
+ "If the library is found, then DEFINE_PATH is set to the full path where it was found";
}
cmTypeMacro(cmFindLibraryCommand, cmCommand);
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx
index ce97478..cb234f9 100644
--- a/Source/cmFindProgramCommand.cxx
+++ b/Source/cmFindProgramCommand.cxx
@@ -60,40 +60,77 @@ bool cmFindProgramCommand::Invoke(std::vector<std::string>& args)
// already, if so use that value and don't look for the program
const char* cacheValue
= cmCacheManager::GetInstance()->GetCacheValue(define);
- if(cacheValue)
+ if(cacheValue && strcmp(cacheValue, "NOTFOUND"))
{
m_Makefile->AddDefinition(define, cacheValue);
return true;
}
-
- // if it is not in the cache, then search the system path
- // add any user specified paths
std::vector<std::string> path;
- for (unsigned int j = 2; j < args.size(); j++)
+ std::vector<std::string> names;
+ bool namePathStyle = false;
+ bool foundName = false;
+ bool foundPath = false;
+ bool doingNames = true;
+ for (unsigned int j = 1; j < args.size(); ++j)
{
- // expand variables
- std::string exp = args[j];
- m_Makefile->ExpandVariablesInString(exp);
- path.push_back(exp);
+ if(args[j] == "NAMES")
+ {
+ doingNames = true;
+ foundName = true;
+ }
+ else if (args[j] == "PATHS")
+ {
+ doingNames = false;
+ foundPath = true;
+ }
+ else
+ {
+ m_Makefile->ExpandVariablesInString(args[j]);
+ if(doingNames)
+ {
+ names.push_back(args[j]);
+ }
+ else
+ {
+ path.push_back(args[j]);
+ }
+ }
}
-
- // Try to find the program.
- std::string result = cmSystemTools::FindProgram(i->c_str(), path);
-
- if(result != "")
+ // if it is not in the cache, then search the system path
+ // add any user specified paths
+ if(!foundPath && !foundName)
{
- // Save the value in the cache
- cmCacheManager::GetInstance()->AddCacheEntry(define,
- result.c_str(),
- "Path to a program.",
- cmCacheManager::FILEPATH);
- m_Makefile->AddDefinition(define, result.c_str());
- return true;
+ path.clear();
+ names.clear();
+ names.push_back(args[1]);
+ for (unsigned int j = 2; j < args.size(); j++)
+ {
+ // expand variables
+ std::string exp = args[j];
+ m_Makefile->ExpandVariablesInString(exp);
+ path.push_back(exp);
+ }
+ }
+ for(std::vector<std::string>::iterator i = names.begin();
+ i != names.end() ; ++i)
+ {
+ // Try to find the program.
+ std::string result = cmSystemTools::FindProgram(i->c_str(), path);
+ if(result != "")
+ {
+ // Save the value in the cache
+ cmCacheManager::GetInstance()->AddCacheEntry(define,
+ result.c_str(),
+ "Path to a program.",
+ cmCacheManager::FILEPATH);
+ m_Makefile->AddDefinition(define, result.c_str());
+ return true;
+ }
}
- std::string error = "Faild to find program: \"";
- error += *i;
- error += "\" ";
- this->SetError(error.c_str());
+ cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
+ "NOTFOUND",
+ "Path to a program",
+ cmCacheManager::FILEPATH);
return true;
}
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx
index afc92e8..89e8016 100644
--- a/Source/cmSystemTools.cxx
+++ b/Source/cmSystemTools.cxx
@@ -613,8 +613,6 @@ std::string cmSystemTools::TemporaryFileName()
{
return tempnam(0, "cmake");
}
-
-
@@ -657,6 +655,63 @@ std::string cmSystemTools::FindProgram(const char* name,
return "";
}
+
+/**
+ * Find the library with the given name. Searches the given path and then
+ * the system search path. Returns the full path to the library if it is
+ * found. Otherwise, the empty string is returned.
+ */
+std::string cmSystemTools::FindLibrary(const char* name,
+ const std::vector<std::string>& userPaths)
+{
+ // See if the executable exists as written.
+ if(cmSystemTools::FileExists(name))
+ {
+ return cmSystemTools::CollapseFullPath(name);
+ }
+
+ // Add the system search path to our path.
+ std::vector<std::string> path = userPaths;
+ cmSystemTools::GetPath(path);
+ std::string tryPath;
+ for(std::vector<std::string>::const_iterator p = path.begin();
+ p != path.end(); ++p)
+ {
+ tryPath = *p;
+ tryPath += "/";
+ tryPath += name;
+ tryPath += ".lib";
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ return cmSystemTools::CollapseFullPath(tryPath.c_str());
+ }
+ tryPath = "lib";
+ tryPath += *p;
+ tryPath + ".so";
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ return cmSystemTools::CollapseFullPath(tryPath.c_str());
+ }
+ tryPath = "lib";
+ tryPath += *p;
+ tryPath + ".a";
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ return cmSystemTools::CollapseFullPath(tryPath.c_str());
+ }
+ tryPath = "lib";
+ tryPath += *p;
+ tryPath + ".sl";
+ if(cmSystemTools::FileExists(tryPath.c_str()))
+ {
+ return cmSystemTools::CollapseFullPath(tryPath.c_str());
+ }
+ }
+
+ // Couldn't find the library.
+ return "";
+}
+
bool cmSystemTools::FileIsDirectory(const char* name)
{
struct stat fs;
@@ -737,6 +792,7 @@ void cmSystemTools::SplitProgramPath(const char* in_name,
*/
std::string cmSystemTools::CollapseFullPath(const char* in_name)
{
+ std::cerr << "CollapseFullPath " << in_name << "\n";
std::string dir, file;
cmSystemTools::SplitProgramPath(in_name, dir, file);
// Ultra-hack warning:
diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h
index 3830ad3..c9838c0 100644
--- a/Source/cmSystemTools.h
+++ b/Source/cmSystemTools.h
@@ -164,11 +164,15 @@ public:
* IsON and IsOff both returning false. Note that the special path
* NOTFOUND will cause IsOff to return true.
*/
- static bool IsOff(const char* val);
+ static bool IsOff(const char* val);
+ ///! Find an executable in the system PATH, with optional extra paths.
static std::string FindProgram(const char* name,
- const std::vector<std::string>& = std::vector<std::string>());
-
+ const std::vector<std::string>& path= std::vector<std::string>());
+ ///! Find a library in the system PATH, with optional extra paths.
+ static std::string FindLibrary(const char* name,
+ const std::vector<std::string>& path);
+ ///! return true if the file is a directory.
static bool FileIsDirectory(const char* name);
static std::string GetCurrentWorkingDirectory();
static std::string GetProgramPath(const char*);
diff --git a/Source/cmUnixMakefileGenerator.cxx b/Source/cmUnixMakefileGenerator.cxx
index 14339f5..19dbd56 100644
--- a/Source/cmUnixMakefileGenerator.cxx
+++ b/Source/cmUnixMakefileGenerator.cxx
@@ -187,7 +187,7 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
{
linkLibs += "-L";
}
- linkLibs += *j;
+ linkLibs += cmSystemTools::EscapeSpaces(j->c_str());
linkLibs += " ";
}
std::string librariesLinked;
@@ -199,14 +199,31 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
if(targetLibrary && (j2->first == targetLibrary)) continue;
// don't look at debug libraries
if (j2->second == cmTarget::DEBUG) continue;
- std::string::size_type pos = j2->first.find("-l");
- if((pos == std::string::npos || pos > 0)
- && j2->first.find("${") == std::string::npos)
+ std::cerr << j2->first.c_str() << "\n";
+
+ if(j2->first.find('/') != std::string::npos)
{
+ std::string dir, file;
+ cmSystemTools::SplitProgramPath(j2->first.c_str(),
+ dir, file);
+ linkLibs += "-L";
+ linkLibs += cmSystemTools::EscapeSpaces(dir.c_str());
+ linkLibs += " ";
librariesLinked += "-l";
+ librariesLinked += file;
+ librariesLinked += " ";
+ }
+ else
+ {
+ std::string::size_type pos = j2->first.find("-l");
+ if((pos == std::string::npos || pos > 0)
+ && j2->first.find("${") == std::string::npos)
+ {
+ librariesLinked += "-l";
+ }
+ librariesLinked += j2->first;
+ librariesLinked += " ";
}
- librariesLinked += j2->first;
- librariesLinked += " ";
}
linkLibs += librariesLinked;
@@ -325,7 +342,7 @@ void cmUnixMakefileGenerator::OutputMakeFlags(std::ostream& fout)
for(i = includes.begin(); i != includes.end(); ++i)
{
std::string include = *i;
- fout << "-I" << i->c_str() << " ";
+ fout << "-I" << cmSystemTools::EscapeSpaces(i->c_str()).c_str() << " ";
}
fout << m_Makefile->GetDefineFlags();
fout << " ${LOCAL_INCLUDE_FLAGS} ";