cpack.cxx 19.7 KB
Newer Older
1
2
3
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4

5
6
  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.
7

8
9
10
11
  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
12
13
14
15
16
#include "cmSystemTools.h"

// Need these for documentation support.
#include "cmake.h"
#include "cmDocumentation.h"
17
#include "cmCPackDocumentVariables.h"
Bill Hoffman's avatar
Bill Hoffman committed
18
#include "cmCPackGeneratorFactory.h"
Bill Hoffman's avatar
Bill Hoffman committed
19
#include "cmCPackGenerator.h"
20
21
22
23
#include "cmake.h"
#include "cmGlobalGenerator.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
24

25
26
#include "cmCPackLog.h"

27
#include <cmsys/CommandLineArguments.hxx>
28
#include <cmsys/SystemTools.hxx>
29
30

//----------------------------------------------------------------------------
31
static const char * cmDocumentationName[][3] =
32
{
33
34
35
  {0,
   "  cpack - Packaging driver provided by CMake.", 0},
  {0,0,0}
36
37
38
};

//----------------------------------------------------------------------------
39
static const char * cmDocumentationUsage[][3] =
40
{
41
  {0,
42
   "  cpack -G <generator> [options]",
43
44
   0},
  {0,0,0}
45
46
47
};

//----------------------------------------------------------------------------
48
static const char * cmDocumentationOptions[][3] =
49
50
{
    {"-G <generator>", "Use the specified generator to generate package.",
Andy Cedilnik's avatar
Andy Cedilnik committed
51
52
53
54
    "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." },
55
    {"-C <Configuration>", "Specify the project configuration",
Andy Cedilnik's avatar
Andy Cedilnik committed
56
57
    "This option specifies the configuration that the project was build "
      "with, for example 'Debug', 'Release'." },
58
59
    {"-D <var>=<value>", "Set a CPack variable.", \
    "Set a variable that can be used by the generator."}, \
60
61
62
    {"--config <config file>", "Specify the config file.",
    "Specify the config file to use to create the package. By default "
      "CPackConfig.cmake in the current directory will be used." },
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    {"--verbose,-V","enable verbose output","Run cpack with verbose output."},
    {"--debug","enable debug output (for CPack developers)",
     "Run cpack with debug output (for CPack developers)."},
    {"-P <package name>","override/define CPACK_PACKAGE_NAME",
     "If the package name is not specified on cpack commmand line then"
     "CPack.cmake defines it as CMAKE_PROJECT_NAME"},
    {"-R <package version>","override/define CPACK_PACKAGE_VERSION",
     "If version is not specified on cpack command line then"
     "CPack.cmake defines it from CPACK_PACKAGE_VERSION_[MAJOR|MINOR|PATCH]"
     "look into CPack.cmake for detail"},
    {"-B <package directory>","override/define CPACK_PACKAGE_DIRECTORY",
     "The directory where CPack will be doing its packaging work."
     "The resulting package will be found there. Inside this directory"
     "CPack creates '_CPack_Packages' sub-directory which is the"
     "CPack temporary directory."},
    {"--vendor <vendor name>","override/define CPACK_PACKAGE_VENDOR",
     "If vendor is not specified on cpack command line "
     "(or inside CMakeLists.txt) then"
     "CPack.cmake defines it with a default value"},
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
    {"--help-command cmd [file]", "Print help for a single command and exit.",
    "Full documentation specific to the given command is displayed. "
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
    "page, HTML, DocBook and plain text."},
    {"--help-command-list [file]", "List available commands and exit.",
     "The list contains all commands for which help may be obtained by using "
     "the --help-command argument followed by a command name. "
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
    "page, HTML, DocBook and plain text."},
    {"--help-commands [file]", "Print help for all commands and exit.",
     "Full documentation specific for all current command is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
    "page, HTML, DocBook and plain text."},
    {"--help-variable var [file]",
     "Print help for a single variable and exit.",
     "Full documentation specific to the given variable is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
    "page, HTML, DocBook and plain text."},
    {"--help-variable-list [file]", "List documented variables and exit.",
     "The list contains all variables for which help may be obtained by using "
     "the --help-variable argument followed by a variable name.  If a file is "
     "specified, the help is written into it."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
     "page, HTML, DocBook and plain text."},
    {"--help-variables [file]", "Print help for all variables and exit.",
     "Full documentation for all variables is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
    "page, HTML, DocBook and plain text."},
116
    {0,0,0}
117
118
119
120
121
122
123
124
125
};

//----------------------------------------------------------------------------
int cpackUnknownArgument(const char*, void*)
{
  return 1;
}

