ENH: Merge from the cpack branch

This commit is contained in:
Andy Cedilnik 2006-01-01 23:21:05 -05:00
parent 74680f1bf4
commit d0329919da
14 changed files with 5728 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#cmakedefine HAVE_WCHAR_H @HAVE_WCHAR_H@
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@
#cmakedefine HAVE_IO_H @HAVE_IO_H@
#cmakedefine HAVE_SIZEOF_SSIZE_T @HAVE_SIZEOF_SSIZE_T@
#if !defined(HAVE_SIZEOF_SSIZE_T)
# define ssize_t @ssize_t@
#endif
#cmakedefine HAVE_SIZEOF_INT64_T @HAVE_SIZEOF_INT64_T@
#if !defined(HAVE_SIZEOF_INT64_T)
# define int64_t @int64_t@
# define uint64_t unsigned @int64_t@
#endif
#cmakedefine HAVE_SIZEOF_UID_T @HAVE_SIZEOF_UID_T@
#if !defined(HAVE_SIZEOF_UID_T)
# define uid_t @uid_t@
#endif
#cmakedefine HAVE_SIZEOF_GID_T @HAVE_SIZEOF_GID_T@
#if !defined(HAVE_SIZEOF_GID_T)
# define gid_t @gid_t@
#endif
#cmakedefine HAVE_SIZEOF_INTMAX_T @HAVE_SIZEOF_INTMAX_T@
#if !defined(HAVE_SIZEOF_INTMAX_T)
# define intmax_t @intmax_t@
#endif
#cmakedefine HAVE_SIZEOF_UINTMAX_T @HAVE_SIZEOF_UINTMAX_T@
#if !defined(HAVE_SIZEOF_UINTMAX_T)
# define uintmax_t @uintmax_t@
#endif
#cmakedefine HAVE_GETEUID @HAVE_GETEUID@
#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@

View File

@ -0,0 +1,106 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCPackGenerators.h"
#include "cmCPackGenericGenerator.h"
#include "cmCPackTGZGenerator.h"
#include "cmCPackSTGZGenerator.h"
#include "cmCPackNSISGenerator.h"
#include "cmCPackPackageMakerGenerator.h"
//----------------------------------------------------------------------
cmCPackGenerators::cmCPackGenerators()
{
this->RegisterGenerator("TGZ", cmCPackTGZGenerator::CreateGenerator);
this->RegisterGenerator("STGZ", cmCPackSTGZGenerator::CreateGenerator);
this->RegisterGenerator("NSIS", cmCPackNSISGenerator::CreateGenerator);
this->RegisterGenerator("PackageMaker", cmCPackPackageMakerGenerator::CreateGenerator);
}
//----------------------------------------------------------------------
cmCPackGenerators::~cmCPackGenerators()
{
std::vector<cmCPackGenericGenerator*>::iterator it;
for ( it = m_Generators.begin(); it != m_Generators.end(); ++ it )
{
delete *it;
}
}
//----------------------------------------------------------------------
cmCPackGenericGenerator* cmCPackGenerators::NewGenerator(const char* name)
{
cmCPackGenericGenerator* gen = this->NewGeneratorInternal(name);
if ( !gen )
{
return 0;
}
if ( !gen->Initialize(name) )
{
delete gen;
return 0;
}
m_Generators.push_back(gen);
return gen;
}
//----------------------------------------------------------------------
cmCPackGenericGenerator* cmCPackGenerators::NewGeneratorInternal(const char* name)
{
if ( !name )
{
return 0;
}
cmCPackGenerators::t_GeneratorCreatorsMap::iterator it = m_GeneratorCreators.find(name);
if ( it == m_GeneratorCreators.end() )
{
return 0;
}
return (it->second)();
/*
std::string sname = name;
if ( sname == "STGZ" )
{
return new cmCPackSTGZGenerator;
}
if ( sname == "TGZ" )
{
return new cmCPackTGZGenerator;
}
if ( sname == "NSIS" )
{
return new cmCPackNSISGenerator;
}
if ( sname == "PackageMaker" )
{
return new cmCPackPackageMakerGenerator;
}
return new cmCPackGenericGenerator;
*/
}
//----------------------------------------------------------------------
void cmCPackGenerators::RegisterGenerator(const char* name, CreateGeneratorCall* createGenerator)
{
if ( !name || !createGenerator )
{
std::cerr << "Cannot register generator" << std::endl;
return;
}
m_GeneratorCreators[name] = createGenerator;
}

View File

@ -0,0 +1,56 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmCPackGenerators_h
#define cmCPackGenerators_h
#include "cmObject.h"
class cmCPackGenericGenerator;
/** \class cmCPackGenerators
* \brief A container for CPack generators
*
*/
class cmCPackGenerators : public cmObject
{
public:
cmTypeMacro(cmCPackGenerators, cmObject);
cmCPackGenerators();
~cmCPackGenerators();
//! Get the generator
cmCPackGenericGenerator* NewGenerator(const char* name);
void DeleteGenerator(cmCPackGenericGenerator* gen);
typedef cmCPackGenericGenerator* CreateGeneratorCall();
void RegisterGenerator(const char* name, CreateGeneratorCall* createGenerator);
private:
cmCPackGenericGenerator* NewGeneratorInternal(const char* name);
std::vector<cmCPackGenericGenerator*> m_Generators;
typedef std::map<cmStdString, CreateGeneratorCall*> t_GeneratorCreatorsMap;
t_GeneratorCreatorsMap m_GeneratorCreators;
};
#endif

View File

