Commit d0329919 authored by Andy Cedilnik's avatar Andy Cedilnik
Browse files

ENH: Merge from the cpack branch

parent 74680f1b
#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@
/*=========================================================================
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;
}
/*=========================================================================
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
/*=========================================================================
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"