//----------------------------------------------------------------------------
126
127
128
struct cpackDefinitions
{
  typedef std::map<cmStdString, cmStdString> MapType;
Andy Cedilnik's avatar
Andy Cedilnik committed
129
130
  MapType Map;
  cmCPackLog *Log;
131
};
132
133

//----------------------------------------------------------------------------
Andy Cedilnik's avatar
Andy Cedilnik committed
134
int cpackDefinitionArgument(const char* argument, const char* cValue,
135
  void* call_data)
136
137
{
  (void)argument;
138
  cpackDefinitions* def = static_cast<cpackDefinitions*>(call_data);
139
140
141
142
  std::string value = cValue;
  size_t pos = value.find_first_of("=");
  if ( pos == std::string::npos )
    {
Andy Cedilnik's avatar
Andy Cedilnik committed
143
    cmCPack_Log(def->Log, cmCPackLog::LOG_ERROR,
144
      "Please specify CPack definitions as: KEY=VALUE" << std::endl);
145
146
147
148
    return 0;
    }
  std::string key = value.substr(0, pos);
  value = value.c_str() + pos + 1;
Andy Cedilnik's avatar
Andy Cedilnik committed
149
150
  def->Map[key] = value;
  cmCPack_Log(def->Log, cmCPackLog::LOG_DEBUG, "Set CPack variable: "
151
    << key.c_str() << " to \"" << value.c_str() << "\"" << std::endl);
152
153
154
  return 1;
}

155

156
157
158
159
//----------------------------------------------------------------------------
// this is CPack.
int main (int argc, char *argv[])
{
160
  cmSystemTools::FindExecutableDirectory(argv[0]);
161
  cmCPackLog log;
162

163
164
165
  log.SetErrorPrefix("CPack Error: ");
  log.SetWarningPrefix("CPack Warning: ");
  log.SetOutputPrefix("CPack: ");
166
  log.SetVerbosePrefix("CPack Verbose: ");
167

168
169
170
171
  cmSystemTools::EnableMSVCDebugHook();

  if ( cmSystemTools::GetCurrentWorkingDirectory().size() == 0 )
    {
172
173
    cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
      "Current working directory cannot be established." << std::endl);
174
    return 1;
175
176
177
178
179
    }

  std::string generator;
  bool help = false;
  bool helpVersion = false;
180
181
  bool verbose = false;
  bool debug = false;
182
183
184
185
186
  std::string helpFull;
  std::string helpMAN;
  std::string helpHTML;

  std::string cpackProjectName;
187
  std::string cpackProjectDirectory;
188
189
190
191
  std::string cpackBuildConfig;
  std::string cpackProjectVersion;
  std::string cpackProjectPatch;
  std::string cpackProjectVendor;
192
193
194
  std::string cpackConfigFile;

  cpackDefinitions definitions;
Andy Cedilnik's avatar
Andy Cedilnik committed
195
  definitions.Log = &log;
196

197
  cpackConfigFile = "";
198
199
200
201
202
203

  cmsys::CommandLineArguments arg;
  arg.Initialize(argc, argv);
  typedef cmsys::CommandLineArguments argT;
  // Help arguments
  arg.AddArgument("--help", argT::NO_ARGUMENT, &help, "CPack help");
Andy Cedilnik's avatar
Andy Cedilnik committed
204
205
206
207
  arg.AddArgument("--help-full", argT::SPACE_ARGUMENT, &helpFull,
    "CPack help");
  arg.AddArgument("--help-html", argT::SPACE_ARGUMENT, &helpHTML,
    "CPack help");
208
209
210
  arg.AddArgument("--help-man", argT::SPACE_ARGUMENT, &helpMAN, "CPack help");
  arg.AddArgument("--version", argT::NO_ARGUMENT, &helpVersion, "CPack help");

211
212
213
  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");
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  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");
  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, &definitions, "CPack Definitions");
232
233
  arg.SetUnknownArgumentCallback(cpackUnknownArgument);

234
  // Parse command line
235
236
  int parsed = arg.Parse();

237
238
239
240
  // Setup logging
  if ( verbose )
    {
    log.SetVerbose(verbose);
241
    cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Verbose" << std::endl);
242
243
244
245
246
247
248
    }
  if ( debug )
    {
    log.SetDebug(debug);
    cmCPack_Log(&log, cmCPackLog::LOG_OUTPUT, "Enable Debug" << std::endl);
    }

249
250
  cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
    "Read CPack config file: " << cpackConfigFile.c_str() << std::endl);
251

252
  cmake cminst;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
253
  cminst.RemoveUnscriptableCommands();
