ENH: Support for packaging source, several cleanups and more yeehaa...

This commit is contained in:
Andy Cedilnik 2006-04-15 13:02:18 -04:00
parent 1df8e12c42
commit c09c3c6bfa
13 changed files with 150 additions and 53 deletions

View File

@ -3,6 +3,10 @@ SET(cpack_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
IF(EXISTS "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
SET(cpack_input_file "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/CPackConfig.cmake.in")
SET(cpack_source_input_file "${CMAKE_ROOT}/Templates/CPackConfig.cmake.in")
IF(EXISTS "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
SET(cpack_source_input_file "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
ENDIF(EXISTS "${CMAKE_SOURCE_DIR}/CPackSourceConfig.cmake.in")
# Macro for setting values if a user did not overwrite them
MACRO(cpack_set_if_not_set name value)
@ -11,6 +15,19 @@ MACRO(cpack_set_if_not_set name value)
ENDIF(NOT DEFINED "${name}")
ENDMACRO(cpack_set_if_not_set)
# Macro to encode variables for the configuration file
MACRO(cpack_encode_variables)
SET(_CPACK_OTHER_VARIABLES_)
GET_CMAKE_PROPERTY(res VARIABLES)
FOREACH(var ${res})
IF("xxx${var}" MATCHES "xxxCPACK")
SET(_CPACK_OTHER_VARIABLES_
"${_CPACK_OTHER_VARIABLES_}\nSET(${var} \"${${var}}\")")
ENDIF("xxx${var}" MATCHES "xxxCPACK")
ENDFOREACH(var ${res})
ENDMACRO(cpack_encode_variables)
# Set the package name
cpack_set_if_not_set(CPACK_PACKAGE_NAME "${CMAKE_PROJECT_NAME}")
cpack_set_if_not_set(CPACK_PACKAGE_VERSION_MAJOR "0")
@ -61,24 +78,38 @@ IF(NOT CPACK_GENERATOR)
ELSE(APPLE)
SET(CPACK_GENERATOR "STGZ")
ENDIF(APPLE)
SET(CPACK_SOURCE_GENERATOR "TGZ")
ELSE(UNIX)
SET(CPACK_GENERATOR "NSIS")
SET(CPACK_SOURCE_GENERATOR "ZIP")
ENDIF(UNIX)
ENDIF(NOT CPACK_GENERATOR)
# Set some other variables
cpack_set_if_not_set(CPACK_BINARY_DIR "${CMAKE_BINARY_DIR}")
cpack_set_if_not_set(CPACK_INSTALL_CMAKE_PROJECTS
"${CMAKE_BINARY_DIR};${CMAKE_PROJECT_NAME};ALL;/")
cpack_set_if_not_set(CPACK_CMAKE_GENERATOR "${CMAKE_GENERATOR}")
cpack_set_if_not_set(CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}")
SET(_CPACK_UNUSED_VARIABLES_)
GET_CMAKE_PROPERTY(res VARIABLES)
FOREACH(var ${res})
IF("xxx${var}" MATCHES "xxxCPACK")
SET(_CPACK_OTHER_VARIABLES_
"${_CPACK_OTHER_VARIABLES_}\nSET(${var} \"${${var}}\")")
ENDIF("xxx${var}" MATCHES "xxxCPACK")
ENDFOREACH(var ${res})
cpack_encode_variables()
CONFIGURE_FILE("${cpack_input_file}"
"${CMAKE_BINARY_DIR}/CPackConfig.cmake" @ONLY IMMEDIATE)
CONFIGURE_FILE("${cpack_input_file}" "${CMAKE_BINARY_DIR}/CPackConfig.cmake" @ONLY IMMEDIATE)
# Generate source file
cpack_set_if_not_set(CPACK_SOURCE_INSTALLED_DIRECTORIES
"${CMAKE_SOURCE_DIR};/")
cpack_set_if_not_set(CPACK_SOURCE_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-Source")
cpack_set_if_not_set(CPACK_SOURCE_PACKAGE_FILE_NAME
"${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}-Source")
cpack_set_if_not_set(CPACK_SOURCE_IGNORE_FILES
"/CVS/;/\\\\\\\\.svn/;\\\\\\\\.swp$;\\\\\\\\.#")
SET(CPACK_INSTALL_CMAKE_PROJECTS "${CPACK_SOURCE_INSTALL_CMAKE_PROJECTS}")
SET(CPACK_INSTALLED_DIRECTORIES "${CPACK_SOURCE_INSTALLED_DIRECTORIES}")
SET(CPACK_GENERATOR "${CPACK_SOURCE_GENERATOR}")
SET(CPACK_TOPLEVEL_TAG "${CPACK_SOURCE_TOPLEVEL_TAG}")
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_SOURCE_PACKAGE_FILE_NAME}")
SET(CPACK_IGNORE_FILES "${CPACK_SOURCE_IGNORE_FILES}")
cpack_encode_variables()
CONFIGURE_FILE("${cpack_source_input_file}"
"${CMAKE_BINARY_DIR}/CPackSourceConfig.cmake" @ONLY IMMEDIATE)

View File

@ -48,6 +48,12 @@ int cmCPackGenericGenerator::PrepareNames()
this->SetOption("CPACK_GENERATOR", this->Name.c_str());
std::string tempDirectory = this->GetOption("CPACK_PACKAGE_DIRECTORY");
tempDirectory += "/_CPack_Packages/";
const char* toplevelTag = this->GetOption("CPACK_TOPLEVEL_TAG");
if ( toplevelTag )
{
tempDirectory += toplevelTag;
tempDirectory += "/";
}
tempDirectory += this->GetOption("CPACK_GENERATOR");
std::string topDirectory = tempDirectory;
@ -120,6 +126,22 @@ int cmCPackGenericGenerator::PrepareNames()
int cmCPackGenericGenerator::InstallProject()
{
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Install projects" << std::endl);
std::vector<cmsys::RegularExpression> ignoreFilesRegex;
const char* cpackIgnoreFiles = this->GetOption("CPACK_IGNORE_FILES");
if ( cpackIgnoreFiles )
{
std::vector<std::string> ignoreFilesRegexString;
cmSystemTools::ExpandListArgument(cpackIgnoreFiles,ignoreFilesRegexString);
std::vector<std::string>::iterator it;
for ( it = ignoreFilesRegexString.begin();
it != ignoreFilesRegexString.end();
++it )
{
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"Create ignore files regex for: " << it->c_str() << std::endl);
ignoreFilesRegex.push_back(it->c_str());
}
}
const char* tempInstallDirectory
= this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
int res = 1;
@ -143,7 +165,7 @@ int cmCPackGenericGenerator::InstallProject()
cmSystemTools::PutEnv(destDir.c_str());
}
const char* installCommands = this->GetOption("CPACK_INSTALL_COMMANDS");
if ( installCommands )
if ( installCommands && *installCommands )
{
std::vector<std::string> installCommandsVector;
cmSystemTools::ExpandListArgument(installCommands,installCommandsVector);
@ -177,7 +199,7 @@ int cmCPackGenericGenerator::InstallProject()
}
const char* installDirectories
= this->GetOption("CPACK_INSTALLED_DIRECTORIES");
if ( installDirectories )
if ( installDirectories && *installDirectories )
{
std::vector<std::string> installDirectoriesVector;
cmSystemTools::ExpandListArgument(installDirectories,
@ -203,6 +225,8 @@ int cmCPackGenericGenerator::InstallProject()
std::string subdir = it->c_str();
std::string findExpr = toplevel;
findExpr += "/*";
cmCPackLogger(cmCPackLog::LOG_OUTPUT,
"- Install directory: " << toplevel << std::endl);
gl.RecurseOn();
if ( !gl.FindFiles(findExpr) )
{
@ -212,12 +236,29 @@ int cmCPackGenericGenerator::InstallProject()
}
std::vector<std::string>& files = gl.GetFiles();
std::vector<std::string>::iterator gfit;
std::vector<cmsys::RegularExpression>::iterator regIt;
for ( gfit = files.begin(); gfit != files.end(); ++ gfit )
{
bool skip = false;
std::string &inFile = *gfit;
for ( regIt= ignoreFilesRegex.begin();
regIt!= ignoreFilesRegex.end();
++ regIt)
{
if ( regIt->find(inFile.c_str()) )
{
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Ignore file: "
<< inFile.c_str() << std::endl);
skip = true;
}
}
if ( skip )
{
continue;
}
std::string filePath = tempDir;
filePath += "/" + subdir + "/"
+ cmSystemTools::RelativePath(toplevel.c_str(), gfit->c_str());
std::string &inFile = *gfit;
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Copy file: "
<< inFile.c_str() << " -> " << filePath.c_str() << std::endl);
if ( !cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
@ -234,7 +275,7 @@ int cmCPackGenericGenerator::InstallProject()
= this->GetOption("CPACK_INSTALL_CMAKE_PROJECTS");
const char* cmakeGenerator
= this->GetOption("CPACK_CMAKE_GENERATOR");
if ( cmakeProjects )
if ( cmakeProjects && *cmakeProjects )
{
if ( !cmakeGenerator )
{
@ -324,6 +365,11 @@ int cmCPackGenericGenerator::InstallProject()
std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
lg->SetGlobalGenerator(&gg);
cmMakefile *mf = lg->GetMakefile();
std::string realInstallDirectory = tempInstallDirectory;
if ( !installSubDirectory.empty() && installSubDirectory != "/" )
{
realInstallDirectory += installSubDirectory;
}
if ( movable )
{
mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
@ -332,6 +378,12 @@ int cmCPackGenericGenerator::InstallProject()
{
mf->AddDefinition("BUILD_TYPE", buildConfig);
}
std::string installComponentLowerCase
= cmSystemTools::LowerCase(installComponent);
if ( installComponentLowerCase != "all" )
{
mf->AddDefinition("CMAKE_INSTALL_COMPONENT", installComponent.c_str());
}
res = mf->ReadListFile(0, installFile.c_str());
if ( cmSystemTools::GetErrorOccuredFlag() )
@ -383,6 +435,17 @@ int cmCPackGenericGenerator::InstallProject()
return res;
}
//----------------------------------------------------------------------
void cmCPackGenericGenerator::SetOptionIfNotSet(const char* op,
const char* value)
{
if ( this->MakefileMap->GetDefinition(op) )
{
return;
}
this->SetOption(op, value);
}
//----------------------------------------------------------------------
void cmCPackGenericGenerator::SetOption(const char* op, const char* value)
{
@ -473,6 +536,12 @@ int cmCPackGenericGenerator::Initialize(const char* name, cmMakefile* mf)
{
this->MakefileMap = mf;
this->Name = name;
return this->InitializeInternal();
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::InitializeInternal()
{
return 1;
}

View File

@ -68,7 +68,7 @@ public:
/**
* Initialize generator
*/
virtual int Initialize(const char* name, cmMakefile* mf);
int Initialize(const char* name, cmMakefile* mf);
/**
* Construct generator
@ -78,6 +78,7 @@ public:
//! 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);
//! Set all the variables
@ -99,6 +100,7 @@ protected:
virtual std::string FindTemplate(const char* name);
virtual bool ConfigureFile(const char* inName, const char* outName);
virtual int InitializeInternal();
bool GeneratorVerbose;
std::string Name;

View File

@ -115,17 +115,14 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName,
}
//----------------------------------------------------------------------
int cmCPackNSISGenerator::Initialize(const char* name, cmMakefile* mf)
int cmCPackNSISGenerator::InitializeInternal()
{
int res = this->Superclass::Initialize(name, mf);
if ( !res )
{
return res;
}
if ( cmSystemTools::IsOn(this->GetOption(
"CPACK_INCLUDE_TOPLEVEL_DIRECTORY")) )
{
cmCPackLogger(cmCPackLog::LOG_ERROR, "NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY. This option will be ignored."
cmCPackLogger(cmCPackLog::LOG_ERROR,
"NSIS Generator cannot work with CPACK_INCLUDE_TOPLEVEL_DIRECTORY. "
"This option will be ignored."
<< std::endl);
this->SetOption("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", 0);
}
@ -222,7 +219,7 @@ int cmCPackNSISGenerator::Initialize(const char* name, cmMakefile* mf)
this->SetOption("CPACK_NSIS_DELETE_ICONS", deleteStr.str().c_str());
}
return res;
return this->Superclass::InitializeInternal();
}
//----------------------------------------------------------------------

View File

@ -31,11 +31,6 @@ class cmCPackNSISGenerator : public cmCPackGenericGenerator
public:
cmCPackTypeMacro(cmCPackNSISGenerator, cmCPackGenericGenerator);
/**
* Initialize generator
*/
virtual int Initialize(const char* name, cmMakefile* mf);
/**
* Construct generator
*/
@ -43,6 +38,7 @@ public:
virtual ~cmCPackNSISGenerator();
protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "exe"; }

View File

@ -137,13 +137,8 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName,
}
//----------------------------------------------------------------------
int cmCPackPackageMakerGenerator::Initialize(const char* name, cmMakefile* mf)
int cmCPackPackageMakerGenerator::InitializeInternal()
{
int res = this->Superclass::Initialize(name, mf);
if ( !res )
{
return res;
}
cmCPackLogger(cmCPackLog::LOG_DEBUG,
"cmCPackPackageMakerGenerator::Initialize()" << std::endl);
std::vector<std::string> path;
@ -228,7 +223,7 @@ int cmCPackPackageMakerGenerator::Initialize(const char* name, cmMakefile* mf)
}
this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
return res;
return this->Superclass::InitializeInternal();
}
//----------------------------------------------------------------------

View File

@ -32,11 +32,6 @@ class cmCPackPackageMakerGenerator : public cmCPackGenericGenerator
public:
cmCPackTypeMacro(cmCPackPackageMakerGenerator, cmCPackGenericGenerator);
/**
* Initialize generator
*/
virtual int Initialize(const char* name, cmMakefile* mf);
/**
* Construct generator
*/
@ -44,6 +39,7 @@ public:
virtual ~cmCPackPackageMakerGenerator();
protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "dmg"; }

View File

@ -35,6 +35,13 @@ cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
{
}
//----------------------------------------------------------------------
int cmCPackSTGZGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "0");
return this->Superclass::InitializeInternal();
}
//----------------------------------------------------------------------
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
{

View File

@ -37,6 +37,7 @@ public:
virtual ~cmCPackSTGZGenerator();
protected:
virtual int InitializeInternal();
int GenerateHeader(std::ostream* os);
virtual const char* GetOutputExtension() { return "sh"; }
};

View File

@ -178,6 +178,13 @@ int cmCPackTGZ_Data_Close(void *client_data)
return (0);
}
//----------------------------------------------------------------------
int cmCPackTGZGenerator::InitializeInternal()
{
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
return this->Superclass::InitializeInternal();
}
//----------------------------------------------------------------------
int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
const char* toplevel, const std::vector<std::string>& files)

View File

@ -40,6 +40,7 @@ public:
virtual ~cmCPackTGZGenerator();
protected:
virtual int InitializeInternal();
virtual int GenerateHeader(std::ostream* os);
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);

View File

@ -38,13 +38,9 @@ cmCPackZIPGenerator::~cmCPackZIPGenerator()
}
//----------------------------------------------------------------------
int cmCPackZIPGenerator::Initialize(const char* name, cmMakefile* mf)
int cmCPackZIPGenerator::InitializeInternal()
{
int res = this->Superclass::Initialize(name, mf);
if ( !res )
{
return res;
}
this->SetOptionIfNotSet("CPACK_INCLUDE_TOPLEVEL_DIRECTORY", "1");
std::vector<std::string> path;
std::string pkgPath = "c:/Program Files/WinZip";
path.push_back(pkgPath);
@ -68,7 +64,8 @@ int cmCPackZIPGenerator::Initialize(const char* name, cmMakefile* mf)
pkgPath = cmSystemTools::FindProgram("zip", path, false);
if ( pkgPath.empty() )
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP" << std::endl);
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Cannot find unix ZIP"
<< std::endl);
}
else
{
@ -83,9 +80,10 @@ int cmCPackZIPGenerator::Initialize(const char* name, cmMakefile* mf)
return 0;
}
this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: " << pkgPath.c_str()
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Found ZIP program: "
<< pkgPath.c_str()
<< std::endl);
return 1;
return this->Superclass::InitializeInternal();
}
//----------------------------------------------------------------------

View File

@ -31,10 +31,6 @@ public:
friend class cmCPackZIPGeneratorForward;
cmCPackTypeMacro(cmCPackZIPGenerator, cmCPackGenericGenerator);
/**
* Initialize generator
*/
virtual int Initialize(const char* name, cmMakefile* mf);
/**
* Construct generator
*/
@ -49,6 +45,7 @@ public:
};
protected:
virtual int InitializeInternal();
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "zip"; }