Commit ad9f0d83 authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'dev/string-apis'

b633b263 CPackWiX: Fix test to build with expected config
191f25e2 stringapi: Prevent a NULL dereference in WiX
219d6ad6 speedup: Avoid excess iterator dereferences
caaad357 speedup: Cache strings for comparisons
7abf4e31 stringapi: Use strings for dependency information
94fc63e2 stringapi: Use strings for cache iterator values
85fc9f26 stringapi: Command names
6557382d stringapi: Use strings for program paths
1a1b737c stringapi: Use strings for generator names
24b5e93d stringapi: Use strings for directories
11ed3e2c stringapi: Add string overload for the Def struct
b3bf31a5 stringapi: Miscellaneous char* parameters
5af95c39 typo: Match argument name with the header
2b17626e stringapi: Pass strings as install directories in CPack
3def29da stringapi: Use strings for feature arguments
acb116e3 stringapi: Return a string reference for the configuration
...
parents 6aad93f4 b633b263
......@@ -987,7 +987,7 @@ function(CUDA_COMPUTE_BUILD_PATH path build_path)
endif()
endif()
# This recipie is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
# This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the
# CMake source.
# Remove leading /
......
......@@ -34,12 +34,11 @@ cmWIXPatchParser::cmWIXPatchParser(
}
void cmWIXPatchParser::StartElement(const char *name, const char **atts)
void cmWIXPatchParser::StartElement(const std::string& name, const char **atts)
{
std::string name_str = name;
if(State == BEGIN_DOCUMENT)
{
if(name_str == "CPackWiXPatch")
if(name == "CPackWiXPatch")
{
State = BEGIN_FRAGMENTS;
}
......@@ -50,7 +49,7 @@ void cmWIXPatchParser::StartElement(const char *name, const char **atts)
}
else if(State == BEGIN_FRAGMENTS)
{
if(name_str == "CPackWiXFragment")
if(name == "CPackWiXFragment")
{
State = INSIDE_FRAGMENT;
StartFragment(atts);
......@@ -107,12 +106,11 @@ void cmWIXPatchParser::StartFragment(const char **attributes)
}
}
void cmWIXPatchParser::EndElement(const char *name)
void cmWIXPatchParser::EndElement(const std::string& name)
{
std::string name_str = name;
if(State == INSIDE_FRAGMENT)
{
if(name_str == "CPackWiXFragment")
if(name == "CPackWiXFragment")
{
State = BEGIN_FRAGMENTS;
ElementStack.clear();
......
......@@ -43,11 +43,11 @@ public:
cmWIXPatchParser(fragment_map_t& Fragments, cmCPackLog* logger);
private:
virtual void StartElement(const char *name, const char **atts);
virtual void StartElement(const std::string& name, const char **atts);
void StartFragment(const char **attributes);
virtual void EndElement(const char *name);
virtual void EndElement(const std::string& name);
virtual void ReportError(int line, int column, const char* msg);
void ReportValidationError(std::string const& message);
......
......@@ -16,7 +16,8 @@
#include <string>
//----------------------------------------------------------------------
unsigned long cmCPackComponent::GetInstalledSize(const char* installDir) const
unsigned long cmCPackComponent::GetInstalledSize(
const std::string& installDir) const
{
if (this->TotalSize != 0)
{
......@@ -37,7 +38,7 @@ unsigned long cmCPackComponent::GetInstalledSize(const char* installDir) const
//----------------------------------------------------------------------
unsigned long
cmCPackComponent::GetInstalledSizeInKbytes(const char* installDir) const
cmCPackComponent::GetInstalledSizeInKbytes(const std::string& installDir) const
{
unsigned long result = (GetInstalledSize(installDir) + 512) / 1024;
return result? result : 1;
......
......@@ -94,11 +94,11 @@ public:
/// Get the total installed size of all of the files in this
/// component, in bytes. installDir is the directory into which the
/// component was installed.
unsigned long GetInstalledSize(const char* installDir) const;
unsigned long GetInstalledSize(const std::string& installDir) const;
/// Identical to GetInstalledSize, but returns the result in
/// kilobytes.
unsigned long GetInstalledSizeInKbytes(const char* installDir) const;
unsigned long GetInstalledSizeInKbytes(const std::string& installDir) const;
private:
mutable unsigned long TotalSize;
......
......@@ -254,7 +254,7 @@ int cmCPackGenerator::InstallProject()
// If the project is a CMAKE project then run pre-install
// and then read the cmake_install script to run it
if ( !this->InstallProjectViaInstallCMakeProjects(
setDestDir, bareTempInstallDirectory.c_str()) )
setDestDir, bareTempInstallDirectory) )
{
return 0;
}
......@@ -269,7 +269,7 @@ int cmCPackGenerator::InstallProject()
//----------------------------------------------------------------------
int cmCPackGenerator::InstallProjectViaInstallCommands(
bool setDestDir, const char* tempInstallDirectory)
bool setDestDir, const std::string& tempInstallDirectory)
{
(void) setDestDir;
const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
......@@ -312,7 +312,7 @@ int cmCPackGenerator::InstallProjectViaInstallCommands(
//----------------------------------------------------------------------
int cmCPackGenerator::InstallProjectViaInstalledDirectories(
bool setDestDir, const char* tempInstallDirectory)
bool setDestDir, const std::string& tempInstallDirectory)
{
(void)setDestDir;
(void)tempInstallDirectory;
......@@ -349,7 +349,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
return 0;
}
std::vector<std::string>::iterator it;
const char* tempDir = tempInstallDirectory;
const std::string& tempDir = tempInstallDirectory;
for ( it = installDirectoriesVector.begin();
it != installDirectoriesVector.end();
++it )
......@@ -457,7 +457,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
//----------------------------------------------------------------------
int cmCPackGenerator::InstallProjectViaInstallScript(
bool setDestDir, const char* tempInstallDirectory)
bool setDestDir, const std::string& tempInstallDirectory)
{
const char* cmakeScripts
= this->GetOption("CPACK_INSTALL_SCRIPT");
......@@ -499,7 +499,7 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
}
else
{
this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
this->SetOption("CMAKE_INSTALL_PREFIX", tempInstallDirectory.c_str());
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"- Using non-DESTDIR install... (this->SetOption)" << std::endl);
......@@ -509,9 +509,9 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
}
this->SetOptionIfNotSet("CMAKE_CURRENT_BINARY_DIR",
tempInstallDirectory);
tempInstallDirectory.c_str());
this->SetOptionIfNotSet("CMAKE_CURRENT_SOURCE_DIR",
tempInstallDirectory);
tempInstallDirectory.c_str());
int res = this->MakefileMap->ReadListFile(0, installScript.c_str());
if ( cmSystemTools::GetErrorOccuredFlag() || !res )
{
......@@ -524,7 +524,7 @@ int cmCPackGenerator::InstallProjectViaInstallScript(
//----------------------------------------------------------------------
int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
bool setDestDir, const char* baseTempInstallDirectory)
bool setDestDir, const std::string& baseTempInstallDirectory)
{
const char* cmakeProjects
= this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
......@@ -623,7 +623,8 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
componentsVector.push_back(installComponent);
}
const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
const char* buildConfigCstr = this->GetOption("CPACK_BUILD_CONFIG");
std::string buildConfig = buildConfigCstr ? buildConfigCstr : "";
cmGlobalGenerator* globalGenerator
= this->MakefileMap->GetCMakeInstance()->CreateGlobalGenerator(
cmakeGenerator);
......@@ -822,9 +823,9 @@ int cmCPackGenerator::InstallProjectViaInstallCMakeProjects(
<< "'" << std::endl);
}
if ( buildConfig && *buildConfig )
if (!buildConfig.empty())
{
mf->AddDefinition("BUILD_TYPE", buildConfig);
mf->AddDefinition("BUILD_TYPE", buildConfig.c_str());
}
std::string installComponentLowerCase
= cmSystemTools::LowerCase(installComponent);
......@@ -972,7 +973,7 @@ bool cmCPackGenerator::ReadListFile(const char* moduleName)
}
//----------------------------------------------------------------------
void cmCPackGenerator::SetOptionIfNotSet(const char* op,
void cmCPackGenerator::SetOptionIfNotSet(const std::string& op,
const char* value)
{
const char* def = this->MakefileMap->GetDefinition(op);
......@@ -984,12 +985,8 @@ void cmCPackGenerator::SetOptionIfNotSet(const char* op,
}
//----------------------------------------------------------------------
void cmCPackGenerator::SetOption(const char* op, const char* value)
void cmCPackGenerator::SetOption(const std::string& op, const char* value)
{
if ( !op )
{
return;
}
if ( !value )
{
this->MakefileMap->RemoveDefinition(op);
......@@ -1092,7 +1089,7 @@ int cmCPackGenerator::DoPackage()
* may update this during PackageFiles.
* (either putting several names or updating the provided one)
*/
packageFileNames.push_back(tempPackageFileName);
packageFileNames.push_back(tempPackageFileName ? tempPackageFileName : "");
toplevel = tempDirectory;
if ( !this->PackageFiles() || cmSystemTools::GetErrorOccuredFlag())
{
......@@ -1142,7 +1139,7 @@ int cmCPackGenerator::DoPackage()
}
//----------------------------------------------------------------------
int cmCPackGenerator::Initialize(const char* name, cmMakefile* mf)
int cmCPackGenerator::Initialize(const std::string& name, cmMakefile* mf)
{
this->MakefileMap = mf;
this->Name = name;
......@@ -1176,19 +1173,19 @@ int cmCPackGenerator::InitializeInternal()
}
//----------------------------------------------------------------------
bool cmCPackGenerator::IsSet(const char* name) const
bool cmCPackGenerator::IsSet(const std::string& name) const
{
return this->MakefileMap->IsSet(name);
}
//----------------------------------------------------------------------
bool cmCPackGenerator::IsOn(const char* name) const
bool cmCPackGenerator::IsOn(const std::string& name) const
{
return cmSystemTools::IsOn(GetOption(name));
}
//----------------------------------------------------------------------
const char* cmCPackGenerator::GetOption(const char* op) const
const char* cmCPackGenerator::GetOption(const std::string& op) const
{
const char* ret = this->MakefileMap->GetDefinition(op);
if(!ret)
......@@ -1486,8 +1483,8 @@ bool cmCPackGenerator::WantsComponentInstallation() const
//----------------------------------------------------------------------
cmCPackInstallationType*
cmCPackGenerator::GetInstallationType(const char *projectName,
const char *name)
cmCPackGenerator::GetInstallationType(const std::string& projectName,
const std::string& name)
{
(void) projectName;
bool hasInstallationType = this->InstallationTypes.count(name) != 0;
......@@ -1518,7 +1515,8 @@ cmCPackGenerator::GetInstallationType(const char *projectName,
//----------------------------------------------------------------------
cmCPackComponent*
cmCPackGenerator::GetComponent(const char *projectName, const char *name)
cmCPackGenerator::GetComponent(const std::string& projectName,
const std::string& name)
{
bool hasComponent = this->Components.count(name) != 0;
cmCPackComponent *component = &this->Components[name];
......@@ -1586,7 +1584,7 @@ cmCPackGenerator::GetComponent(const char *projectName, const char *name)
++installTypesIt)
{
component->InstallationTypes.push_back(
this->GetInstallationType(projectName, installTypesIt->c_str()));
this->GetInstallationType(projectName, *installTypesIt));
}
}
......@@ -1613,7 +1611,8 @@ cmCPackGenerator::GetComponent(const char *projectName, const char *name)
//----------------------------------------------------------------------
cmCPackComponentGroup*
cmCPackGenerator::GetComponentGroup(const char *projectName, const char *name)
cmCPackGenerator::GetComponentGroup(const std::string& projectName,
const std::string& name)
{
(void) projectName;
std::string macroPrefix = "CPACK_COMPONENT_GROUP_"
......
......@@ -90,7 +90,7 @@ public:
/**
* Initialize generator
*/
int Initialize(const char* name, cmMakefile* mf);
int Initialize(const std::string& name, cmMakefile* mf);
/**
* Construct generator
......@@ -99,12 +99,12 @@ public:
virtual ~cmCPackGenerator();
//! Set and get the options
void SetOption(const char* op, const char* value);
void SetOptionIfNotSet(const char* op, const char* value);
const char* GetOption(const char* op) const;
void SetOption(const std::string& op, const char* value);
void SetOptionIfNotSet(const std::string& op, const char* value);
const char* GetOption(const std::string& op) const;
std::vector<std::string> GetOptions() const;
bool IsSet(const char* name) const;
bool IsOn(const char* name) const;
bool IsSet(const std::string& name) const;
bool IsOn(const std::string& name) const;
//! Set the logger
void SetLogger(cmCPackLog* log) { this->Logger = log; }
......@@ -190,13 +190,13 @@ protected:
//! Run install commands if specified
virtual int InstallProjectViaInstallCommands(
bool setDestDir, const char* tempInstallDirectory);
bool setDestDir, const std::string& tempInstallDirectory);
virtual int InstallProjectViaInstallScript(
bool setDestDir, const char* tempInstallDirectory);
bool setDestDir, const std::string& tempInstallDirectory);
virtual int InstallProjectViaInstalledDirectories(
bool setDestDir, const char* tempInstallDirectory);
bool setDestDir, const std::string& tempInstallDirectory);
virtual int InstallProjectViaInstallCMakeProjects(
bool setDestDir, const char* tempInstallDirectory);
bool setDestDir, const std::string& tempInstallDirectory);
/**
* The various level of support of
......@@ -245,12 +245,14 @@ protected:
* @return true if component installation is supported and wanted.
*/
virtual bool WantsComponentInstallation() const;
virtual cmCPackInstallationType* GetInstallationType(const char *projectName,
const char* name);
virtual cmCPackComponent* GetComponent(const char *projectName,
const char* name);
virtual cmCPackComponentGroup* GetComponentGroup(const char *projectName,
const char* name);
virtual cmCPackInstallationType* GetInstallationType(
const std::string& projectName,
const std::string& name);
virtual cmCPackComponent* GetComponent(const std::string& projectName,
const std::string& name);
virtual cmCPackComponentGroup* GetComponentGroup(
const std::string& projectName,
const std::string& name);
cmSystemTools::OutputOption GeneratorVerbose;
std::string Name;
......
......@@ -151,7 +151,8 @@ cmCPackGeneratorFactory::~cmCPackGeneratorFactory()
}
//----------------------------------------------------------------------
cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator(const char* name)
cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator(
const std::string& name)
{
cmCPackGenerator* gen = this->NewGeneratorInternal(name);
if ( !gen )
......@@ -165,12 +166,8 @@ cmCPackGenerator* cmCPackGeneratorFactory::NewGenerator(const char* name)
//----------------------------------------------------------------------
cmCPackGenerator* cmCPackGeneratorFactory::NewGeneratorInternal(
const char* name)
const std::string& name)
{
if ( !name )
{
return 0;
}
cmCPackGeneratorFactory::t_GeneratorCreatorsMap::iterator it
= this->GeneratorCreators.find(name);
if ( it == this->GeneratorCreators.end() )
......@@ -181,11 +178,11 @@ cmCPackGenerator* cmCPackGeneratorFactory::NewGeneratorInternal(
}
//----------------------------------------------------------------------
void cmCPackGeneratorFactory::RegisterGenerator(const char* name,
void cmCPackGeneratorFactory::RegisterGenerator(const std::string& name,
const char* generatorDescription,
CreateGeneratorCall* createGenerator)
{
if ( !name || !createGenerator )
if ( !createGenerator )
{
cmCPack_Log(this->Logger, cmCPackLog::LOG_ERROR,
"Cannot register generator" << std::endl);
......
......@@ -31,26 +31,26 @@ public:
~cmCPackGeneratorFactory();
//! Get the generator
cmCPackGenerator* NewGenerator(const char* name);
cmCPackGenerator* NewGenerator(const std::string& name);
void DeleteGenerator(cmCPackGenerator* gen);
typedef cmCPackGenerator* CreateGeneratorCall();
void RegisterGenerator(const char* name,
void RegisterGenerator(const std::string& name,
const char* generatorDescription,
CreateGeneratorCall* createGenerator);
void SetLogger(cmCPackLog* logger) { this->Logger = logger; }
typedef std::map<cmStdString, cmStdString> DescriptionsMap;
typedef std::map<std::string, std::string> DescriptionsMap;
const DescriptionsMap& GetGeneratorsList() const
{ return this->GeneratorDescriptions; }
private:
cmCPackGenerator* NewGeneratorInternal(const char* name);
cmCPackGenerator* NewGeneratorInternal(const std::string& name);
std::vector<cmCPackGenerator*> Generators;
typedef std::map<cmStdString, CreateGeneratorCall*> t_GeneratorCreatorsMap;
typedef std::map<std::string, CreateGeneratorCall*> t_GeneratorCreatorsMap;
t_GeneratorCreatorsMap GeneratorCreators;
DescriptionsMap GeneratorDescriptions;
cmCPackLog* Logger;
......
......@@ -227,7 +227,7 @@ int cmCPackOSXX11Generator::InitializeInternal()
//----------------------------------------------------------------------
/*
bool cmCPackOSXX11Generator::CopyCreateResourceFile(const char* name)
bool cmCPackOSXX11Generator::CopyCreateResourceFile(const std::string& name)
{
std::string uname = cmSystemTools::UpperCase(name);
std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
......@@ -271,8 +271,8 @@ bool cmCPackOSXX11Generator::CopyCreateResourceFile(const char* name)
*/
//----------------------------------------------------------------------
bool cmCPackOSXX11Generator::CopyResourcePlistFile(const char* name,
const char* dir, const char* outputFileName /* = 0 */,
bool cmCPackOSXX11Generator::CopyResourcePlistFile(const std::string& name,
const std::string& dir, const char* outputFileName /* = 0 */,
bool copyOnly /* = false */)
{
std::string inFName = "CPack.";
......@@ -288,7 +288,7 @@ bool cmCPackOSXX11Generator::CopyResourcePlistFile(const char* name,
if ( !outputFileName )
{
outputFileName = name;
outputFileName = name.c_str();
}
std::string destFileName = dir;
......
......@@ -37,8 +37,9 @@ protected:
virtual const char* GetPackagingInstallPrefix();
virtual const char* GetOutputExtension() { return ".dmg"; }
//bool CopyCreateResourceFile(const char* name, const char* dir);
bool CopyResourcePlistFile(const char* name, const char* dir,
//bool CopyCreateResourceFile(const std::string& name,
// const std::string& dir);
bool CopyResourcePlistFile(const std::string& name, const std::string& dir,
const char* outputFileName = 0, bool copyOnly = false);
std::string InstallPrefix;
};
......
......@@ -43,14 +43,14 @@ bool cmCPackPackageMakerGenerator::SupportsComponentInstallation() const
}
//----------------------------------------------------------------------
int cmCPackPackageMakerGenerator::CopyInstallScript(const char* resdir,
const char* script,
const char* name)
int cmCPackPackageMakerGenerator::CopyInstallScript(const std::string& resdir,
const std::string& script,
const std::string& name)
{
std::string dst = resdir;
dst += "/";
dst += name;
cmSystemTools::CopyFileAlways(script, dst.c_str());
cmSystemTools::CopyFileAlways(script.c_str(), dst.c_str());
cmSystemTools::SetPermissions(dst.c_str(),0777);
cmCPackLogger(cmCPackLog::LOG_VERBOSE,
"copy script : " << script << "\ninto " << dst.c_str() <<
......@@ -553,8 +553,9 @@ int cmCPackPackageMakerGenerator::InitializeInternal()
}
//----------------------------------------------------------------------
bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name,
const char* dirName)
bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(
const std::string& name,
const std::string& dirName)
{
std::string uname = cmSystemTools::UpperCase(name);
std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
......@@ -563,7 +564,7 @@ bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name,
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "CPack option: " << cpackVar.c_str()
<< " not specified. It should point to "
<< (name ? name : "(NULL)")
<< (!name.empty() ? name : "<empty>")
<< ".rtf, " << name
<< ".html, or " << name << ".txt file" << std::endl);
return false;
......@@ -571,7 +572,7 @@ bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name,
if ( !cmSystemTools::FileExists(inFileName) )
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find "
<< (name ? name : "(NULL)")
<< (!name.empty() ? name : "<empty>")
<< " resource file: " << inFileName << std::endl);
return false;
}
......@@ -600,12 +601,13 @@ bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name,
return true;
}
bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name,
const char* outName)
bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(
const std::string& name,
const char* outName)
{
if (!outName)
{
outName = name;
outName = name.c_str();
}
std::string inFName = "CPack.";
......
......@@ -38,9 +38,9 @@ public:
virtual bool SupportsComponentInstallation() const;
protected:
int CopyInstallScript(const char* resdir,
const char* script,
const char* name);
int CopyInstallScript(const std::string& resdir,
const std::string& script,
const std::string& name);
virtual int InitializeInternal();
int PackageFiles();
virtual const char* GetOutputExtension() { return ".dmg"; }
......@@ -51,8 +51,9 @@ protected:
// CPACK_RESOURCE_FILE_${NAME} (where ${NAME} is the uppercased
// version of name) specifies the input file to use for this file,
// which will be configured via ConfigureFile.
bool CopyCreateResourceFile(const char* name, const char *dirName);
bool CopyResourcePlistFile(const char* name, const char* outName = 0);
bool CopyCreateResourceFile(const std::string& name,
const std::string& dirName);
bool CopyResourcePlistFile(const std::string& name, const char* outName = 0);
// Run PackageMaker with the given command line, which will (if
// successful) produce the given package file. Returns true if
......
......@@ -68,7 +68,7 @@ int cpackUnknownArgument(const char*, void*)
//----------------------------------------------------------------------------
struct cpackDefinitions
{
typedef std::map<cmStdString, cmStdString> MapType;
typedef std::map<std::string, std::string> MapType;
MapType Map;
cmCPackLog *Log;
};
......
......@@ -225,35 +225,35 @@ private:
return true;
}
virtual void StartElement(const char* name, const char**)
virtual void StartElement(const std::string& name, const char**)
{
this->CData.clear();
if(strcmp(name, "log") == 0)
if(name == "log")
{
this->Rev = Revision();
this->Changes.clear();
}
// affected-files can contain blocks of
// modified, unknown, renamed, kind-changed, removed, conflicts, added
else if(strcmp(name, "modified") == 0
|| strcmp(name, "renamed") == 0
|| strcmp(name, "kind-changed") == 0)
else if(name == "modified"
|| name == "renamed"
|| name == "kind-changed")