254
255
  cmGlobalGenerator cmgg;
  cmgg.SetCMakeInstance(&cminst);
256
  cmsys::auto_ptr<cmLocalGenerator> cmlg(cmgg.CreateLocalGenerator());
257
  cmMakefile* globalMF = cmlg->GetMakefile();
258
259
260
261
262

  bool cpackConfigFileSpecified = true;
  if ( cpackConfigFile.empty() )
    {
    cpackConfigFile = cmSystemTools::GetCurrentWorkingDirectory();
263
    cpackConfigFile += "/CPackConfig.cmake";
264
265
    cpackConfigFileSpecified = false;
    }
266

Bill Hoffman's avatar
Bill Hoffman committed
267
  cmCPackGeneratorFactory generators;
268
  generators.SetLogger(&log);
Bill Hoffman's avatar
Bill Hoffman committed
269
  cmCPackGenerator* cpackGenerator = 0;
270

271
272
  cmDocumentation doc;
  doc.addCPackStandardDocSections();
273
274
275
276
277
  /* Were we invoked to display doc or to do some work ?
   * Unlike cmake launching cpack with zero argument
   * should launch cpack using "cpackConfigFile" if it exists
   * in the current directory.
   */
278
  if((doc.CheckOptions(argc, argv,"-G")) && !(argc==1))
279
    {
280
281
282
283
284
      help = true;
    }
  else
    {
      help = false;
285
286
    }

287
288
  // This part is used for cpack documentation lookup as well.
  cminst.AddCMakePaths();
Alexander Neundorf's avatar
 
Alexander Neundorf committed
289

290
291
  if ( parsed && !help )
    {
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
    // find out which system cpack is running on, so it can setup the search
    // paths, so FIND_XXX() commands can be used in scripts
    std::string systemFile =
      globalMF->GetModulesFile("CMakeDetermineSystem.cmake");
    if (!globalMF->ReadListFile(0, systemFile.c_str()))
      {
      cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
        "Error reading CMakeDetermineSystem.cmake" << std::endl);
      return 1;
      }

    systemFile =
      globalMF->GetModulesFile("CMakeSystemSpecificInformation.cmake");
    if (!globalMF->ReadListFile(0, systemFile.c_str()))
      {
      cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
        "Error reading CMakeSystemSpecificInformation.cmake" << std::endl);
      return 1;
      }

312
    if ( cmSystemTools::FileExists(cpackConfigFile.c_str()) )
313
      {
314
      cpackConfigFile =
Ken Martin's avatar
Ken Martin committed
315
        cmSystemTools::CollapseFullPath(cpackConfigFile.c_str());
316
317
318
319
      cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
        "Read CPack configuration file: " << cpackConfigFile.c_str()
        << std::endl);
      if ( !globalMF->ReadListFile(0, cpackConfigFile.c_str()) )
320
        {
321
        cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
Alexander Neundorf's avatar
 
Alexander Neundorf committed
322
          "Problem reading CPack config file: \""
323
          << cpackConfigFile.c_str() << "\"" << std::endl);
324
325
        return 1;
        }
326
327
328
      }
    else if ( cpackConfigFileSpecified )
      {
329
330
331
      cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
        "Cannot find CPack config file: \"" << cpackConfigFile.c_str()
        << "\"" << std::endl);
332
333
334
      return 1;
      }

335
336
    if ( !generator.empty() )
      {
337
      globalMF->AddDefinition("CPACK_GENERATOR", generator.c_str());
338
339
340
      }
    if ( !cpackProjectName.empty() )
      {
341
      globalMF->AddDefinition("CPACK_PACKAGE_NAME", cpackProjectName.c_str());
342
343
344
      }
    if ( !cpackProjectVersion.empty() )
      {
Andy Cedilnik's avatar
Andy Cedilnik committed
345
346
      globalMF->AddDefinition("CPACK_PACKAGE_VERSION",
        cpackProjectVersion.c_str());
347
348
349
      }
    if ( !cpackProjectVendor.empty() )
      {
Andy Cedilnik's avatar
Andy Cedilnik committed
350
351
      globalMF->AddDefinition("CPACK_PACKAGE_VENDOR",
        cpackProjectVendor.c_str());
352
      }
353
354
    // if this is not empty it has been set on the command line
    // go for it. Command line override values set in config file.
