2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2001-01-11 22:55:47 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2001-01-11 22:55:47 +03:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2001-04-25 00:49:12 +04:00
|
|
|
#include "cmSourceFile.h"
|
2000-08-29 23:26:29 +04:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
#include "cmGlobalGenerator.h"
|
2006-12-13 20:19:59 +03:00
|
|
|
#include "cmMakefile.h"
|
2007-06-18 19:59:23 +04:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmake.h"
|
2000-08-29 23:26:29 +04:00
|
|
|
|
2014-02-06 23:05:57 +04:00
|
|
|
cmSourceFile::cmSourceFile(cmMakefile* mf, const std::string& name):
|
2007-06-18 19:59:23 +04:00
|
|
|
Location(mf, name)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
this->CustomCommand = 0;
|
|
|
|
this->FindFullPathFailed = false;
|
2015-01-01 22:20:14 +03:00
|
|
|
this->IsUiFile = (".ui" ==
|
2014-02-09 06:35:52 +04:00
|
|
|
cmSystemTools::GetFilenameLastExtension(this->Location.GetName()));
|
2007-06-18 19:59:23 +04:00
|
|
|
}
|
2004-04-27 01:32:56 +04:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
cmSourceFile::~cmSourceFile()
|
|
|
|
{
|
|
|
|
this->SetCustomCommand(0);
|
|
|
|
}
|
2001-05-09 16:51:54 +04:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
std::string const& cmSourceFile::GetExtension() const
|
|
|
|
{
|
|
|
|
return this->Extension;
|
|
|
|
}
|
2004-04-27 01:32:56 +04:00
|
|
|
|
2014-03-11 08:22:02 +04:00
|
|
|
const std::string cmSourceFile::propLANGUAGE = "LANGUAGE";
|
|
|
|
|
2014-02-26 18:59:18 +04:00
|
|
|
void cmSourceFile::SetObjectLibrary(std::string const& objlib)
|
|
|
|
{
|
|
|
|
this->ObjectLibrary = objlib;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmSourceFile::GetObjectLibrary() const
|
|
|
|
{
|
|
|
|
return this->ObjectLibrary;
|
|
|
|
}
|
|
|
|
|
2014-02-04 06:20:56 +04:00
|
|
|
std::string cmSourceFile::GetLanguage()
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
2008-04-29 22:17:42 +04:00
|
|
|
// If the language was set explicitly by the user then use it.
|
2014-03-11 08:22:02 +04:00
|
|
|
if(const char* lang = this->GetProperty(propLANGUAGE))
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
2008-04-29 22:17:42 +04:00
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform computation needed to get the language if necessary.
|
|
|
|
if(this->FullPath.empty() && this->Language.empty())
|
|
|
|
{
|
2008-05-27 21:10:09 +04:00
|
|
|
// If a known extension is given or a known full path is given
|
|
|
|
// then trust that the current extension is sufficient to
|
|
|
|
// determine the language. This will fail only if the user
|
|
|
|
// specifies a full path to the source but leaves off the
|
|
|
|
// extension, which is kind of weird.
|
|
|
|
if(this->Location.ExtensionIsAmbiguous() &&
|
|
|
|
this->Location.DirectoryIsAmbiguous())
|
2008-04-29 22:17:42 +04:00
|
|
|
{
|
|
|
|
// Finalize the file location to get the extension and set the
|
|
|
|
// language.
|
|
|
|
this->GetFullPath();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the known extension to get the language if possible.
|
|
|
|
std::string ext =
|
|
|
|
cmSystemTools::GetFilenameLastExtension(this->Location.GetName());
|
|
|
|
this->CheckLanguage(ext);
|
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now try to determine the language.
|
|
|
|
return static_cast<cmSourceFile const*>(this)->GetLanguage();
|
|
|
|
}
|
2001-05-09 16:51:54 +04:00
|
|
|
|
2014-02-04 06:20:56 +04:00
|
|
|
std::string cmSourceFile::GetLanguage() const
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
|
|
|
// If the language was set explicitly by the user then use it.
|
2014-03-11 08:22:02 +04:00
|
|
|
if(const char* lang = this->GetProperty(propLANGUAGE))
|
2000-11-02 18:24:59 +03:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
return lang;
|
|
|
|
}
|
2001-12-28 23:54:05 +03:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
// If the language was determined from the source file extension use it.
|
|
|
|
if(!this->Language.empty())
|
|
|
|
{
|
2014-02-04 06:20:56 +04:00
|
|
|
return this->Language;
|
2007-06-18 19:59:23 +04:00
|
|
|
}
|
2005-11-17 21:49:10 +03:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
// The language is not known.
|
2014-02-04 06:20:56 +04:00
|
|
|
return "";
|
2007-06-18 19:59:23 +04:00
|
|
|
}
|
|
|
|
|
2007-12-17 18:12:19 +03:00
|
|
|
cmSourceFileLocation const& cmSourceFile::GetLocation() const
|
|
|
|
{
|
|
|
|
return this->Location;
|
|
|
|
}
|
|
|
|
|
2010-09-13 23:56:06 +04:00
|
|
|
std::string const& cmSourceFile::GetFullPath(std::string* error)
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
|
|
|
if(this->FullPath.empty())
|
|
|
|
{
|
2010-09-13 23:56:06 +04:00
|
|
|
if(this->FindFullPath(error))
|
2004-04-18 21:16:34 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
this->CheckExtension();
|
2004-04-18 21:16:34 +04:00
|
|
|
}
|
2000-11-02 18:24:59 +03:00
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
return this->FullPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string const& cmSourceFile::GetFullPath() const
|
|
|
|
{
|
|
|
|
return this->FullPath;
|
|
|
|
}
|
|
|
|
|
2010-09-13 23:56:06 +04:00
|
|
|
bool cmSourceFile::FindFullPath(std::string* error)
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
|
|
|
// If thie method has already failed once do not try again.
|
|
|
|
if(this->FindFullPathFailed)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the file is generated compute the location without checking on
|
|
|
|
// disk.
|
|
|
|
if(this->GetPropertyAsBool("GENERATED"))
|
2001-06-15 01:06:10 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
// The file is either already a full path or is relative to the
|
|
|
|
// build directory for the target.
|
|
|
|
this->Location.DirectoryUseBinary();
|
|
|
|
this->FullPath = this->Location.GetDirectory();
|
|
|
|
this->FullPath += "/";
|
|
|
|
this->FullPath += this->Location.GetName();
|
|
|
|
return true;
|
2001-06-15 01:06:10 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
// The file is not generated. It must exist on disk.
|
2014-01-21 20:09:14 +04:00
|
|
|
cmMakefile const* mf = this->Location.GetMakefile();
|
2007-06-18 19:59:23 +04:00
|
|
|
const char* tryDirs[3] = {0, 0, 0};
|
|
|
|
if(this->Location.DirectoryIsAmbiguous())
|
|
|
|
{
|
2015-04-16 22:17:41 +03:00
|
|
|
tryDirs[0] = mf->GetCurrentSourceDirectory();
|
2015-04-16 22:33:09 +03:00
|
|
|
tryDirs[1] = mf->GetCurrentBinaryDirectory();
|
2007-06-18 19:59:23 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tryDirs[0] = "";
|
|
|
|
}
|
2015-10-24 15:58:23 +03:00
|
|
|
const std::vector<std::string>& srcExts =
|
|
|
|
mf->GetCMakeInstance()->GetSourceExtensions();
|
|
|
|
std::vector<std::string> hdrExts =
|
|
|
|
mf->GetCMakeInstance()->GetHeaderExtensions();
|
2007-06-18 19:59:23 +04:00
|
|
|
for(const char* const* di = tryDirs; *di; ++di)
|
2001-07-16 18:14:41 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
std::string tryPath = this->Location.GetDirectory();
|
|
|
|
if(!tryPath.empty())
|
|
|
|
{
|
|
|
|
tryPath += "/";
|
|
|
|
}
|
|
|
|
tryPath += this->Location.GetName();
|
2014-10-15 16:54:05 +04:00
|
|
|
tryPath = cmSystemTools::CollapseFullPath(tryPath, *di);
|
2014-03-11 03:04:11 +04:00
|
|
|
if(this->TryFullPath(tryPath, ""))
|
2001-07-17 02:40:42 +04:00
|
|
|
{
|
2006-05-05 19:46:20 +04:00
|
|
|
return true;
|
2001-07-17 02:40:42 +04:00
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
for(std::vector<std::string>::const_iterator ei = srcExts.begin();
|
|
|
|
ei != srcExts.end(); ++ei)
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
if(this->TryFullPath(tryPath, *ei))
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(std::vector<std::string>::const_iterator ei = hdrExts.begin();
|
|
|
|
ei != hdrExts.end(); ++ei)
|
|
|
|
{
|
2014-03-11 03:04:11 +04:00
|
|
|
if(this->TryFullPath(tryPath, *ei))
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2001-07-16 18:14:41 +04:00
|
|
|
}
|
|
|
|
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2011-01-15 16:00:11 +03:00
|
|
|
std::string missing = this->Location.GetDirectory();
|
|
|
|
if(!missing.empty())
|
|
|
|
{
|
|
|
|
missing += "/";
|
|
|
|
}
|
|
|
|
missing += this->Location.GetName();
|
|
|
|
e << "Cannot find source file:\n " << missing << "\nTried extensions";
|
2007-06-18 19:59:23 +04:00
|
|
|
for(std::vector<std::string>::const_iterator ext = srcExts.begin();
|
|
|
|
ext != srcExts.end(); ++ext)
|
2001-07-16 18:14:41 +04:00
|
|
|
{
|
2006-05-05 19:46:20 +04:00
|
|
|
e << " ." << *ext;
|
2001-07-16 18:14:41 +04:00
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
for(std::vector<std::string>::const_iterator ext = hdrExts.begin();
|
|
|
|
ext != hdrExts.end(); ++ext)
|
2000-09-12 13:30:35 +04:00
|
|
|
{
|
2006-05-05 19:46:20 +04:00
|
|
|
e << " ." << *ext;
|
2000-09-12 13:30:35 +04:00
|
|
|
}
|
2010-09-13 23:56:06 +04:00
|
|
|
if(error)
|
|
|
|
{
|
|
|
|
*error = e.str();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Location.GetMakefile()->IssueMessage(cmake::FATAL_ERROR, e.str());
|
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
this->FindFullPathFailed = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-04 02:00:21 +04:00
|
|
|
bool cmSourceFile::TryFullPath(const std::string& path,
|
|
|
|
const std::string& ext)
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
2014-02-04 02:00:21 +04:00
|
|
|
std::string tryPath = path;
|
|
|
|
if(!ext.empty())
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
|
|
|
tryPath += ".";
|
|
|
|
tryPath += ext;
|
|
|
|
}
|
|
|
|
if(cmSystemTools::FileExists(tryPath.c_str()))
|
|
|
|
{
|
|
|
|
this->FullPath = tryPath;
|
|
|
|
return true;
|
|
|
|
}
|
2006-05-05 19:46:20 +04:00
|
|
|
return false;
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
void cmSourceFile::CheckExtension()
|
2001-02-27 01:15:44 +03:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
// Compute the extension.
|
|
|
|
std::string realExt =
|
|
|
|
cmSystemTools::GetFilenameLastExtension(this->FullPath);
|
|
|
|
if(!realExt.empty())
|
2002-01-21 18:11:47 +03:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
// Store the extension without the leading '.'.
|
|
|
|
this->Extension = realExt.substr(1);
|
2002-01-21 18:11:47 +03:00
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
|
|
|
|
// Look for object files.
|
|
|
|
if(this->Extension == "obj" ||
|
|
|
|
this->Extension == "o" ||
|
|
|
|
this->Extension == "lo")
|
2005-11-17 21:49:10 +03:00
|
|
|
{
|
|
|
|
this->SetProperty("EXTERNAL_OBJECT", "1");
|
|
|
|
}
|
2007-06-18 19:59:23 +04:00
|
|
|
|
|
|
|
// Try to identify the source file language from the extension.
|
2008-04-29 22:17:42 +04:00
|
|
|
if(this->Language.empty())
|
|
|
|
{
|
|
|
|
this->CheckLanguage(this->Extension);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmSourceFile::CheckLanguage(std::string const& ext)
|
|
|
|
{
|
|
|
|
// Try to identify the source file language from the extension.
|
2014-01-21 20:09:14 +04:00
|
|
|
cmMakefile const* mf = this->Location.GetMakefile();
|
2015-05-03 12:10:30 +03:00
|
|
|
cmGlobalGenerator* gg = mf->GetGlobalGenerator();
|
2014-02-04 06:20:56 +04:00
|
|
|
std::string l = gg->GetLanguageFromExtension(ext.c_str());
|
|
|
|
if(!l.empty())
|
2007-06-18 19:59:23 +04:00
|
|
|
{
|
|
|
|
this->Language = l;
|
|
|
|
}
|
2001-02-27 01:15:44 +03:00
|
|
|
}
|
2000-08-29 23:26:29 +04:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
bool cmSourceFile::Matches(cmSourceFileLocation const& loc)
|
2000-08-29 23:26:29 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
return this->Location.Matches(loc);
|
2002-08-16 19:20:18 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
void cmSourceFile::SetProperty(const std::string& prop, const char* value)
|
2002-08-16 19:20:18 +04:00
|
|
|
{
|
2015-06-06 10:41:15 +03:00
|
|
|
this->Properties.SetProperty(prop, value);
|
2013-07-25 11:24:53 +04:00
|
|
|
|
2014-02-09 06:35:52 +04:00
|
|
|
if (this->IsUiFile)
|
2013-07-25 11:24:53 +04:00
|
|
|
{
|
2014-01-21 20:09:14 +04:00
|
|
|
cmMakefile const* mf = this->Location.GetMakefile();
|
2013-09-03 00:27:32 +04:00
|
|
|
if (prop == "AUTOUIC_OPTIONS")
|
2013-07-25 11:24:53 +04:00
|
|
|
{
|
2014-01-21 20:09:14 +04:00
|
|
|
const_cast<cmMakefile*>(mf)->AddQtUiFileWithOptions(this);
|
2013-07-25 11:24:53 +04:00
|
|
|
}
|
|
|
|
}
|
2002-08-16 19:20:18 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
void cmSourceFile::AppendProperty(const std::string& prop, const char* value,
|
2011-07-14 01:14:41 +04:00
|
|
|
bool asString)
|
2008-01-18 02:13:55 +03:00
|
|
|
{
|
2015-06-06 10:41:15 +03:00
|
|
|
this->Properties.AppendProperty(prop, value, asString);
|
2008-01-18 02:13:55 +03:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
const char* cmSourceFile::GetPropertyForUser(const std::string& prop)
|
2008-01-30 19:21:54 +03:00
|
|
|
{
|
|
|
|
// This method is a consequence of design history and backwards
|
|
|
|
// compatibility. GetProperty is (and should be) a const method.
|
|
|
|
// Computed properties should not be stored back in the property map
|
|
|
|
// but instead reference information already known. If they need to
|
|
|
|
// cache information in a mutable ivar to provide the return string
|
|
|
|
// safely then so be it.
|
|
|
|
//
|
|
|
|
// The LOCATION property is particularly problematic. The CMake
|
|
|
|
// language has very loose restrictions on the names that will match
|
|
|
|
// a given source file (for historical reasons). Implementing
|
|
|
|
// lookups correctly with such loose naming requires the
|
|
|
|
// cmSourceFileLocation class to commit to a particular full path to
|
|
|
|
// the source file as late as possible. If the users requests the
|
|
|
|
// LOCATION property we must commit now.
|
2013-09-03 00:27:32 +04:00
|
|
|
if(prop == "LOCATION")
|
2008-01-30 19:21:54 +03:00
|
|
|
{
|
|
|
|
// Commit to a location.
|
|
|
|
this->GetFullPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform the normal property lookup.
|
|
|
|
return this->GetProperty(prop);
|
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
const char* cmSourceFile::GetProperty(const std::string& prop) const
|
2002-08-16 19:20:18 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
// Check for computed properties.
|
2013-09-03 00:27:32 +04:00
|
|
|
if(prop == "LOCATION")
|
2006-03-22 22:06:52 +03:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
if(this->FullPath.empty())
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this->FullPath.c_str();
|
|
|
|
}
|
2006-03-22 22:06:52 +03:00
|
|
|
}
|
|
|
|
|
2015-06-06 10:41:30 +03:00
|
|
|
const char *retVal = this->Properties.GetPropertyValue(prop);
|
|
|
|
if (!retVal)
|
2006-12-13 20:19:59 +03:00
|
|
|
{
|
2014-01-21 20:09:14 +04:00
|
|
|
cmMakefile const* mf = this->Location.GetMakefile();
|
2015-06-06 10:41:30 +03:00
|
|
|
const bool chain = mf->GetState()->
|
|
|
|
IsPropertyChained(prop, cmProperty::SOURCE_FILE);
|
|
|
|
if (chain)
|
|
|
|
{
|
|
|
|
return mf->GetProperty(prop, chain);
|
|
|
|
}
|
2006-12-13 20:19:59 +03:00
|
|
|
}
|
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
return retVal;
|
2002-08-16 19:20:18 +04:00
|
|
|
}
|
|
|
|
|
2013-09-03 00:27:32 +04:00
|
|
|
bool cmSourceFile::GetPropertyAsBool(const std::string& prop) const
|
2002-08-16 19:20:18 +04:00
|
|
|
{
|
2006-12-07 17:45:32 +03:00
|
|
|
return cmSystemTools::IsOn(this->GetProperty(prop));
|
2000-08-29 23:26:29 +04:00
|
|
|
}
|
2005-02-19 00:19:09 +03:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
cmCustomCommand* cmSourceFile::GetCustomCommand()
|
2005-04-14 00:35:26 +04:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
return this->CustomCommand;
|
2005-04-14 00:35:26 +04:00
|
|
|
}
|
2006-12-07 17:45:32 +03:00
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
cmCustomCommand const* cmSourceFile::GetCustomCommand() const
|
2006-12-07 17:45:32 +03:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
return this->CustomCommand;
|
2006-12-07 17:45:32 +03:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:59:23 +04:00
|
|
|
void cmSourceFile::SetCustomCommand(cmCustomCommand* cc)
|
2006-12-13 20:19:59 +03:00
|
|
|
{
|
2007-06-18 19:59:23 +04:00
|
|
|
cmCustomCommand* old = this->CustomCommand;
|
|
|
|
this->CustomCommand = cc;
|
|
|
|
delete old;
|
2006-12-13 20:19:59 +03:00
|
|
|
}
|