@ -0,0 +1,475 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCPackGenericGenerator.h"
#include "cmake.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include <cmsys/SystemTools.hxx>
#include <cmsys/Glob.hxx>
#include <memory> // auto_ptr
//----------------------------------------------------------------------
cmCPackGenericGenerator::cmCPackGenericGenerator()
{
m_GeneratorVerbose = false;
m_GlobalGenerator = 0;
m_LocalGenerator = 0;
m_MakefileMap = 0;
m_CMakeInstance = 0;
}
//----------------------------------------------------------------------
cmCPackGenericGenerator::~cmCPackGenericGenerator()
{
if ( m_GlobalGenerator )
{
delete m_GlobalGenerator;
m_GlobalGenerator = 0;
}
if ( m_LocalGenerator )
{
delete m_LocalGenerator;
m_LocalGenerator = 0;
}
if ( m_CMakeInstance )
{
delete m_CMakeInstance;
m_CMakeInstance = 0;
}
m_MakefileMap = 0;
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::PrepareNames()
{
std::string tempDirectory = this->GetOption("CPACK_PROJECT_DIRECTORY");
tempDirectory += "/_CPack_Packages/";
tempDirectory += this->GetOption("CPACK_GENERATOR");
std::string topDirectory = tempDirectory;
std::string outName = this->GetOption("CPACK_PROJECT_NAME");
outName += "-";
outName += this->GetOption("CPACK_PROJECT_VERSION");
const char* patch = this->GetOption("CPACK_PROJECT_VERSION_PATCH");
if ( patch && *patch )
{
outName += "-";
outName += patch;
}
const char* postfix = this->GetOutputPostfix();
if ( postfix && *postfix )
{
outName += "-";
outName += postfix;
}
tempDirectory += "/" + outName;
outName += ".";
outName += this->GetOutputExtension();
std::string installFile = this->GetOption("CPACK_PROJECT_DIRECTORY");
installFile += "/cmake_install.cmake";
std::string destFile = this->GetOption("CPACK_PROJECT_DIRECTORY");
destFile += "/" + outName;
std::string outFile = topDirectory + "/" + outName;
std::string installPrefix = tempDirectory + this->GetInstallPrefix();
this->SetOption("CPACK_TOPLEVEL_DIRECTORY", topDirectory.c_str());
this->SetOption("CPACK_TEMPORARY_DIRECTORY", tempDirectory.c_str());
this->SetOption("CPACK_INSTALL_FILE_NAME", installFile.c_str());
this->SetOption("CPACK_OUTPUT_FILE_NAME", outName.c_str());
this->SetOption("CPACK_PACKAGE_FILE_NAME", destFile.c_str());
this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", outFile.c_str());
this->SetOption("CPACK_INSTALL_DIRECTORY", this->GetInstallPath());
this->SetOption("CPACK_NATIVE_INSTALL_DIRECTORY",
cmsys::SystemTools::ConvertToOutputPath(this->GetInstallPath()).c_str());
this->SetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY", installPrefix.c_str());
std::cout << "Look for: CPACK_PROJECT_DESCRIPTION_FILE_NAME" << std::endl;
const char* descFileName = this->GetOption("CPACK_PROJECT_DESCRIPTION_FILE_NAME");
std::cout << "Look for: " << descFileName << std::endl;
if ( descFileName )
{
if ( !cmSystemTools::FileExists(descFileName) )
{
std::cout << "Cannot find description file name: " << descFileName << std::endl;
return 0;
}
std::ifstream ifs(descFileName);
if ( !ifs )
{
std::cout << "Cannot open description file name: " << descFileName << std::endl;
return 0;
}
cmOStringStream ostr;
std::string line;
while ( ifs && cmSystemTools::GetLineFromStream(ifs, line) )
{
ostr << cmSystemTools::MakeXMLSafe(line.c_str()) << std::endl;
}
this->SetOption("CPACK_PROJECT_DESCRIPTION", ostr.str().c_str());
}
if ( !this->GetOption("CPACK_PROJECT_DESCRIPTION") )
{
std::cout << "Project description not specified. Please specify CPACK_PROJECT_DESCRIPTION or CPACK_PROJECT_DESCRIPTION_FILE_NAME." << std::endl;
return 0;
}
return 1;
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::InstallProject()
{
std::cout << "Install project" << std::endl;
const char* tempInstallDirectory = this->GetOption("CPACK_TEMPORARY_INSTALL_DIRECTORY");
const char* installFile = this->GetOption("CPACK_INSTALL_FILE_NAME");
if ( !cmsys::SystemTools::MakeDirectory(tempInstallDirectory))
{
std::cerr << "Problem creating temporary directory: " << tempInstallDirectory << std::endl;
return 0;
}
cmake cm;
cmGlobalGenerator gg;
gg.SetCMakeInstance(&cm);
std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
lg->SetGlobalGenerator(&gg);
cmMakefile *mf = lg->GetMakefile();
bool movable = true;
if ( movable )
{
mf->AddDefinition("CMAKE_INSTALL_PREFIX", tempInstallDirectory);
}
const char* buildConfig = this->GetOption("CPACK_BUILD_CONFIG");
if ( buildConfig && *buildConfig )
{
mf->AddDefinition("BUILD_TYPE", buildConfig);
}
if ( movable )
{
// Make sure there is no destdir
cmSystemTools::PutEnv("DESTDIR=");
}
else
{
std::string destDir = "DESTDIR=";
destDir += tempInstallDirectory;
cmSystemTools::PutEnv(destDir.c_str());
}
int res = mf->ReadListFile(0, installFile);
if ( !movable )
{
cmSystemTools::PutEnv("DESTDIR=");
}
return res;
}
//----------------------------------------------------------------------
void cmCPackGenericGenerator::SetOption(const char* op, const char* value)
{
if ( !op )
{
return;
}
if ( !value )
{
m_MakefileMap->RemoveDefinition(op);
return;
}
std::cout << this->GetNameOfClass() << "::SetOption(" << op << ", " << value << ")" << std::endl;
m_MakefileMap->AddDefinition(op, value);
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::ProcessGenerator()
{
if ( !this->PrepareNames() )
{
return 0;
}
if ( !this->InstallProject() )
{
return 0;
}
const char* tempPackageFileName = this->GetOption(
"CPACK_TEMPORARY_PACKAGE_FILE_NAME");
const char* packageFileName = this->GetOption("CPACK_PACKAGE_FILE_NAME");
const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
std::cout << "Find files" << std::endl;
cmsys::Glob gl;
std::string findExpr = tempDirectory;
findExpr += "/*";
gl.RecurseOn();
if ( !gl.FindFiles(findExpr) )
{
std::cerr << "CPack error: cannot find any files in the packaging tree" << std::endl;
return 0;
}
std::cout << "Compress files to: " << tempPackageFileName << std::endl;
if ( !this->CompressFiles(tempPackageFileName,
tempDirectory, gl.GetFiles()) )
{
std::cerr << "CPack error: problem compressing the directory" << std::endl;
return 0;
}
std::cout << "Finalize package" << std::endl;
std::cout << "Copy final package: " << tempPackageFileName << " to " << packageFileName << std::endl;
if ( !cmSystemTools::CopyFileIfDifferent(tempPackageFileName, packageFileName) )
{
std::cerr << "CPack error: problem copying the package: " << tempPackageFileName << " to " << packageFileName << std::endl;
return 0;
}
std::cout << "All done" << std::endl;
return 1;
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::Initialize(const char* name)
{
m_CMakeInstance = new cmake;
m_CMakeInstance->AddCMakePaths(m_CMakeRoot.c_str());
m_GlobalGenerator = new cmGlobalGenerator;
m_GlobalGenerator->SetCMakeInstance(m_CMakeInstance);
m_LocalGenerator = m_GlobalGenerator->CreateLocalGenerator();
m_MakefileMap = m_LocalGenerator->GetMakefile();
m_Name = name;
this->SetOption("CPACK_GENERATOR", name);
return 1;
}
//----------------------------------------------------------------------
const char* cmCPackGenericGenerator::GetOption(const char* op)
{
return m_MakefileMap->GetDefinition(op);
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::GenerateHeader(std::ostream* os)
{
(void)os;
return 1;
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::FindRunningCMake(const char* arg0)
{
int found = 0;
// Find our own executable.
std::vector<cmStdString> failures;
m_CPackSelf = arg0;
cmSystemTools::ConvertToUnixSlashes(m_CPackSelf);
failures.push_back(m_CPackSelf);
m_CPackSelf = cmSystemTools::FindProgram(m_CPackSelf.c_str());
if(!cmSystemTools::FileExists(m_CPackSelf.c_str()))
{
failures.push_back(m_CPackSelf);
m_CPackSelf = "/usr/local/bin/ctest";
}
if(!cmSystemTools::FileExists(m_CPackSelf.c_str()))
{
failures.push_back(m_CPackSelf);
cmOStringStream msg;
msg << "CTEST can not find the command line program ctest.\n";
msg << " argv[0] = \"" << arg0 << "\"\n";
msg << " Attempted paths:\n";
std::vector<cmStdString>::iterator i;
for(i=failures.begin(); i != failures.end(); ++i)
{
msg << " \"" << i->c_str() << "\"\n";
}
cmSystemTools::Error(msg.str().c_str());
}
std::string dir;
std::string file;
if(cmSystemTools::SplitProgramPath(m_CPackSelf.c_str(),
dir, file, true))
{
m_CMakeSelf = dir += "/cmake";
m_CMakeSelf += cmSystemTools::GetExecutableExtension();
if(cmSystemTools::FileExists(m_CMakeSelf.c_str()))
{
found = 1;
}
}
if ( !found )
{
failures.push_back(m_CMakeSelf);
#ifdef CMAKE_BUILD_DIR
std::string intdir = ".";
#ifdef CMAKE_INTDIR
intdir = CMAKE_INTDIR;
#endif
m_CMakeSelf = CMAKE_BUILD_DIR;
m_CMakeSelf += "/bin/";
m_CMakeSelf += intdir;
m_CMakeSelf += "/cmake";
m_CMakeSelf += cmSystemTools::GetExecutableExtension();
#endif
if(!cmSystemTools::FileExists(m_CMakeSelf.c_str()))
{
failures.push_back(m_CMakeSelf);
cmOStringStream msg;
msg << "CTEST can not find the command line program cmake.\n";
msg << " argv[0] = \"" << arg0 << "\"\n";
msg << " Attempted paths:\n";
std::vector<cmStdString>::iterator i;
for(i=failures.begin(); i != failures.end(); ++i)
{
msg << " \"" << i->c_str() << "\"\n";
}
cmSystemTools::Error(msg.str().c_str());
}
}
// do CMAKE_ROOT, look for the environment variable first
std::string cMakeRoot;
std::string modules;
if (getenv("CMAKE_ROOT"))
{
cMakeRoot = getenv("CMAKE_ROOT");
modules = cMakeRoot + "/Modules/CMake.cmake";
}
if(!cmSystemTools::FileExists(modules.c_str()))
{
// next try exe/..
cMakeRoot = cmSystemTools::GetProgramPath(m_CMakeSelf.c_str());
std::string::size_type slashPos = cMakeRoot.rfind("/");
if(slashPos != std::string::npos)
{
cMakeRoot = cMakeRoot.substr(0, slashPos);
}
// is there no Modules direcory there?
modules = cMakeRoot + "/Modules/CMake.cmake";
}
if (!cmSystemTools::FileExists(modules.c_str()))
{
// try exe/../share/cmake
cMakeRoot += CMAKE_DATA_DIR;
modules = cMakeRoot + "/Modules/CMake.cmake";
}
#ifdef CMAKE_ROOT_DIR
if (!cmSystemTools::FileExists(modules.c_str()))
{
// try compiled in root directory
cMakeRoot = CMAKE_ROOT_DIR;
modules = cMakeRoot + "/Modules/CMake.cmake";
}
#endif
#ifdef CMAKE_PREFIX
if (!cmSystemTools::FileExists(modules.c_str()))
{
// try compiled in install prefix
cMakeRoot = CMAKE_PREFIX CMAKE_DATA_DIR;
modules = cMakeRoot + "/Modules/CMake.cmake";
}
#endif
if (!cmSystemTools::FileExists(modules.c_str()))
{
// try
cMakeRoot = cmSystemTools::GetProgramPath(m_CMakeSelf.c_str());
cMakeRoot += CMAKE_DATA_DIR;
modules = cMakeRoot + "/Modules/CMake.cmake";
}
if(!cmSystemTools::FileExists(modules.c_str()))
{
// next try exe
cMakeRoot = cmSystemTools::GetProgramPath(m_CMakeSelf.c_str());
// is there no Modules direcory there?
modules = cMakeRoot + "/Modules/CMake.cmake";
}
if (!cmSystemTools::FileExists(modules.c_str()))
{
// couldn't find modules
cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
"CMake has most likely not been installed correctly.\n"
"Modules directory not found in\n",
cMakeRoot.c_str());
return 0;
}
m_CMakeRoot = cMakeRoot;
return 1;
}
//----------------------------------------------------------------------
int cmCPackGenericGenerator::CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files)
{
(void)outFileName;
(void)toplevel;
(void)files;
return 0;
}
//----------------------------------------------------------------------
const char* cmCPackGenericGenerator::GetInstallPath()
{
if ( !m_InstallPath.empty() )
{
return m_InstallPath.c_str();
}
#if defined(_WIN32) && !defined(__CYGWIN__)
const char* prgfiles = cmsys::SystemTools::GetEnv("ProgramFiles");
const char* sysDrive = cmsys::SystemTools::GetEnv("SystemDrive");
if ( prgfiles )
{
m_InstallPath = prgfiles;
}
else if ( sysDrive )
{
m_InstallPath = sysDrive;
m_InstallPath += "/Program Files";
}
else
{
m_InstallPath = "c:/Program Files";
}
m_InstallPath += "/";
m_InstallPath += this->GetOption("CPACK_PROJECT_NAME");
m_InstallPath += "-";
m_InstallPath += this->GetOption("CPACK_PROJECT_VERSION");
#else
m_InstallPath = "/usr/local/";
#endif
return m_InstallPath.c_str();
}
//----------------------------------------------------------------------
std::string cmCPackGenericGenerator::FindTemplate(const char* name)
{
return m_MakefileMap->GetModulesFile(name);
}
//----------------------------------------------------------------------
bool cmCPackGenericGenerator::ConfigureFile(const char* inName, const char* outName)
{
return m_MakefileMap->ConfigureFile(inName, outName, false, true, false);
}

View File

@ -0,0 +1,103 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmCPackGenericGenerator_h
#define cmCPackGenericGenerator_h
#include "cmObject.h"
#define cmCPackTypeMacro(class, superclass) \
cmTypeMacro(class, superclass); \
static cmCPackGenericGenerator* CreateGenerator() { return new class; }
class cmMakefile;
class cmLocalGenerator;
class cmGlobalGenerator;
class cmake;
/** \class cmCPackGenericGenerator
* \brief A superclass of all CPack Generators
*
*/
class cmCPackGenericGenerator : public cmObject
{
public:
cmTypeMacro(cmCPackGenericGenerator, cmObject);
/**
* If verbose then more informaiton is printed out
*/
void SetVerbose(bool val) { m_GeneratorVerbose = val; }
/**
* Do the actual processing. Subclass has to override it.
* Return 0 if error.
*/
virtual int ProcessGenerator();
/**
* Initialize generator
*/
virtual int Initialize(const char* name);
/**
* Construct generator
*/
cmCPackGenericGenerator();
virtual ~cmCPackGenericGenerator();
//! Set and get the options
void SetOption(const char* op, const char* value);
const char* GetOption(const char* op);
//! Set all the variables
int FindRunningCMake(const char* arg0);
protected:
int PrepareNames();
int InstallProject();
virtual int GenerateHeader(std::ostream* os);
virtual const char* GetOutputExtension() { return "cpack"; }
virtual const char* GetOutputPostfix() { return 0; }
virtual int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetInstallPath();
virtual const char* GetInstallPrefix() { return "/"; }
virtual std::string FindTemplate(const char* name);
virtual bool ConfigureFile(const char* inName, const char* outName);
bool m_GeneratorVerbose;
std::string m_Name;
std::string m_InstallPath;
std::string m_CPackSelf;
std::string m_CMakeSelf;
std::string m_CMakeRoot;
private:
cmGlobalGenerator* m_GlobalGenerator;
cmLocalGenerator* m_LocalGenerator;
cmMakefile* m_MakefileMap;
cmake* m_CMakeInstance;
};
#endif

View File

@ -0,0 +1,108 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCPackNSISGenerator.h"
#include "cmake.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmSystemTools.h"
#include "cmMakefile.h"
#include "cmGeneratedFileStream.h"
#include <cmsys/SystemTools.hxx>
#include <cmsys/Glob.hxx>
//----------------------------------------------------------------------
cmCPackNSISGenerator::cmCPackNSISGenerator()
{
}
//----------------------------------------------------------------------
cmCPackNSISGenerator::~cmCPackNSISGenerator()
{
}
//----------------------------------------------------------------------
int cmCPackNSISGenerator::ProcessGenerator()
{
return this->Superclass::ProcessGenerator();
}
//----------------------------------------------------------------------
int cmCPackNSISGenerator::CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files)
{
(void)outFileName; // TODO: Fix nsis to force out file name
(void)toplevel;
(void)files;
std::string nsisInFileName = this->FindTemplate("NSIS.template.in");
if ( nsisInFileName.size() == 0 )
{
std::cerr << "CPack error: Could not find NSIS installer template file." << std::endl;
return false;
}
std::string nsisFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
std::string tmpFile = nsisFileName;
tmpFile += "/NSISOutput.log";
nsisFileName += "/project.nsi";
std::cout << "Configure file: " << nsisInFileName << " to " << nsisFileName << std::endl;
this->ConfigureFile(nsisInFileName.c_str(), nsisFileName.c_str());
std::string nsisCmd = "\"";
nsisCmd += this->GetOption("CPACK_INSTALLER_PROGRAM");
nsisCmd += "\" \"" + nsisFileName + "\"";
std::cout << "Execute: " << nsisCmd.c_str() << std::endl;
std::string output;
int retVal = 1;
bool res = cmSystemTools::RunSingleCommand(nsisCmd.c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
if ( !res || retVal )
{
cmGeneratedFileStream ofs(tmpFile.c_str());
ofs << "# Run command: " << nsisCmd.c_str() << std::endl
<< "# Output:" << std::endl
<< output.c_str() << std::endl;
std::cerr << "Problem running NSIS command: " << nsisCmd.c_str() << std::endl;
std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
return 0;
}
return 1;
}
//----------------------------------------------------------------------
int cmCPackNSISGenerator::Initialize(const char* name)
{
std::cout << "cmCPackNSISGenerator::Initialize()" << std::endl;
int res = this->Superclass::Initialize(name);
std::vector<std::string> path;
std::string nsisPath;
if ( !cmsys::SystemTools::ReadRegistryValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\NSIS",
nsisPath) )
{
std::cerr << "Cannot find NSIS registry value" << std::endl;
return 0;
}
path.push_back(nsisPath);
nsisPath = cmSystemTools::FindProgram("makensis", path, false);
if ( nsisPath.empty() )
{
std::cerr << "Cannot find NSIS compiler" << std::endl;
return 0;
}
this->SetOption("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
return res;
}

View File

@ -0,0 +1,60 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmCPackNSISGenerator_h
#define cmCPackNSISGenerator_h
#include "cmCPackGenericGenerator.h"
#include "CPack/cmCPackConfigure.h" // for ssize_t
/** \class cmCPackNSISGenerator
* \brief A generator for NSIS files
*
* http://people.freebsd.org/~kientzle/libarchive/
*/
class cmCPackNSISGenerator : public cmCPackGenericGenerator
{
public:
cmCPackTypeMacro(cmCPackNSISGenerator, cmCPackGenericGenerator);
/**
* Do the actual processing. Subclass has to override it.
* Return < 0 if error.
*/
virtual int ProcessGenerator();
/**
* Initialize generator
*/
virtual int Initialize(const char* name);
/**
* Construct generator
*/
cmCPackNSISGenerator();
virtual ~cmCPackNSISGenerator();
protected:
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "exe"; }
virtual const char* GetOutputPostfix() { return "win32"; }
};
#endif

View File

@ -0,0 +1,203 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCPackPackageMakerGenerator.h"
#include "cmake.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmSystemTools.h"
#include "cmMakefile.h"
#include "cmGeneratedFileStream.h"
#include <cmsys/SystemTools.hxx>
#include <cmsys/Glob.hxx>
//----------------------------------------------------------------------
cmCPackPackageMakerGenerator::cmCPackPackageMakerGenerator()
{
}
//----------------------------------------------------------------------
cmCPackPackageMakerGenerator::~cmCPackPackageMakerGenerator()
{
}
//----------------------------------------------------------------------
int cmCPackPackageMakerGenerator::ProcessGenerator()
{
return this->Superclass::ProcessGenerator();
}
//----------------------------------------------------------------------
int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files)
{
// Create directory structure
std::string resDir = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
resDir += "/Resources";
std::string preflightDirName = resDir + "/PreFlight";
std::string postflightDirName = resDir + "/PostFlight";
if ( !cmsys::SystemTools::MakeDirectory(preflightDirName.c_str())
|| !cmsys::SystemTools::MakeDirectory(postflightDirName.c_str()) )
{
std::cerr << "Problem creating installer directories: " << preflightDirName.c_str() << " and " << postflightDirName.c_str() << std::endl;
return 0;
}
if ( !this->CopyCreateResourceFile("License")
|| !this->CopyCreateResourceFile("ReadMe")
|| !this->CopyCreateResourceFile("Welcome")
|| !this->CopyResourcePlistFile("Info.plist")
|| !this->CopyResourcePlistFile("Description.plist") )
{
std::cerr << "Problem copying the resource files" << std::endl;
return 0;
}
std::string packageDirFileName = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
packageDirFileName += ".pkg";
std::string tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/PackageMakerOutput.log";
cmOStringStream pkgCmd;
/*
pkgCmd << "sh -c '\"" << this->GetOption("CPACK_INSTALLER_PROGRAM")
<< "\" -build -p \"" << packageDirFileName << "\" -f \"" << this->GetOption("CPACK_TEMPORARY_DIRECTORY")
<< "\" -r \"" << this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Resources\" -i \""
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Info.plist\" -d \""
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Description.plist\"'";
*/
pkgCmd << "/Users/kitware/Andy/CMake-CPack/foo.sh";
std::cout << "Execute: " << pkgCmd.str().c_str() << std::endl;
std::string output;
int retVal = 1;
//bool res = cmSystemTools::RunSingleCommand(pkgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
bool res = true;
retVal = system(pkgCmd.str().c_str());
std::cout << "Done running package maker" << std::endl;
if ( !res || retVal )
{
cmGeneratedFileStream ofs(tmpFile.c_str());
ofs << "# Run command: " << pkgCmd.str().c_str() << std::endl
<< "# Output:" << std::endl
<< output.c_str() << std::endl;
std::cerr << "Problem running PackageMaker command: " << pkgCmd.str().c_str() << std::endl;
std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
return 0;
}
tmpFile = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
tmpFile += "/hdiutilOutput.log";
cmOStringStream dmgCmd;
dmgCmd << "\"" << this->GetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE") << "\" create -ov -format UDZO -srcfolder \"" << packageDirFileName
<< "\" \"" << outFileName << "\"";
res = cmSystemTools::RunSingleCommand(dmgCmd.str().c_str(), &output, &retVal, 0, m_GeneratorVerbose, 0);
if ( !res || retVal )
{
cmGeneratedFileStream ofs(tmpFile.c_str());
ofs << "# Run command: " << dmgCmd.str().c_str() << std::endl
<< "# Output:" << std::endl
<< output.c_str() << std::endl;
std::cerr << "Problem running hdiutil command: " << dmgCmd.str().c_str() << std::endl;
std::cerr << "Please check " << tmpFile.c_str() << " for errors" << std::endl;
return 0;
}
return 1;
}
//----------------------------------------------------------------------
int cmCPackPackageMakerGenerator::Initialize(const char* name)
{
std::cout << "cmCPackPackageMakerGenerator::Initialize()" << std::endl;
int res = this->Superclass::Initialize(name);
std::vector<std::string> path;
std::string pkgPath = "/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS";
path.push_back(pkgPath);
pkgPath = cmSystemTools::FindProgram("PackageMaker", path, false);
if ( pkgPath.empty() )
{
std::cerr << "Cannot find PackageMaker compiler" << std::endl;
return 0;
}
this->SetOption("CPACK_INSTALLER_PROGRAM", pkgPath.c_str());
pkgPath = cmSystemTools::FindProgram("hdiutil", path, false);
if ( pkgPath.empty() )
{
std::cerr << "Cannot find hdiutil compiler" << std::endl;
return 0;
}
this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
return res;
}
//----------------------------------------------------------------------
bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name)
{
std::string uname = cmSystemTools::UpperCase(name);
std::string cpackVar = "CPACK_RESOURCE_FILE_" + uname;
const char* inFileName = this->GetOption(cpackVar.c_str());
if ( !inFileName )
{
std::cerr << "CPack option: " << cpackVar.c_str() << " not specified. It should point to " << name << ".rtf, " << name << ".html, or " << name << ".txt file" << std::endl;
return false;
}
if ( !cmSystemTools::FileExists(inFileName) )
{
std::cerr << "Cannot find " << name << " resource file: " << inFileName << std::endl;
return false;
}
std::string ext = cmSystemTools::GetFilenameLastExtension(inFileName);
if ( ext != ".rtfd" && ext != ".rtf" && ext != ".html" && ext != ".txt" )
{
std::cerr << "Bad file extension specified: " << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." << std::endl;
return false;
}
std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
destFileName += "/Resources/";
destFileName += name + ext;
std::cout << "Configure file: " << inFileName << " to " << destFileName.c_str() << std::endl;
this->ConfigureFile(inFileName, destFileName.c_str());
return true;
}
bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name)
{
std::string inFName = "CPack.";
inFName += name;
inFName += ".in";
std::string inFileName = this->FindTemplate(inFName.c_str());
if ( inFileName.empty() )
{
std::cerr << "Cannot find input file: " << inFName << std::endl;
return false;
}
std::string destFileName = this->GetOption("CPACK_TOPLEVEL_DIRECTORY");
destFileName += "/";
destFileName += name;
std::cout << "Configure file: " << inFileName.c_str() << " to " << destFileName.c_str() << std::endl;
this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
return true;
}