355
356
    if ( !cpackProjectDirectory.empty() )
      {
357
      globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY",
358
359
360
361
362
363
364
365
366
367
368
369
370
                              cpackProjectDirectory.c_str());
      }
    // The value has not been set on the command line
    else
      {
      // get a default value (current working directory)
      cpackProjectDirectory = cmsys::SystemTools::GetCurrentWorkingDirectory();
      // use default value iff no value has been provided by the config file
      if (!globalMF->IsSet("CPACK_PACKAGE_DIRECTORY"))
        {
        globalMF->AddDefinition("CPACK_PACKAGE_DIRECTORY",
                                cpackProjectDirectory.c_str());
        }
371
372
373
      }
    if ( !cpackBuildConfig.empty() )
      {
374
      globalMF->AddDefinition("CPACK_BUILD_CONFIG", cpackBuildConfig.c_str());
375
      }
376
    cpackDefinitions::MapType::iterator cdit;
Andy Cedilnik's avatar
Andy Cedilnik committed
377
378
    for ( cdit = definitions.Map.begin();
      cdit != definitions.Map.end();
379
      ++cdit )
380
      {
381
      globalMF->AddDefinition(cdit->first.c_str(), cdit->second.c_str());
382
383
      }

Brad King's avatar
Brad King committed
384
385
    const char* cpackModulesPath =
      globalMF->GetDefinition("CPACK_MODULE_PATH");
386
387
388
389
    if ( cpackModulesPath )
      {
      globalMF->AddDefinition("CMAKE_MODULE_PATH", cpackModulesPath);
      }
390
391
    const char* genList = globalMF->GetDefinition("CPACK_GENERATOR");
    if ( !genList )
392
      {
393
394
      cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
        "CPack generator not specified" << std::endl);
Andy Cedilnik's avatar
Andy Cedilnik committed
395
      parsed = 0;
396
      }
Andy Cedilnik's avatar
Andy Cedilnik committed
397
    else
398
      {
Andy Cedilnik's avatar
Andy Cedilnik committed
399
400
401
402
403
404
405
      std::vector<std::string> generatorsVector;
      cmSystemTools::ExpandListArgument(genList,
        generatorsVector);
      std::vector<std::string>::iterator it;
      for ( it = generatorsVector.begin();
        it != generatorsVector.end();
        ++it )
406
        {
Andy Cedilnik's avatar
Andy Cedilnik committed
407
408
409
        const char* gen = it->c_str();
        cmMakefile newMF(*globalMF);
        cmMakefile* mf = &newMF;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
410
411
412
413
414
415
416
417
        cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE,
          "Specified generator: " << gen << std::endl);
        if ( parsed && !mf->GetDefinition("CPACK_PACKAGE_NAME") )
          {
          cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
            "CPack project name not specified" << std::endl);
          parsed = 0;
          }
418
419
420
421
422
        if (parsed &&
            !(mf->GetDefinition("CPACK_PACKAGE_VERSION") ||
              (mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR") &&
               mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR") &&
               mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH"))))
423
          {
Alexander Neundorf's avatar
 
Alexander Neundorf committed
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
          cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
            "CPack project version not specified" << std::endl
            << "Specify CPACK_PACKAGE_VERSION, or "
            "CPACK_PACKAGE_VERSION_MAJOR, "
            "CPACK_PACKAGE_VERSION_MINOR, and CPACK_PACKAGE_VERSION_PATCH."
            << std::endl);
          parsed = 0;
          }
        if ( parsed )
          {
          cpackGenerator = generators.NewGenerator(gen);
          if ( !cpackGenerator )
            {
            cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
              "Cannot initialize CPack generator: "
Alexander Neundorf's avatar
 
Alexander Neundorf committed
439
              << gen << std::endl);
Alexander Neundorf's avatar
 
Alexander Neundorf committed
440
441
            parsed = 0;
            }
Bill Hoffman's avatar
Bill Hoffman committed
442
          if ( parsed && !cpackGenerator->Initialize(gen, mf) )
443
444
            {
            cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
Alexander Neundorf's avatar
 
Alexander Neundorf committed
445
              "Cannot initialize the generator " << gen << std::endl);
446
447
            parsed = 0;
            }
Alexander Neundorf's avatar
 
Alexander Neundorf committed
448
449
450
451

          if ( !mf->GetDefinition("CPACK_INSTALL_COMMANDS") &&
            !mf->GetDefinition("CPACK_INSTALLED_DIRECTORIES") &&
            !mf->GetDefinition("CPACK_INSTALL_CMAKE_PROJECTS") )
452
453
            {
            cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
Alexander Neundorf's avatar
 
Alexander Neundorf committed
454
455
456
457
              "Please specify build tree of the project that uses CMake "
              "using CPACK_INSTALL_CMAKE_PROJECTS, specify "
              "CPACK_INSTALL_COMMANDS, or specify "
              "CPACK_INSTALLED_DIRECTORIES."
Andy Cedilnik's avatar
Andy Cedilnik committed
458
              << std::endl);
459
460
            parsed = 0;
            }
