ENH: More improvements and add logging
This commit is contained in:
parent
9d0f86d7d0
commit
bbf1c2d275
|
@ -261,6 +261,7 @@ SET(CPACK_SRCS
|
|||
CPack/cmCPackNSISGenerator.cxx
|
||||
CPack/cmCPackPackageMakerGenerator.cxx
|
||||
CPack/cmCPackGenericGenerator.cxx
|
||||
CPack/cmCPackLog.cxx
|
||||
)
|
||||
# Build CPackLib
|
||||
ADD_LIBRARY(CPackLib ${CPACK_SRCS})
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "cmCPackNSISGenerator.h"
|
||||
#include "cmCPackPackageMakerGenerator.h"
|
||||
|
||||
#include "cmCPackLog.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
cmCPackGenerators::cmCPackGenerators()
|
||||
{
|
||||
|
@ -56,6 +58,7 @@ cmCPackGenericGenerator* cmCPackGenerators::NewGenerator(const char* name)
|
|||
return 0;
|
||||
}
|
||||
m_Generators.push_back(gen);
|
||||
gen->SetLogger(m_Logger);
|
||||
return gen;
|
||||
}
|
||||
|
||||
|
@ -72,26 +75,6 @@ cmCPackGenericGenerator* cmCPackGenerators::NewGeneratorInternal(const char* nam
|
|||
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;
|
||||
*/
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -99,7 +82,7 @@ void cmCPackGenerators::RegisterGenerator(const char* name, CreateGeneratorCall*
|
|||
{
|
||||
if ( !name || !createGenerator )
|
||||
{
|
||||
std::cerr << "Cannot register generator" << std::endl;
|
||||
cmCPack_Log(m_Logger, cmCPackLog::LOG_ERROR, "Cannot register generator" << std::endl);
|
||||
return;
|
||||
}
|
||||
m_GeneratorCreators[name] = createGenerator;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "cmObject.h"
|
||||
|
||||
class cmCPackLog;
|
||||
class cmCPackGenericGenerator;
|
||||
|
||||
/** \class cmCPackGenerators
|
||||
|
@ -42,12 +43,15 @@ public:
|
|||
|
||||
void RegisterGenerator(const char* name, CreateGeneratorCall* createGenerator);
|
||||
|
||||
void SetLogger(cmCPackLog* logger) { m_Logger = logger; }
|
||||
|
||||
private:
|
||||
cmCPackGenericGenerator* NewGeneratorInternal(const char* name);
|
||||
std::vector<cmCPackGenericGenerator*> m_Generators;
|
||||
|
||||
typedef std::map<cmStdString, CreateGeneratorCall*> t_GeneratorCreatorsMap;
|
||||
t_GeneratorCreatorsMap m_GeneratorCreators;
|
||||
cmCPackLog* m_Logger;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "cmGlobalGenerator.h"
|
||||
#include "cmLocalGenerator.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmCPackLog.h"
|
||||
|
||||
#include <cmsys/SystemTools.hxx>
|
||||
#include <cmsys/Glob.hxx>
|
||||
|
@ -34,6 +35,7 @@ cmCPackGenericGenerator::cmCPackGenericGenerator()
|
|||
m_LocalGenerator = 0;
|
||||
m_MakefileMap = 0;
|
||||
m_CMakeInstance = 0;
|
||||
m_Logger = 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -60,6 +62,7 @@ cmCPackGenericGenerator::~cmCPackGenericGenerator()
|
|||
//----------------------------------------------------------------------
|
||||
int cmCPackGenericGenerator::PrepareNames()
|
||||
{
|
||||
this->SetOption("CPACK_GENERATOR", m_Name.c_str());
|
||||
std::string tempDirectory = this->GetOption("CPACK_PROJECT_DIRECTORY");
|
||||
tempDirectory += "/_CPack_Packages/";
|
||||
tempDirectory += this->GetOption("CPACK_GENERATOR");
|
||||
|
@ -106,20 +109,20 @@ int cmCPackGenericGenerator::PrepareNames()
|
|||
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;
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Look for: " << descFileName << std::endl);
|
||||
if ( descFileName )
|
||||
{
|
||||
if ( !cmSystemTools::FileExists(descFileName) )
|
||||
{
|
||||
std::cout << "Cannot find description file name: " << descFileName << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot open description file name: " << descFileName << std::endl);
|
||||
return 0;
|
||||
}
|
||||
cmOStringStream ostr;
|
||||
|
@ -132,7 +135,9 @@ int cmCPackGenericGenerator::PrepareNames()
|
|||
}
|
||||
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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Project description not specified. Please specify CPACK_PROJECT_DESCRIPTION or CPACK_PROJECT_DESCRIPTION_FILE_NAME."
|
||||
<< std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -142,12 +147,12 @@ int cmCPackGenericGenerator::PrepareNames()
|
|||
//----------------------------------------------------------------------
|
||||
int cmCPackGenericGenerator::InstallProject()
|
||||
{
|
||||
std::cout << "Install project" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating temporary directory: " << tempInstallDirectory << std::endl);
|
||||
return 0;
|
||||
}
|
||||
cmake cm;
|
||||
|
@ -198,7 +203,7 @@ void cmCPackGenericGenerator::SetOption(const char* op, const char* value)
|
|||
m_MakefileMap->RemoveDefinition(op);
|
||||
return;
|
||||
}
|
||||
std::cout << this->GetNameOfClass() << "::SetOption(" << op << ", " << value << ")" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, this->GetNameOfClass() << "::SetOption(" << op << ", " << value << ")" << std::endl);
|
||||
m_MakefileMap->AddDefinition(op, value);
|
||||
}
|
||||
|
||||
|
@ -220,34 +225,35 @@ int cmCPackGenericGenerator::ProcessGenerator()
|
|||
const char* tempDirectory = this->GetOption("CPACK_TEMPORARY_DIRECTORY");
|
||||
|
||||
|
||||
std::cout << "Find files" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find any files in the packaging tree" << std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "Compress files to: " << tempPackageFileName << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Compress package" << std::endl);
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Compress files to: " << tempPackageFileName << std::endl);
|
||||
if ( !this->CompressFiles(tempPackageFileName,
|
||||
tempDirectory, gl.GetFiles()) )
|
||||
{
|
||||
std::cerr << "CPack error: problem compressing the directory" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_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;
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Finalize package" << std::endl);
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the package: " << tempPackageFileName << " to " << packageFileName << std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "All done" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_OUTPUT, "Package " << packageFileName << " generated." << std::endl);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -261,7 +267,6 @@ int cmCPackGenericGenerator::Initialize(const char* name)
|
|||
m_LocalGenerator = m_GlobalGenerator->CreateLocalGenerator();
|
||||
m_MakefileMap = m_LocalGenerator->GetMakefile();
|
||||
m_Name = name;
|
||||
this->SetOption("CPACK_GENERATOR", name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,28 @@
|
|||
cmTypeMacro(class, superclass); \
|
||||
static cmCPackGenericGenerator* CreateGenerator() { return new class; }
|
||||
|
||||
#define cmCPackLogger(logType, msg) \
|
||||
do { \
|
||||
cmOStringStream cmCPackLog_msg; \
|
||||
cmCPackLog_msg << msg; \
|
||||
m_Logger->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str());\
|
||||
} while ( 0 )
|
||||
|
||||
#ifdef cerr
|
||||
# undef cerr
|
||||
#endif
|
||||
#define cerr no_cerr_use_cmCPack_Log
|
||||
|
||||
#ifdef cout
|
||||
# undef cout
|
||||
#endif
|
||||
#define cout no_cout_use_cmCPack_Log
|
||||
|
||||
class cmMakefile;
|
||||
class cmLocalGenerator;
|
||||
class cmGlobalGenerator;
|
||||
class cmake;
|
||||
class cmCPackLog;
|
||||
|
||||
/** \class cmCPackGenericGenerator
|
||||
* \brief A superclass of all CPack Generators
|
||||
|
@ -67,6 +85,9 @@ public:
|
|||
//! Set all the variables
|
||||
int FindRunningCMake(const char* arg0);
|
||||
|
||||
//! Set the logger
|
||||
void SetLogger(cmCPackLog* log) { m_Logger = log; }
|
||||
|
||||
protected:
|
||||
int PrepareNames();
|
||||
int InstallProject();
|
||||
|
@ -90,6 +111,8 @@ protected:
|
|||
std::string m_CMakeSelf;
|
||||
std::string m_CMakeRoot;
|
||||
|
||||
cmCPackLog* m_Logger;
|
||||
|
||||
private:
|
||||
cmGlobalGenerator* m_GlobalGenerator;
|
||||
cmLocalGenerator* m_LocalGenerator;
|
||||
|
|
|
@ -0,0 +1,218 @@
|
|||
/*=========================================================================
|
||||
|
||||
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 "cmCPackLog.h"
|
||||
|
||||
#include "cmGeneratedFileStream.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
cmCPackLog::cmCPackLog()
|
||||
{
|
||||
m_Verbose = false;
|
||||
m_Debug = false;
|
||||
m_Quiet = false;
|
||||
m_NewLine = true;
|
||||
|
||||
m_LastTag = cmCPackLog::NOTAG;
|
||||
#undef cerr
|
||||
#undef cout
|
||||
m_DefaultOutput = &std::cout;
|
||||
m_DefaultError = &std::cerr;
|
||||
|
||||
m_LogOutput = 0;
|
||||
m_LogOutputCleanup = false;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
cmCPackLog::~cmCPackLog()
|
||||
{
|
||||
this->SetLogOutputStream(0);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void cmCPackLog::SetLogOutputStream(ostream* os)
|
||||
{
|
||||
if ( m_LogOutputCleanup && m_LogOutput )
|
||||
{
|
||||
delete m_LogOutput;
|
||||
}
|
||||
m_LogOutputCleanup = false;
|
||||
m_LogOutput = os;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
bool cmCPackLog::SetLogOutputFile(const char* fname)
|
||||
{
|
||||
cmGeneratedFileStream *cg = 0;
|
||||
if ( fname )
|
||||
{
|
||||
cg = new cmGeneratedFileStream(fname);
|
||||
}
|
||||
if ( cg && !*cg )
|
||||
{
|
||||
delete cg;
|
||||
cg = 0;
|
||||
}
|
||||
this->SetLogOutputStream(cg);
|
||||
if ( !cg )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_LogOutputCleanup = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void cmCPackLog::Log(int tag, const char* file, int line, const char* msg, size_t length)
|
||||
{
|
||||
// By default no logging
|
||||
bool display = false;
|
||||
|
||||
// Should we go to the error stream
|
||||
bool errorStream = false;
|
||||
|
||||
// Display file and line number if debug
|
||||
bool useFileAndLine = m_Debug;
|
||||
|
||||
bool output = false;
|
||||
bool debug = false;
|
||||
bool warning = false;
|
||||
bool error = false;
|
||||
bool verbose = false;
|
||||
|
||||
// When writing in file, add list of tags whenever tag changes.
|
||||
std::string tagString;
|
||||
bool needTagString = false;
|
||||
if ( m_LogOutput && m_LastTag != tag )
|
||||
{
|
||||
needTagString = true;
|
||||
}
|
||||
|
||||
if ( tag & LOG_OUTPUT )
|
||||
{
|
||||
output = true;
|
||||
display = true;
|
||||
if ( needTagString )
|
||||
{
|
||||
if ( tagString.size() > 0 ) { tagString += ","; }
|
||||
tagString = "VERBOSE";
|
||||
}
|
||||
}
|
||||
if ( tag & LOG_WARNING )
|
||||
{
|
||||
warning = true;
|
||||
display = true;
|
||||
errorStream = true;
|
||||
if ( needTagString )
|
||||
{
|
||||
if ( tagString.size() > 0 ) { tagString += ","; }
|
||||
tagString = "WARNING";
|
||||
}
|
||||
}
|
||||
if ( tag & LOG_ERROR )
|
||||
{
|
||||
error = true;
|
||||
display = true;
|
||||
errorStream = true;
|
||||
if ( needTagString )
|
||||
{
|
||||
if ( tagString.size() > 0 ) { tagString += ","; }
|
||||
tagString = "ERROR";
|
||||
}
|
||||
}
|
||||
if ( tag & LOG_DEBUG && m_Debug )
|
||||
{
|
||||
debug = true;
|
||||
display = true;
|
||||
if ( needTagString )
|
||||
{
|
||||
if ( tagString.size() > 0 ) { tagString += ","; }
|
||||
tagString = "DEBUG";
|
||||
}
|
||||
useFileAndLine = true;
|
||||
}
|
||||
if ( tag & LOG_VERBOSE && m_Verbose )
|
||||
{
|
||||
verbose = true;
|
||||
display = true;
|
||||
if ( needTagString )
|
||||
{
|
||||
if ( tagString.size() > 0 ) { tagString += ","; }
|
||||
tagString = "VERBOSE";
|
||||
}
|
||||
}
|
||||
if ( m_Quiet )
|
||||
{
|
||||
display = false;
|
||||
}
|
||||
if ( m_LogOutput )
|
||||
{
|
||||
if ( needTagString )
|
||||
{
|
||||
*m_LogOutput << "[" << file << ":" << line << " " << tagString << "] ";
|
||||
}
|
||||
m_LogOutput->write(msg, length);
|
||||
}
|
||||
m_LastTag = tag;
|
||||
if ( !display )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( m_NewLine )
|
||||
{
|
||||
if ( error && !m_ErrorPrefix.empty() )
|
||||
{
|
||||
*m_DefaultError << m_ErrorPrefix.c_str();
|
||||
}
|
||||
else if ( warning && !m_WarningPrefix.empty() )
|
||||
{
|
||||
*m_DefaultError << m_WarningPrefix.c_str();
|
||||
}
|
||||
else if ( output && !m_OutputPrefix.empty() )
|
||||
{
|
||||
*m_DefaultOutput << m_OutputPrefix.c_str();
|
||||
}
|
||||
else if ( verbose && !m_VerbosePrefix.empty() )
|
||||
{
|
||||
*m_DefaultOutput << m_VerbosePrefix.c_str();
|
||||
}
|
||||
else if ( debug && !m_DebugPrefix.empty() )
|
||||
{
|
||||
*m_DefaultOutput << m_DebugPrefix.c_str();
|
||||
}
|
||||
else if ( !m_Prefix.empty() )
|
||||
{
|
||||
*m_DefaultOutput << m_Prefix.c_str();
|
||||
}
|
||||
if ( useFileAndLine )
|
||||
{
|
||||
*m_DefaultOutput << __FILE__ << ":" << __LINE__ << " ";
|
||||
}
|
||||
}
|
||||
if ( error || warning )
|
||||
{
|
||||
m_DefaultError->write(msg, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_DefaultOutput->write(msg, length);
|
||||
}
|
||||
if ( msg[length-1] == '\n' || length > 2 )
|
||||
{
|
||||
m_NewLine = true;;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
/*=========================================================================
|
||||
|
||||
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 cmCPackLog_h
|
||||
#define cmCPackLog_h
|
||||
|
||||
#include "cmObject.h"
|
||||
|
||||
#define cmCPack_Log(ctSelf, logType, msg) \
|
||||
do { \
|
||||
cmOStringStream cmCPackLog_msg; \
|
||||
cmCPackLog_msg << msg; \
|
||||
(ctSelf)->Log(logType, __FILE__, __LINE__, cmCPackLog_msg.str().c_str());\
|
||||
} while ( 0 )
|
||||
|
||||
#ifdef cerr
|
||||
# undef cerr
|
||||
#endif
|
||||
#define cerr no_cerr_use_cmCPack_Log
|
||||
|
||||
#ifdef cout
|
||||
# undef cout
|
||||
#endif
|
||||
#define cout no_cout_use_cmCPack_Log
|
||||
|
||||
|
||||
/** \class cmCPackLog
|
||||
* \brief A container for CPack generators
|
||||
*
|
||||
*/
|
||||
class cmCPackLog : public cmObject
|
||||
{
|
||||
public:
|
||||
cmTypeMacro(cmCPackLog, cmObject);
|
||||
|
||||
cmCPackLog();
|
||||
~cmCPackLog();
|
||||
|
||||
enum __log_tags {
|
||||
NOTAG = 0,
|
||||
LOG_OUTPUT = 0x1,
|
||||
LOG_VERBOSE = 0x2,
|
||||
LOG_DEBUG = 0x4,
|
||||
LOG_WARNING = 0x8,
|
||||
LOG_ERROR = 0x10
|
||||
};
|
||||
|
||||
//! Various signatures for logging.
|
||||
void Log(const char* file, int line, const char* msg) { this->Log(LOG_OUTPUT, file, line, msg); }
|
||||
void Log(const char* file, int line, const char* msg, size_t length) { this->Log(LOG_OUTPUT, file, line, msg, length); }
|
||||
void Log(int tag, const char* file, int line, const char* msg) { this->Log(tag, file, line, msg, strlen(msg)); }
|
||||
void Log(int tag, const char* file, int line, const char* msg, size_t length);
|
||||
|
||||
//! Set Verbose
|
||||
void VerboseOn() { this->SetVerbose(true); }
|
||||
void VerboseOff() { this->SetVerbose(true); }
|
||||
void SetVerbose(bool verb) { m_Verbose = verb; }
|
||||
bool GetVerbose() { return m_Verbose; }
|
||||
|
||||
//! Set Debug
|
||||
void DebugOn() { this->SetDebug(true); }
|
||||
void DebugOff() { this->SetDebug(true); }
|
||||
void SetDebug(bool verb) { m_Debug = verb; }
|
||||
bool GetDebug() { return m_Debug; }
|
||||
|
||||
//! Set Quiet
|
||||
void QuietOn() { this->SetQuiet(true); }
|
||||
void QuietOff() { this->SetQuiet(true); }
|
||||
void SetQuiet(bool verb) { m_Quiet = verb; }
|
||||
bool GetQuiet() { return m_Quiet; }
|
||||
|
||||
//! Set the output stream
|
||||
void SetOutputStream(ostream* os) { m_DefaultOutput = os; }
|
||||
|
||||
//! Set the error stream
|
||||
void SetErrorStream(ostream* os) { m_DefaultError = os; }
|
||||
|
||||
//! Set the log output stream
|
||||
void SetLogOutputStream(ostream* os);
|
||||
|
||||
//! Set the log output file. The cmCPackLog will try to create file. If it
|
||||
// cannot, it will report an error.
|
||||
bool SetLogOutputFile(const char* fname);
|
||||
|
||||
//! Set the various prefixes for the logging. SetPrefix sets the generic
|
||||
// prefix that overwrittes missing ones.
|
||||
void SetPrefix(std::string pfx) { m_Prefix = pfx; }
|
||||
void SetOutputPrefix(std::string pfx) { m_OutputPrefix = pfx; }
|
||||
void SetVerbosePrefix(std::string pfx) { m_VerbosePrefix = pfx; }
|
||||
void SetDebugPrefix(std::string pfx) { m_DebugPrefix = pfx; }
|
||||
void SetWarningPrefix(std::string pfx) { m_WarningPrefix = pfx; }
|
||||
void SetErrorPrefix(std::string pfx) { m_ErrorPrefix = pfx; }
|
||||
|
||||
private:
|
||||
bool m_Verbose;
|
||||
bool m_Debug;
|
||||
bool m_Quiet;
|
||||
|
||||
bool m_NewLine;
|
||||
|
||||
int m_LastTag;
|
||||
|
||||
std::string m_Prefix;
|
||||
std::string m_OutputPrefix;
|
||||
std::string m_VerbosePrefix;
|
||||
std::string m_DebugPrefix;
|
||||
std::string m_WarningPrefix;
|
||||
std::string m_ErrorPrefix;
|
||||
|
||||
std::ostream *m_DefaultOutput;
|
||||
std::ostream *m_DefaultError;
|
||||
|
||||
std::string m_LogOutputFileName;
|
||||
std::ostream *m_LogOutput;
|
||||
// Do we need to cleanup log output stream
|
||||
bool m_LogOutputCleanup;
|
||||
};
|
||||
|
||||
class cmCPackLogWrite
|
||||
{
|
||||
public:
|
||||
cmCPackLogWrite(const char* data, size_t length) : Data(data), Length(length) {}
|
||||
|
||||
const char* Data;
|
||||
size_t Length;
|
||||
};
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& os, const cmCPackLogWrite& c)
|
||||
{
|
||||
os.write(c.Data, c.Length);
|
||||
os.flush();
|
||||
return os;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -23,6 +23,7 @@
|
|||
#include "cmSystemTools.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmCPackLog.h"
|
||||
|
||||
#include <cmsys/SystemTools.hxx>
|
||||
#include <cmsys/Glob.hxx>
|
||||
|
@ -53,19 +54,19 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName, const char* top
|
|||
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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "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);
|
||||
|
@ -75,8 +76,8 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName, const char* top
|
|||
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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running NSIS command: " << nsisCmd.c_str() << std::endl
|
||||
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
@ -85,21 +86,21 @@ int cmCPackNSISGenerator::CompressFiles(const char* outFileName, const char* top
|
|||
//----------------------------------------------------------------------
|
||||
int cmCPackNSISGenerator::Initialize(const char* name)
|
||||
{
|
||||
std::cout << "cmCPackNSISGenerator::Initialize()" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find NSIS compiler" << std::endl);
|
||||
return 0;
|
||||
}
|
||||
this->SetOption("CPACK_INSTALLER_PROGRAM", nsisPath.c_str());
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "cmSystemTools.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmCPackLog.h"
|
||||
|
||||
#include <cmsys/SystemTools.hxx>
|
||||
#include <cmsys/Glob.hxx>
|
||||
|
@ -57,7 +58,8 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const c
|
|||
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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem creating installer directories: " << preflightDirName.c_str() << " and "
|
||||
<< postflightDirName.c_str() << std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -67,7 +69,7 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const c
|
|||
|| !this->CopyResourcePlistFile("Info.plist")
|
||||
|| !this->CopyResourcePlistFile("Description.plist") )
|
||||
{
|
||||
std::cerr << "Problem copying the resource files" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem copying the resource files" << std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -85,21 +87,21 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const c
|
|||
<< this->GetOption("CPACK_TOPLEVEL_DIRECTORY") << "/Description.plist\"'";
|
||||
*/
|
||||
pkgCmd << "/Users/kitware/Andy/CMake-CPack/foo.sh";
|
||||
std::cout << "Execute: " << pkgCmd.str().c_str() << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running PackageMaker command: " << pkgCmd.str().c_str() << std::endl
|
||||
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -115,8 +117,8 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const c
|
|||
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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem running hdiutil command: " << dmgCmd.str().c_str() << std::endl
|
||||
<< "Please check " << tmpFile.c_str() << " for errors" << std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -126,7 +128,7 @@ int cmCPackPackageMakerGenerator::CompressFiles(const char* outFileName, const c
|
|||
//----------------------------------------------------------------------
|
||||
int cmCPackPackageMakerGenerator::Initialize(const char* name)
|
||||
{
|
||||
std::cout << "cmCPackPackageMakerGenerator::Initialize()" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, "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";
|
||||
|
@ -134,14 +136,14 @@ int cmCPackPackageMakerGenerator::Initialize(const char* name)
|
|||
pkgPath = cmSystemTools::FindProgram("PackageMaker", path, false);
|
||||
if ( pkgPath.empty() )
|
||||
{
|
||||
std::cerr << "Cannot find PackageMaker compiler" << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find hdiutil compiler" << std::endl);
|
||||
return 0;
|
||||
}
|
||||
this->SetOption("CPACK_INSTALLER_PROGRAM_DISK_IMAGE", pkgPath.c_str());
|
||||
|
@ -157,18 +159,18 @@ bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name)
|
|||
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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "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;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Bad file extension specified: " << ext << ". Currently only .rtfd, .rtf, .html, and .txt files allowed." << std::endl);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -177,7 +179,7 @@ bool cmCPackPackageMakerGenerator::CopyCreateResourceFile(const char* name)
|
|||
destFileName += name + ext;
|
||||
|
||||
|
||||
std::cout << "Configure file: " << inFileName << " to " << destFileName.c_str() << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName << " to " << destFileName.c_str() << std::endl);
|
||||
this->ConfigureFile(inFileName, destFileName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
@ -190,7 +192,7 @@ bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name)
|
|||
std::string inFileName = this->FindTemplate(inFName.c_str());
|
||||
if ( inFileName.empty() )
|
||||
{
|
||||
std::cerr << "Cannot find input file: " << inFName << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Cannot find input file: " << inFName << std::endl);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -198,7 +200,7 @@ bool cmCPackPackageMakerGenerator::CopyResourcePlistFile(const char* name)
|
|||
destFileName += "/";
|
||||
destFileName += name;
|
||||
|
||||
std::cout << "Configure file: " << inFileName.c_str() << " to " << destFileName.c_str() << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_VERBOSE, "Configure file: " << inFileName.c_str() << " to " << destFileName.c_str() << std::endl);
|
||||
this->ConfigureFile(inFileName.c_str(), destFileName.c_str());
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "cmLocalGenerator.h"
|
||||
#include "cmSystemTools.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmCPackLog.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
@ -49,6 +50,7 @@ int cmCPackSTGZGenerator::Initialize(const char* name)
|
|||
//----------------------------------------------------------------------
|
||||
int cmCPackSTGZGenerator::GenerateHeader(std::ostream* os)
|
||||
{
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Writing header" << std::endl);
|
||||
*os
|
||||
<< "#!/bin/sh" << std::endl
|
||||
<< "echo \"" << this->GetOption("ProjectName")
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "cmSystemTools.h"
|
||||
#include "cmMakefile.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmCPackLog.h"
|
||||
|
||||
#include <cmsys/SystemTools.hxx>
|
||||
#include <cmzlib/zlib.h>
|
||||
|
@ -74,6 +75,7 @@ public:
|
|||
cmCPackTGZGenerator* Generator;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
extern "C" {
|
||||
int cmCPackTGZ_Data_Open(void *client_data, const char* name, int oflags, mode_t mode);
|
||||
ssize_t cmCPackTGZ_Data_Write(void *client_data, void *buff, size_t n);
|
||||
|
@ -96,7 +98,7 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname, int, mode_t)
|
|||
gf->SetCompression(true);
|
||||
gf->SetCompressionExtraExtension(false);
|
||||
|
||||
if ( !cmCPackTGZGeneratorForward::GenerateHeader(mydata->Generator,mydata->OutputStream))
|
||||
if ( !cmCPackTGZGeneratorForward::GenerateHeader(mydata->Generator,gf))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -130,7 +132,7 @@ int cmCPackTGZ_Data_Close(void *client_data)
|
|||
int cmCPackTGZGenerator::CompressFiles(const char* outFileName, const char* toplevel,
|
||||
const std::vector<std::string>& files)
|
||||
{
|
||||
std::cout << "Toplevel: " << toplevel << std::endl;
|
||||
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl);
|
||||
cmCPackTGZ_Data mydata(this);
|
||||
TAR *t;
|
||||
char buf[TAR_MAXPATHLEN];
|
||||
|
@ -155,7 +157,7 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName, const char* topl
|
|||
(m_GeneratorVerbose?TAR_VERBOSE:0)
|
||||
| 0) == -1)
|
||||
{
|
||||
cmSystemTools::Error("Problem with tar_open(): ", strerror(errno));
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_open(): " << strerror(errno) << std::endl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -168,24 +170,23 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName, const char* topl
|
|||
buf[sizeof(buf)-1] = 0;
|
||||
if (tar_append_tree(t, buf, pathname) != 0)
|
||||
{
|
||||
cmOStringStream ostr;
|
||||
ostr << "Problem with tar_append_tree(\"" << buf << "\", \"" << pathname << "\"): "
|
||||
<< strerror(errno);
|
||||
cmSystemTools::Error(ostr.str().c_str());
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR,
|
||||
"Problem with tar_append_tree(\"" << buf << "\", \"" << pathname << "\"): "
|
||||
<< strerror(errno) << std::endl);
|
||||
tar_close(t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (tar_append_eof(t) != 0)
|
||||
{
|
||||
cmSystemTools::Error("Problem with tar_append_eof(): ", strerror(errno));
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_append_eof(): " << strerror(errno) << std::endl);
|
||||
tar_close(t);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tar_close(t) != 0)
|
||||
{
|
||||
cmSystemTools::Error("Problem with tar_close(): ", strerror(errno));
|
||||
cmCPackLogger(cmCPackLog::LOG_ERROR, "Problem with tar_close(): " << strerror(errno) << std::endl);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "cmCPackGenerators.h"
|
||||
#include "cmCPackGenericGenerator.h"
|
||||
|
||||
#include "cmCPackLog.h"
|
||||
|
||||
#include <cmsys/CommandLineArguments.hxx>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -92,24 +94,30 @@ int cpackUnknownArgument(const char*, void*)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
typedef std::map<cmStdString, cmStdString> cpackDefinitionsMapType;
|
||||
struct cpackDefinitions
|
||||
{
|
||||
typedef std::map<cmStdString, cmStdString> MapType;
|
||||
MapType m_Map;
|
||||
cmCPackLog *m_Log;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int cpackDefinitionArgument(const char* argument, const char* cValue,
|
||||
void* call_data)
|
||||
{
|
||||
(void)argument;
|
||||
cpackDefinitions* def = static_cast<cpackDefinitions*>(call_data);
|
||||
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;
|
||||
cmCPack_Log(def->m_Log, cmCPackLog::LOG_ERROR, "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;
|
||||
def->m_Map[key] = value;
|
||||
cmCPack_Log(def->m_Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: " << key.c_str() << " to \"" << value.c_str() << "\"" << std::endl);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -117,17 +125,24 @@ int cpackDefinitionArgument(const char* argument, const char* cValue,
|
|||
// this is CPack.
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
cmCPackLog log;
|
||||
log.SetErrorPrefix("CPack Error: ");
|
||||
log.SetWarningPrefix("CPack Warning: ");
|
||||
log.SetOutputPrefix("CPack: ");
|
||||
|
||||
int res = 0;
|
||||
cmSystemTools::EnableMSVCDebugHook();
|
||||
|
||||
if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
|
||||
{
|
||||
std::cerr << "Current working directory cannot be established." << std::endl;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Current working directory cannot be established." << std::endl);
|
||||
}
|
||||
|
||||
std::string generator;
|
||||
bool help = false;
|
||||
bool helpVersion = false;
|
||||
bool verbose = false;
|
||||
bool debug = false;
|
||||
std::string helpFull;
|
||||
std::string helpMAN;
|
||||
std::string helpHTML;
|
||||
|
@ -138,7 +153,13 @@ int main (int argc, char *argv[])
|
|||
std::string cpackProjectVersion;
|
||||
std::string cpackProjectPatch;
|
||||
std::string cpackProjectVendor;
|
||||
cpackDefinitionsMapType definitionsMap;
|
||||
std::string cpackConfigFile;
|
||||
|
||||
cpackDefinitions definitions;
|
||||
definitions.m_Log = &log;
|
||||
|
||||
cpackConfigFile = cmSystemTools::GetCurrentWorkingDirectory();
|
||||
cpackConfigFile += "/CPack.cmake";
|
||||
|
||||
cmDocumentation doc;
|
||||
cmsys::CommandLineArguments arg;
|
||||
|
@ -151,6 +172,10 @@ int main (int argc, char *argv[])
|
|||
arg.AddArgument("--help-man", argT::SPACE_ARGUMENT, &helpMAN, "CPack help");
|
||||
arg.AddArgument("--version", argT::NO_ARGUMENT, &helpVersion, "CPack help");
|
||||
|
||||
arg.AddArgument("-V", argT::NO_ARGUMENT, &verbose, "CPack verbose");
|
||||
arg.AddArgument("--verbose", argT::NO_ARGUMENT, &verbose, "-V");
|
||||
arg.AddArgument("--debug", argT::NO_ARGUMENT, &debug, "-V");
|
||||
arg.AddArgument("--config", argT::SPACE_ARGUMENT, &cpackConfigFile, "CPack configuration file");
|
||||
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");
|
||||
|
@ -158,12 +183,29 @@ int main (int argc, char *argv[])
|
|||
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.AddCallback("-D", argT::SPACE_ARGUMENT, cpackDefinitionArgument, &definitions, "CPack Definitions");
|
||||
arg.SetUnknownArgumentCallback(cpackUnknownArgument);
|
||||
|
||||
// Parse command line
|
||||
int parsed = arg.Parse();
|
||||
|
||||
// Setup logging
|
||||
if ( verbose )
|
||||
{
|
||||
log.SetVerbose(verbose);
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbse" << std::endl);
|
||||
}
|
||||
if ( debug )
|
||||
{
|
||||
log.SetDebug(debug);
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug" << std::endl);
|
||||
}
|
||||
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Read CPack config file: " << cpackConfigFile.c_str() << std::endl);
|
||||
|
||||
|
||||
cmCPackGenerators generators;
|
||||
generators.SetLogger(&log);
|
||||
cmCPackGenericGenerator* cpackGenerator = 0;
|
||||
|
||||
if ( !helpFull.empty() || !helpMAN.empty() || !helpHTML.empty() || helpVersion )
|
||||
|
@ -175,17 +217,17 @@ int main (int argc, char *argv[])
|
|||
{
|
||||
if ( generator.empty() )
|
||||
{
|
||||
std::cerr << "CPack generator not specified" << std::endl;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack generator not specified" << std::endl);
|
||||
parsed = 0;
|
||||
}
|
||||
if ( parsed && cpackProjectName.empty() )
|
||||
{
|
||||
std::cerr << "CPack project name not specified" << std::endl;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack project name not specified" << std::endl);
|
||||
parsed = 0;
|
||||
}
|
||||
if ( parsed && cpackProjectVersion.empty() )
|
||||
{
|
||||
std::cerr << "CPack project version not specified" << std::endl;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "CPack project version not specified" << std::endl);
|
||||
parsed = 0;
|
||||
}
|
||||
if ( parsed )
|
||||
|
@ -193,12 +235,12 @@ int main (int argc, char *argv[])
|
|||
cpackGenerator = generators.NewGenerator(generator.c_str());
|
||||
if ( !cpackGenerator )
|
||||
{
|
||||
std::cerr << "Cannot initialize CPack generator: " << generator.c_str() << std::endl;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "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;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot initialize the generator" << std::endl);
|
||||
parsed = 0;
|
||||
}
|
||||
|
||||
|
@ -206,7 +248,7 @@ int main (int argc, char *argv[])
|
|||
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;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Cannot find installation file: " << makeInstallFile.c_str() << std::endl);
|
||||
parsed = 0;
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +264,9 @@ int main (int argc, char *argv[])
|
|||
doc.SetDescriptionSection(cmDocumentationDescription);
|
||||
doc.SetOptionsSection(cmDocumentationOptions);
|
||||
doc.SetSeeAlsoList(cmDocumentationSeeAlso);
|
||||
#undef cout
|
||||
return doc.PrintRequestedDocumentation(std::cout)? 0:1;
|
||||
#define cout no_cout_use_cmCPack_Log
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -230,8 +274,8 @@ int main (int argc, char *argv[])
|
|||
cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
|
||||
#endif
|
||||
|
||||
std::cout << "Use generator: " << cpackGenerator->GetNameOfClass() << std::endl;
|
||||
std::cout << "For project: " << cpackProjectName.c_str() << std::endl;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: " << cpackGenerator->GetNameOfClass() << std::endl);
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "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());
|
||||
|
@ -241,8 +285,8 @@ int main (int argc, char *argv[])
|
|||
{
|
||||
cpackGenerator->SetOption("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
|
||||
}
|
||||
cpackDefinitionsMapType::iterator cdit;
|
||||
for ( cdit = definitionsMap.begin(); cdit != definitionsMap.end(); ++cdit )
|
||||
cpackDefinitions::MapType::iterator cdit;
|
||||
for ( cdit = definitions.m_Map.begin(); cdit != definitions.m_Map.end(); ++cdit )
|
||||
{
|
||||
cpackGenerator->SetOption(cdit->first.c_str(), cdit->second.c_str());
|
||||
}
|
||||
|
@ -250,7 +294,7 @@ int main (int argc, char *argv[])
|
|||
res = cpackGenerator->ProcessGenerator();
|
||||
if ( !res )
|
||||
{
|
||||
std::cerr << "Error when generating package: " << cpackProjectName.c_str() << std::endl;
|
||||
cmCPack_Log(&log, cmCPackLog::LOG_ERROR, "Error when generating package: " << cpackProjectName.c_str() << std::endl);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue