diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-01-02 21:14:21 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2006-01-02 21:14:21 (GMT) |
commit | bbf1c2d275ce58a76cfe5d3a6539a3bb490456b7 (patch) | |
tree | 73ebeba061fde907454361a8d51e7f9ddadbaa81 /Source/CPack/cpack.cxx | |
parent | 9d0f86d7d017aa00420800bd72e00d45681710c9 (diff) | |
download | CMake-bbf1c2d275ce58a76cfe5d3a6539a3bb490456b7.zip CMake-bbf1c2d275ce58a76cfe5d3a6539a3bb490456b7.tar.gz CMake-bbf1c2d275ce58a76cfe5d3a6539a3bb490456b7.tar.bz2 |
ENH: More improvements and add logging
Diffstat (limited to 'Source/CPack/cpack.cxx')
-rw-r--r-- | Source/CPack/cpack.cxx | 82 |
1 files changed, 63 insertions, 19 deletions
diff --git a/Source/CPack/cpack.cxx b/Source/CPack/cpack.cxx index dd1e244..1fbb39b 100644 --- a/Source/CPack/cpack.cxx +++ b/Source/CPack/cpack.cxx @@ -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* 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; } |