Andy Cedilnik's avatar
Andy Cedilnik committed
461
          if ( parsed )
462
            {
Alexander Neundorf's avatar
 
Alexander Neundorf committed
463
464
465
466
467
468
469
470
471
472
473
#ifdef _WIN32
            std::string comspec = "cmw9xcom.exe";
            cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
#endif

            const char* projName = mf->GetDefinition("CPACK_PACKAGE_NAME");
            cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "Use generator: "
              << cpackGenerator->GetNameOfClass() << std::endl);
            cmCPack_Log(&log, cmCPackLog::LOG_VERBOSE, "For project: "
              << projName << std::endl);

474
            const char* projVersion =
Alexander Neundorf's avatar
 
Alexander Neundorf committed
475
476
              mf->GetDefinition("CPACK_PACKAGE_VERSION");
            if ( !projVersion )
Andy Cedilnik's avatar
Andy Cedilnik committed
477
              {
Alexander Neundorf's avatar
 
Alexander Neundorf committed
478
479
480
481
482
483
484
485
486
              const char* projVersionMajor
                = mf->GetDefinition("CPACK_PACKAGE_VERSION_MAJOR");
              const char* projVersionMinor
                = mf->GetDefinition("CPACK_PACKAGE_VERSION_MINOR");
              const char* projVersionPatch
                = mf->GetDefinition("CPACK_PACKAGE_VERSION_PATCH");
              cmOStringStream ostr;
              ostr << projVersionMajor << "." << projVersionMinor << "."
                << projVersionPatch;
487
              mf->AddDefinition("CPACK_PACKAGE_VERSION",
Alexander Neundorf's avatar
 
Alexander Neundorf committed
488
                                ostr.str().c_str());
Andy Cedilnik's avatar
Andy Cedilnik committed
489
490
              }

491
            int res = cpackGenerator->DoPackage();
Alexander Neundorf's avatar
 
Alexander Neundorf committed
492
            if ( !res )
Andy Cedilnik's avatar
Andy Cedilnik committed
493
494
              {
              cmCPack_Log(&log, cmCPackLog::LOG_ERROR,
Alexander Neundorf's avatar
 
Alexander Neundorf committed
495
496
                "Error when generating package: " << projName << std::endl);
              return 1;
Andy Cedilnik's avatar
Andy Cedilnik committed
497
              }
498
499
            }
          }
500
        }
Andy Cedilnik's avatar
Andy Cedilnik committed
501
502
      }
    }
503

504
505
506
507
  /* In this case we are building the documentation object
   * instance in order to create appropriate structure
   * in order to satisfy the appropriate --help-xxx request
   */
Alexander Neundorf's avatar
 
Alexander Neundorf committed
508
  if ( help )
Andy Cedilnik's avatar
Andy Cedilnik committed
509
510
    {
    // Construct and print requested documentation.
511

Andy Cedilnik's avatar
Andy Cedilnik committed
512
    doc.SetName("cpack");
513
514
    doc.SetSection("Name",cmDocumentationName);
    doc.SetSection("Usage",cmDocumentationUsage);
515
    doc.PrependSection("Options",cmDocumentationOptions);
Andy Cedilnik's avatar
Andy Cedilnik committed
516
517

    std::vector<cmDocumentationEntry> v;
Bill Hoffman's avatar
Bill Hoffman committed
518
    cmCPackGeneratorFactory::DescriptionsMap::const_iterator generatorIt;
Andy Cedilnik's avatar
Andy Cedilnik committed
519
520
521
522
523
    for( generatorIt = generators.GetGeneratorsList().begin();
      generatorIt != generators.GetGeneratorsList().end();
      ++ generatorIt )
      {
      cmDocumentationEntry e;
524
525
526
      e.Name = generatorIt->first.c_str();
      e.Brief = generatorIt->second.c_str();
      e.Full = "";
Andy Cedilnik's avatar
Andy Cedilnik committed
527
528
      v.push_back(e);
      }
529
    doc.SetSection("Generators",v);
530

531
#undef cout
Andy Cedilnik's avatar
Andy Cedilnik committed
532
    return doc.PrintRequestedDocumentation(std::cout)? 0:1;
533
#define cout no_cout_use_cmCPack_Log
534
535
    }

536
537
538
539
540
  if (cmSystemTools::GetErrorOccuredFlag())
    {
    return 1;
    }

541
542
  return 0;
}