View File

@ -0,0 +1,64 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmCPackPackageMakerGenerator_h
#define cmCPackPackageMakerGenerator_h
#include "cmCPackGenericGenerator.h"
#include "CPack/cmCPackConfigure.h" // for ssize_t
/** \class cmCPackPackageMakerGenerator
* \brief A generator for PackageMaker files
*
* http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/packagemaker.1.html
*/
class cmCPackPackageMakerGenerator : public cmCPackGenericGenerator
{
public:
cmCPackTypeMacro(cmCPackPackageMakerGenerator, cmCPackGenericGenerator);
/**
* Do the actual processing. Subclass has to override it.
* Return < 0 if error.
*/
virtual int ProcessGenerator();
/**
* Initialize generator
*/
virtual int Initialize(const char* name);
/**
* Construct generator
*/
cmCPackPackageMakerGenerator();
virtual ~cmCPackPackageMakerGenerator();
protected:
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "dmg"; }
virtual const char* GetOutputPostfix() { return "darwin"; }
virtual const char* GetInstallPrefix() { return "/usr"; }
bool CopyCreateResourceFile(const char* name);
bool CopyResourcePlistFile(const char* name);
};
#endif

View File

@ -0,0 +1,73 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmCPackSTGZGenerator.h"
#include "cmake.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmSystemTools.h"
#include "cmMakefile.h"
//----------------------------------------------------------------------
cmCPackSTGZGenerator::cmCPackSTGZGenerator()
{
}
//----------------------------------------------------------------------
cmCPackSTGZGenerator::~cmCPackSTGZGenerator()
{
}
//----------------------------------------------------------------------
int cmCPackSTGZGenerator::ProcessGenerator()
{
return this->Superclass::ProcessGenerator();
}
//----------------------------------------------------------------------
int cmCPackSTGZGenerator::Initialize(const char* name)
{
return this->Superclass::Initialize(name);
}
//----------------------------------------------------------------------
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
{
*os
<< "#!/bin/sh" << std::endl
<< "echo \"" << this->GetOption("ProjectName")
<< " - self-extracting archive.\"" << std::endl
<< "echo \"If you want to stop extracting, please press <ctrl-C>.\"" << std::endl
<< "read line" << std::endl
<< "echo \"Extracting... Please wait...\"" << std::endl
<< "echo \"\"" << std::endl
<< "" << std::endl
<< "# take the archive portion of this file and pipe it to tar" << std::endl
<< "# the NUMERIC parameter in this command should be one more" << std::endl
<< "# than the number of lines in this header file" << std::endl
<< "tail +18 $0 | gunzip | tar xf -" << std::endl
<< "" << std::endl
<< "exit 0" << std::endl
<< "echo \"\"" << std::endl
<< "#-----------------------------------------------------------" << std::endl
<< "# Start of TAR.GZ file" << std::endl
<< "#-----------------------------------------------------------" << std::endl;
return 1;
}

