ENH: Replaced LibraryOutputPath and ExecutableOutputPath variables in Makefile and VS generators to instead ask each target for its output path. This significantly reduces total code size and centralizes previously duplicate code. It is also a step towards bug#2240.
This commit is contained in:
parent
ea19994b13
commit
33ee83714d
|
@ -78,8 +78,17 @@ void cmLocalUnixMakefileGenerator3::Configure()
|
|||
//----------------------------------------------------------------------------
|
||||
void cmLocalUnixMakefileGenerator3::Generate()
|
||||
{
|
||||
// Setup our configuration variables for this directory.
|
||||
this->ConfigureOutputPaths();
|
||||
// Store the configuration name that will be generated.
|
||||
if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
|
||||
{
|
||||
// Use the build type given by the user.
|
||||
this->ConfigurationName = config;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No configuration type given.
|
||||
this->ConfigurationName = "";
|
||||
}
|
||||
|
||||
// Record whether some options are enabled to avoid checking many
|
||||
// times later.
|
||||
|
@ -181,66 +190,6 @@ void cmLocalUnixMakefileGenerator3::WriteAllProgressVariable()
|
|||
<< gg->GetNumberOfProgressActionsInAll(this) << "\n";
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmLocalUnixMakefileGenerator3::ConfigureOutputPaths()
|
||||
{
|
||||
// Format the library and executable output paths.
|
||||
if(const char* libOut =
|
||||
this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
|
||||
{
|
||||
this->LibraryOutputPath = libOut;
|
||||
this->FormatOutputPath(this->LibraryOutputPath, "LIBRARY");
|
||||
}
|
||||
if(const char* exeOut =
|
||||
this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
|
||||
{
|
||||
this->ExecutableOutputPath = exeOut;
|
||||
this->FormatOutputPath(this->ExecutableOutputPath, "EXECUTABLE");
|
||||
}
|
||||
|
||||
// Store the configuration name that will be generated.
|
||||
if(const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE"))
|
||||
{
|
||||
// Use the build type given by the user.
|
||||
this->ConfigurationName = config;
|
||||
}
|
||||
else
|
||||
{
|
||||
// No configuration type given.
|
||||
this->ConfigurationName = "";
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmLocalUnixMakefileGenerator3::FormatOutputPath(std::string& path,
|
||||
const char* name)
|
||||
{
|
||||
if(!path.empty())
|
||||
{
|
||||
// Convert the output path to a full path in case it is
|
||||
// specified as a relative path. Treat a relative path as
|
||||
// relative to the current output directory for this makefile.
|
||||
path = cmSystemTools::CollapseFullPath
|
||||
(path.c_str(), this->Makefile->GetStartOutputDirectory());
|
||||
|
||||
// Add a trailing slash for easy appending later.
|
||||
if(path.empty() || path[path.size()-1] != '/')
|
||||
{
|
||||
path += "/";
|
||||
}
|
||||
|
||||
// Make sure the output path exists on disk.
|
||||
if(!cmSystemTools::MakeDirectory(path.c_str()))
|
||||
{
|
||||
cmSystemTools::Error("Error failed to create ",
|
||||
name, "_OUTPUT_PATH directory:", path.c_str());
|
||||
}
|
||||
|
||||
// Add this as a link directory automatically.
|
||||
this->Makefile->AddLinkDirectory(path.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmLocalUnixMakefileGenerator3::WriteLocalMakefile()
|
||||
{
|
||||
|
|
|
@ -254,11 +254,6 @@ public:
|
|||
void GetTargetObjectFileDirectories(cmTarget* target,
|
||||
std::vector<std::string>& dirs);
|
||||
protected:
|
||||
// these two methods just compute reasonable values for LibraryOutputPath
|
||||
// and ExecutableOutputPath
|
||||
void ConfigureOutputPaths();
|
||||
void FormatOutputPath(std::string& path, const char* name);
|
||||
|
||||
void WriteLocalMakefile();
|
||||
|
||||
|
||||
|
@ -332,8 +327,6 @@ private:
|
|||
int MakefileVariableSize;
|
||||
std::string IncludeDirective;
|
||||
std::string MakeSilentFlag;
|
||||
std::string ExecutableOutputPath;
|
||||
std::string LibraryOutputPath;
|
||||
std::string ConfigurationName;
|
||||
std::string NativeEchoCommand;
|
||||
bool NativeEchoWindows;
|
||||
|
|
|
@ -105,35 +105,6 @@ void cmLocalVisualStudio7Generator::OutputVCProjFile()
|
|||
}
|
||||
}
|
||||
|
||||
this->LibraryOutputPath = "";
|
||||
if (this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
|
||||
{
|
||||
this->LibraryOutputPath =
|
||||
this->Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
|
||||
}
|
||||
if(this->LibraryOutputPath.size())
|
||||
{
|
||||
// make sure there is a trailing slash
|
||||
if(this->LibraryOutputPath[this->LibraryOutputPath.size()-1] != '/')
|
||||
{
|
||||
this->LibraryOutputPath += "/";
|
||||
}
|
||||
}
|
||||
this->ExecutableOutputPath = "";
|
||||
if (this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
|
||||
{
|
||||
this->ExecutableOutputPath =
|
||||
this->Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
|
||||
}
|
||||
if(this->ExecutableOutputPath.size())
|
||||
{
|
||||
// make sure there is a trailing slash
|
||||
if(this->ExecutableOutputPath[this->ExecutableOutputPath.size()-1] != '/')
|
||||
{
|
||||
this->ExecutableOutputPath += "/";
|
||||
}
|
||||
}
|
||||
|
||||
// Create the VCProj or set of VCProj's for libraries and executables
|
||||
|
||||
// clear project names
|
||||
|
@ -627,22 +598,15 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
|
|||
targetOptions.OutputPreprocessorDefinitions(fout, "\t\t\t\t", "\n");
|
||||
fout << "\t\t\t\tAssemblerListingLocation=\"" << configName << "\"\n";
|
||||
fout << "\t\t\t\tObjectFile=\"$(IntDir)\\\"\n";
|
||||
if(targetOptions.UsingDebugPDB())
|
||||
if(targetOptions.UsingDebugPDB() &&
|
||||
(target.GetType() == cmTarget::EXECUTABLE ||
|
||||
target.GetType() == cmTarget::STATIC_LIBRARY ||
|
||||
target.GetType() == cmTarget::SHARED_LIBRARY ||
|
||||
target.GetType() == cmTarget::MODULE_LIBRARY))
|
||||
{
|
||||
if(target.GetType() == cmTarget::EXECUTABLE)
|
||||
{
|
||||
fout << "\t\t\t\tProgramDataBaseFileName=\""
|
||||
<< this->ExecutableOutputPath
|
||||
<< "$(OutDir)/" << target.GetPDBName(configName) << "\"\n";
|
||||
}
|
||||
else if(target.GetType() == cmTarget::STATIC_LIBRARY ||
|
||||
target.GetType() == cmTarget::SHARED_LIBRARY ||
|
||||
target.GetType() == cmTarget::MODULE_LIBRARY)
|
||||
{
|
||||
fout << "\t\t\t\tProgramDataBaseFileName=\""
|
||||
<< this->LibraryOutputPath
|
||||
<< "$(OutDir)/" << target.GetPDBName(configName) << "\"\n";
|
||||
}
|
||||
fout << "\t\t\t\tProgramDataBaseFileName=\""
|
||||
<< target.GetOutputDir() << "/$(OutDir)/"
|
||||
<< target.GetPDBName(configName) << "\"\n";
|
||||
}
|
||||
fout << "/>\n"; // end of <Tool Name=VCCLCompilerTool
|
||||
fout << "\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n";
|
||||
|
@ -764,8 +728,9 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
|
|||
case cmTarget::STATIC_LIBRARY:
|
||||
{
|
||||
std::string targetNameFull = target.GetFullName(configName);
|
||||
std::string libpath = this->LibraryOutputPath +
|
||||
"$(OutDir)/" + targetNameFull;
|
||||
std::string libpath = target.GetOutputDir();
|
||||
libpath += "/$(OutDir)/";
|
||||
libpath += targetNameFull;
|
||||
fout << "\t\t\t<Tool\n"
|
||||
<< "\t\t\t\tName=\"VCLibrarianTool\"\n";
|
||||
if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
|
||||
|
@ -830,7 +795,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
|
|||
<< " ";
|
||||
this->OutputLibraries(fout, linkLibs);
|
||||
fout << "\"\n";
|
||||
temp = this->LibraryOutputPath;
|
||||
temp = target.GetOutputDir();
|
||||
temp += "/";
|
||||
temp += configName;
|
||||
temp += "/";
|
||||
temp += targetNameFull;
|
||||
|
@ -842,8 +808,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
|
|||
this->OutputLibraryDirectories(fout, linkDirs);
|
||||
fout << "\"\n";
|
||||
this->OutputModuleDefinitionFile(fout, target);
|
||||
temp = this->LibraryOutputPath;
|
||||
temp += "$(OutDir)/";
|
||||
temp = target.GetOutputDir();
|
||||
temp += "/$(OutDir)/";
|
||||
temp += targetNamePDB;
|
||||
fout << "\t\t\t\tProgramDataBaseFile=\"" <<
|
||||
this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
|
||||
|
@ -860,7 +826,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
|
|||
{
|
||||
fout << "\t\t\t\tStackReserveSize=\"" << stackVal << "\"\n";
|
||||
}
|
||||
temp = this->LibraryOutputPath;
|
||||
temp = target.GetOutputDir();
|
||||
temp += "/";
|
||||
temp += configName;
|
||||
temp += "/";
|
||||
temp += targetNameImport;
|
||||
|
@ -908,7 +875,8 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
|
|||
<< " ";
|
||||
this->OutputLibraries(fout, linkLibs);
|
||||
fout << "\"\n";
|
||||
temp = this->ExecutableOutputPath;
|
||||
temp = target.GetOutputDir();
|
||||
temp += "/";
|
||||
temp += configName;
|
||||
temp += "/";
|
||||
temp += targetNameFull;
|
||||
|
@ -919,8 +887,9 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
|
|||
fout << "\t\t\t\tAdditionalLibraryDirectories=\"";
|
||||
this->OutputLibraryDirectories(fout, linkDirs);
|
||||
fout << "\"\n";
|
||||
fout << "\t\t\t\tProgramDataBaseFile=\"" << this->ExecutableOutputPath
|
||||
<< "$(OutDir)\\" << targetNamePDB << "\"\n";
|
||||
fout << "\t\t\t\tProgramDataBaseFile=\""
|
||||
<< target.GetOutputDir() << "\\$(OutDir)\\" << targetNamePDB
|
||||
<< "\"\n";
|
||||
if(strcmp(configName, "Debug") == 0
|
||||
|| strcmp(configName, "RelWithDebInfo") == 0)
|
||||
{
|
||||
|
|
|
@ -125,8 +125,6 @@ private:
|
|||
virtual std::string GetTargetDirectory(cmTarget&);
|
||||
|
||||
std::vector<std::string> CreatedProjectNames;
|
||||
std::string LibraryOutputPath;
|
||||
std::string ExecutableOutputPath;
|
||||
std::string ModuleDefinitionFile;
|
||||
int Version;
|
||||
std::string PlatformName; // Win32 or x64
|
||||
|
|
|
@ -116,12 +116,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
|||
this->LocalGenerator->ConfigurationName.c_str());
|
||||
|
||||
// Construct the full path version of the names.
|
||||
std::string outpath = this->LocalGenerator->ExecutableOutputPath;
|
||||
if(outpath.length() == 0)
|
||||
{
|
||||
outpath = this->Makefile->GetStartOutputDirectory();
|
||||
outpath += "/";
|
||||
}
|
||||
std::string outpath = this->Target->GetOutputDir();
|
||||
outpath += "/";
|
||||
#ifdef __APPLE__
|
||||
if(this->Target->GetPropertyAsBool("MACOSX_BUNDLE"))
|
||||
{
|
||||
|
|
|
@ -245,12 +245,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
|||
this->LocalGenerator->ConfigurationName.c_str());
|
||||
|
||||
// Construct the full path version of the names.
|
||||
std::string outpath = this->LocalGenerator->LibraryOutputPath;
|
||||
if(outpath.length() == 0)
|
||||
{
|
||||
outpath = this->Makefile->GetStartOutputDirectory();
|
||||
outpath += "/";
|
||||
}
|
||||
std::string outpath;
|
||||
if(relink)
|
||||
{
|
||||
outpath = this->Makefile->GetStartOutputDirectory();
|
||||
|
@ -259,6 +254,11 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
|||
cmSystemTools::MakeDirectory(outpath.c_str());
|
||||
outpath += "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
outpath = this->Target->GetOutputDir();
|
||||
outpath += "/";
|
||||
}
|
||||
std::string targetFullPath = outpath + targetName;
|
||||
std::string targetFullPathPDB = outpath + targetNamePDB;
|
||||
std::string targetFullPathSO = outpath + targetNameSO;
|
||||
|
|
|
@ -466,16 +466,13 @@ cmMakefileTargetGenerator
|
|||
{
|
||||
std::string targetFullPathPDB;
|
||||
const char* configName = this->LocalGenerator->ConfigurationName.c_str();
|
||||
if(this->Target->GetType() == cmTarget::EXECUTABLE)
|
||||
if(this->Target->GetType() == cmTarget::EXECUTABLE ||
|
||||
this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
|
||||
this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
|
||||
this->Target->GetType() == cmTarget::MODULE_LIBRARY)
|
||||
{
|
||||
targetFullPathPDB = this->LocalGenerator->ExecutableOutputPath;
|
||||
targetFullPathPDB += this->Target->GetPDBName(configName);
|
||||
}
|
||||
else if(this->Target->GetType() == cmTarget::STATIC_LIBRARY ||
|
||||
this->Target->GetType() == cmTarget::SHARED_LIBRARY ||
|
||||
this->Target->GetType() == cmTarget::MODULE_LIBRARY)
|
||||
{
|
||||
targetFullPathPDB = this->LocalGenerator->LibraryOutputPath;
|
||||
targetFullPathPDB = this->Target->GetOutputDir();
|
||||
targetFullPathPDB += "/";
|
||||
targetFullPathPDB += this->Target->GetPDBName(configName);
|
||||
}
|
||||
targetOutPathPDB =
|
||||
|
|
|
@ -1093,34 +1093,7 @@ void cmTarget::SetProperty(const char* prop, const char* value)
|
|||
|
||||
const char* cmTarget::GetDirectory(const char* config)
|
||||
{
|
||||
switch( this->GetType() )
|
||||
{
|
||||
case cmTarget::STATIC_LIBRARY:
|
||||
case cmTarget::MODULE_LIBRARY:
|
||||
case cmTarget::SHARED_LIBRARY:
|
||||
this->Directory =
|
||||
this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
|
||||
break;
|
||||
case cmTarget::EXECUTABLE:
|
||||
this->Directory =
|
||||
this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
|
||||
break;
|
||||
default:
|
||||
this->Directory = this->Makefile->GetStartOutputDirectory();
|
||||
break;
|
||||
}
|
||||
if(this->Directory.empty())
|
||||
{
|
||||
this->Directory = this->Makefile->GetStartOutputDirectory();
|
||||
}
|
||||
// if LIBRARY_OUTPUT_PATH or EXECUTABLE_OUTPUT_PATH was relative
|
||||
// then make them full paths because this directory MUST
|
||||
// be a full path or things will not work!!!
|
||||
if(!cmSystemTools::FileIsFullPath(this->Directory.c_str()))
|
||||
{
|
||||
this->Directory = this->Makefile->GetCurrentOutputDirectory() +
|
||||
std::string("/") + this->Directory;
|
||||
}
|
||||
this->Directory = this->GetOutputDir();
|
||||
if(config)
|
||||
{
|
||||
// Add the configuration's subdirectory.
|
||||
|
@ -1956,3 +1929,50 @@ std::string cmTarget::GetInstallNameDirForInstallTree(const char*)
|
|||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const char* cmTarget::GetOutputDir()
|
||||
{
|
||||
if(this->OutputDir.empty())
|
||||
{
|
||||
// Lookup the output path for this target type.
|
||||
switch(this->GetType())
|
||||
{
|
||||
case cmTarget::STATIC_LIBRARY:
|
||||
case cmTarget::MODULE_LIBRARY:
|
||||
case cmTarget::SHARED_LIBRARY:
|
||||
this->OutputDir =
|
||||
this->Makefile->GetSafeDefinition("LIBRARY_OUTPUT_PATH");
|
||||
break;
|
||||
case cmTarget::EXECUTABLE:
|
||||
this->OutputDir =
|
||||
this->Makefile->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
|
||||
break;
|
||||
}
|
||||
if(this->OutputDir.empty())
|
||||
{
|
||||
this->OutputDir = ".";
|
||||
}
|
||||
|
||||
// Convert the output path to a full path in case it is
|
||||
// specified as a relative path. Treat a relative path as
|
||||
// relative to the current output directory for this makefile.
|
||||
this->OutputDir =
|
||||
cmSystemTools::CollapseFullPath
|
||||
(this->OutputDir.c_str(), this->Makefile->GetStartOutputDirectory());
|
||||
|
||||
// Make sure the output path exists on disk.
|
||||
if(!cmSystemTools::MakeDirectory(this->OutputDir.c_str()))
|
||||
{
|
||||
cmSystemTools::Error("Error failed to create output directory:",
|
||||
this->OutputDir.c_str());
|
||||
}
|
||||
|
||||
// TODO: This came from cmLocalUnixMakefileGenerator3::FormatOutputPath.
|
||||
// Where should it go. Is it still needed?
|
||||
// Add this as a link directory automatically.
|
||||
// this->Makefile->AddLinkDirectory(path.c_str());
|
||||
}
|
||||
|
||||
return this->OutputDir.c_str();
|
||||
}
|
||||
|
|
|
@ -213,6 +213,9 @@ public:
|
|||
makefile and the configuration type. */
|
||||
std::string GetFullPath(const char* config=0, bool implib = false);
|
||||
|
||||
/** Get the full path to the target output directory. */
|
||||
const char* GetOutputDir();
|
||||
|
||||
/** Get the names of the library needed to generate a build rule
|
||||
that takes into account shared library version numbers. This
|
||||
should be called only on a library target. */
|
||||
|
@ -357,6 +360,7 @@ private:
|
|||
bool HaveInstallRule;
|
||||
std::string InstallPath;
|
||||
std::string RuntimeInstallPath;
|
||||
std::string OutputDir;
|
||||
std::string Directory;
|
||||
std::string Location;
|
||||
std::set<cmStdString> Utilities;
|
||||
|
|
Loading…
Reference in New Issue