View File

@ -0,0 +1,57 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmCPackSTGZGenerator_h
#define cmCPackSTGZGenerator_h
#include "cmCPackTGZGenerator.h"
/** \class cmCPackSTGZGenerator
* \brief A generator for Self extractable TGZ files
*
*/
class cmCPackSTGZGenerator : public cmCPackTGZGenerator
{
public:
cmCPackTypeMacro(cmCPackSTGZGenerator, cmCPackTGZGenerator);
/**
* Do the actual processing. Subclass has to override it.
* Return < 0 if error.
*/
virtual int ProcessGenerator();
/**
* Initialize generator
*/
virtual int Initialize(const char* name);
/**
* Construct generator
*/
cmCPackSTGZGenerator();
virtual ~cmCPackSTGZGenerator();
protected:
int GenerateHeader(std::ostream* os);
virtual const char* GetOutputExtension() { return "sh"; }
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,64 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef cmCPackTGZGenerator_h
#define cmCPackTGZGenerator_h
#include "cmCPackGenericGenerator.h"
#include "CPack/cmCPackConfigure.h" // for ssize_t
/** \class cmCPackTGZGenerator
* \brief A generator for TGZ files
*
* http://people.freebsd.org/~kientzle/libarchive/
*/
class cmCPackTGZGenerator : public cmCPackGenericGenerator
{
public:
cmCPackTypeMacro(cmCPackTGZGenerator, cmCPackGenericGenerator);
/**
* Do the actual processing. Subclass has to override it.
* Return < 0 if error.
*/
virtual int ProcessGenerator();
/**
* Initialize generator
*/
virtual int Initialize(const char* name);
/**
* Construct generator
*/
cmCPackTGZGenerator();
virtual ~cmCPackTGZGenerator();
protected:
static int TGZ_Open(struct archive *a, void *client_data);
static ssize_t TGZ_Write(struct archive *a, void *client_data, void *buff, size_t n);
static int TGZ_Close(struct archive *a, void *client_data);
int CompressFiles(const char* outFileName, const char* toplevel,
const std::vector<std::string>& files);
virtual const char* GetOutputExtension() { return "tar.gz"; }
};
#endif

260
Source/CPack/cpack.cxx Normal file
View File

@ -0,0 +1,260 @@
/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmSystemTools.h"
// Need these for documentation support.
#include "cmake.h"
#include "cmDocumentation.h"
#include "cmCPackGenerators.h"
#include "cmCPackGenericGenerator.h"
#include <cmsys/CommandLineArguments.hxx>
//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationName[] =
{
{0,
" cpack - Packaging driver provided by CMake.", 0},
{0,0,0}
};
//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationUsage[] =
{
{0,
" cpack -G <generator> -P <ProjectName> -R <ReleaseVersion> [options]", 0},
{0,0,0}
};
//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationDescription[] =
{
{0,
"The \"cpack\" executable is the CMake packaging program. "
"CMake-generated build trees created for projects that use "
"the INSTALL_* commands have packaging support. "
"This program will generate the package.", 0},
CMAKE_STANDARD_INTRODUCTION,
{0,0,0}
};
//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationOptions[] =
{
{"-G <generator>", "Use the specified generator to generate package.",
"CPack may support multiple native packaging systems on certain platforms. A "
"generator is responsible for generating input files for particular system "
"and invoking that systems. Possible generator names are specified in the "
"Generators section." },
{"-P <ProjectName>", "Specify the project name.",
"This option specifies the project name that will be used to generate the "
"installer." },
{"-R <ReleaseVersion>", "Specify the release version of the project.",
"This option specifies the release version of the project that will be "
"used by installer." },
{"-D <var>=<value>", "Set a CPack variable.", \
"Set a variable that can be used by the generator."}, \
{"--patch <ReleasePatch>", "Specify the patch of the project.",
"This option specifies the patch of the project that will be "
"used by installer." },
{"--vendor <ProjectVendor>", "Specify the vendor of the project.",
"This option specifies the vendor of the project that will be "
"used by installer." },
{0,0,0}
};
//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationSeeAlso[] =
{
{0, "cmake", 0},
{0, "ccmake", 0},
{0, 0, 0}
};
//----------------------------------------------------------------------------
int cpackUnknownArgument(const char*, void*)
{
return 1;
}
//----------------------------------------------------------------------------
typedef std::map<cmStdString, cmStdString> cpackDefinitionsMapType;
//----------------------------------------------------------------------------
int cpackDefinitionArgument(const char* argument, const char* cValue,
void* call_data)
{
(void)argument;
std::string value = cValue;
size_t pos = value.find_first_of("=");
if ( pos == std::string::npos )
{
std::cerr << "Please specify CPack definitions as: KEY=VALUE" << std::endl;
return 0;
}
std::string key = value.substr(0, pos);
value = value.c_str() + pos + 1;
cpackDefinitionsMapType* map = static_cast<cpackDefinitionsMapType*>(call_data);
(*map)[key] = value;
return 1;
}
//----------------------------------------------------------------------------
// this is CPack.
int main (int argc, char *argv[])
{
int res = 0;
cmSystemTools::EnableMSVCDebugHook();
if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
{
std::cerr << "Current working directory cannot be established." << std::endl;
}
std::string generator;
bool help = false;
bool helpVersion = false;
std::string helpFull;
std::string helpMAN;
std::string helpHTML;
std::string cpackProjectName;
std::string cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory();
std::string cpackBuildConfig;
std::string cpackProjectVersion;
std::string cpackProjectPatch;
std::string cpackProjectVendor;
cpackDefinitionsMapType definitionsMap;
cmDocumentation doc;
cmsys::CommandLineArguments arg;
arg.Initialize(argc, argv);
typedef cmsys::CommandLineArguments argT;
// Help arguments
arg.AddArgument("--help", argT::NO_ARGUMENT, &help, "CPack help");
arg.AddArgument("--help-full", argT::SPACE_ARGUMENT, &helpFull, "CPack help");
arg.AddArgument("--help-html", argT::SPACE_ARGUMENT, &helpHTML, "CPack help");
arg.AddArgument("--help-man", argT::SPACE_ARGUMENT, &helpMAN, "CPack help");
arg.AddArgument("--version", argT::NO_ARGUMENT, &helpVersion, "CPack help");
arg.AddArgument("-C", argT::SPACE_ARGUMENT, &cpackBuildConfig, "CPack build configuration");
arg.AddArgument("-G", argT::SPACE_ARGUMENT, &generator, "CPack generator");
arg.AddArgument("-P", argT::SPACE_ARGUMENT, &cpackProjectName, "CPack project name");
arg.AddArgument("-R", argT::SPACE_ARGUMENT, &cpackProjectVersion, "CPack project version");
arg.AddArgument("-B", argT::SPACE_ARGUMENT, &cpackProjectDirectory, "CPack project directory");
arg.AddArgument("--patch", argT::SPACE_ARGUMENT, &cpackProjectPatch, "CPack project patch");
arg.AddArgument("--vendor", argT::SPACE_ARGUMENT, &cpackProjectVendor, "CPack project vendor");
arg.AddCallback("-D", argT::SPACE_ARGUMENT, cpackDefinitionArgument, &definitionsMap, "CPack Definitions");
arg.SetUnknownArgumentCallback(cpackUnknownArgument);
int parsed = arg.Parse();
cmCPackGenerators generators;
cmCPackGenericGenerator* cpackGenerator = 0;
if ( !helpFull.empty() || !helpMAN.empty() || !helpHTML.empty() || helpVersion )
{
help = true;
}
if ( parsed && !help )
{
if ( generator.empty() )
{
std::cerr << "CPack generator not specified" << std::endl;
parsed = 0;
}
if ( parsed && cpackProjectName.empty() )
{
std::cerr << "CPack project name not specified" << std::endl;
parsed = 0;
}
if ( parsed && cpackProjectVersion.empty() )
{
std::cerr << "CPack project version not specified" << std::endl;
parsed = 0;
}
if ( parsed )
{
cpackGenerator = generators.NewGenerator(generator.c_str());
if ( !cpackGenerator )
{
std::cerr << "Cannot initialize CPack generator: " << generator.c_str() << std::endl;
parsed = 0;
}
if ( parsed && !cpackGenerator->FindRunningCMake(argv[0]) )
{
std::cerr << "Cannot initialize the generator" << std::endl;
parsed = 0;
}
cmsys::SystemTools::ConvertToUnixSlashes(cpackProjectDirectory);
std::string makeInstallFile = cpackProjectDirectory + "/cmake_install.cmake";
if ( !cmsys::SystemTools::FileExists(makeInstallFile.c_str()) )
{
std::cerr << "Cannot find installation file: " << makeInstallFile.c_str() << std::endl;
parsed = 0;
}
}
}
if ( !parsed || help )
{
doc.CheckOptions(argc, argv);
// Construct and print requested documentation.
doc.SetName("cpack");
doc.SetNameSection(cmDocumentationName);
doc.SetUsageSection(cmDocumentationUsage);
doc.SetDescriptionSection(cmDocumentationDescription);
doc.SetOptionsSection(cmDocumentationOptions);
doc.SetSeeAlsoList(cmDocumentationSeeAlso);
return doc.PrintRequestedDocumentation(std::cout)? 0:1;
}
#ifdef _WIN32
std::string comspec = "cmw9xcom.exe";
cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
#endif
std::cout << "Use generator: " << cpackGenerator->GetNameOfClass() << std::endl;
std::cout << "For project: " << cpackProjectName.c_str() << std::endl;
cpackGenerator->SetOption("CPACK_PROJECT_NAME", cpackProjectName.c_str());
cpackGenerator->SetOption("CPACK_PROJECT_VERSION", cpackProjectVersion.c_str());
cpackGenerator->SetOption("CPACK_PROJECT_VERSION_PATCH", cpackProjectPatch.c_str());
cpackGenerator->SetOption("CPACK_PROJECT_VENDOR", cpackProjectVendor.c_str());
cpackGenerator->SetOption("CPACK_PROJECT_DIRECTORY", cpackProjectDirectory.c_str());
if ( !cpackBuildConfig.empty() )
{
cpackGenerator->SetOption("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
}
cpackDefinitionsMapType::iterator cdit;
for ( cdit = definitionsMap.begin(); cdit != definitionsMap.end(); ++cdit )
{
cpackGenerator->SetOption(cdit->first.c_str(), cdit->second.c_str());
}
res = cpackGenerator->ProcessGenerator();
if ( !res )
{
std::cerr << "Error when generating package: " << cpackProjectName.c_str() << std::endl;
return 1;
}
return 0;
}