cmDocumentation.h 5.56 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
#ifndef _cmDocumentation_h
#define _cmDocumentation_h

#include "cmStandardIncludes.h"
Alexander Neundorf's avatar
 
Alexander Neundorf committed
16
#include "cmProperty.h"
Alexander Neundorf's avatar
 
Alexander Neundorf committed
17
18
#include "cmDocumentationFormatter.h"
#include "cmDocumentationFormatterHTML.h"
19
#include "cmDocumentationFormatterDocbook.h"
Alexander Neundorf's avatar
 
Alexander Neundorf committed
20
#include "cmDocumentationFormatterMan.h"
21
#include "cmDocumentationFormatterRST.h"
Alexander Neundorf's avatar
 
Alexander Neundorf committed
22
23
#include "cmDocumentationFormatterText.h"
#include "cmDocumentationFormatterUsage.h"
24
#include "cmDocumentationSection.h"
25
#include "cmake.h"
Alexander Neundorf's avatar
 
Alexander Neundorf committed
26

Alexander Neundorf's avatar
 
Alexander Neundorf committed
27
28
29
30
31
namespace cmsys
{
  class Directory;
}

32
/** Class to generate documentation.  */
Alexander Neundorf's avatar
 
Alexander Neundorf committed
33
class cmDocumentation: public cmDocumentationEnums
34
35
36
{
public:
  cmDocumentation();
37

38
  ~cmDocumentation();
39

40
41
  /**
   * Check command line arguments for documentation options.  Returns
42
43
   * true if documentation options are found, and false otherwise.
   * When true is returned, PrintRequestedDocumentation should be
44
   * called.  exitOpt can be used for things like cmake -E, so that
45
46
   * all arguments after the -E are ignored and not searched for
   * help arguments.
47
   */
48
  bool CheckOptions(int argc, const char* const* argv,
49
                    const char* exitOpt =0);
50

51
52
53
54
55
56
57
  /**
   * Print help requested on the command line.  Call after
   * CheckOptions returns true.  Returns true on success, and false
   * otherwise.  Failure can occur when output files specified on the
   * command line cannot be written.
   */
  bool PrintRequestedDocumentation(std::ostream& os);
58

59
  /** Print help of the given type.  */
60
  bool PrintDocumentation(Type ht, std::ostream& os);
61
62

  void SetShowGenerators(bool showGen) { this->ShowGenerators = showGen; }
63

64
  /** Set the program name for standard document generation.  */
65
66
  void SetName(const char* name);

67
  /** Set a section of the documentation. Typical sections include Name,
68
      Usage, Description, Options */
69
70
71
72
73
74
75
76
  void SetSection(const char *sectionName,
                  cmDocumentationSection *section);
  void SetSection(const char *sectionName,
                  std::vector<cmDocumentationEntry> &docs);
  void SetSection(const char *sectionName,
                  const char *docs[][3]);
  void SetSections(std::map<std::string,cmDocumentationSection *>
                   &sections);
77

78
79
80
  /** Add the documentation to the beginning/end of the section */
  void PrependSection(const char *sectionName,
                      const char *docs[][3]);
81
82
83
84
  void PrependSection(const char *sectionName,
                      std::vector<cmDocumentationEntry> &docs);
  void PrependSection(const char *sectionName,
                      cmDocumentationEntry &docs);
85
86
87
88
  void AppendSection(const char *sectionName,
                     const char *docs[][3]);
  void AppendSection(const char *sectionName,
                     std::vector<cmDocumentationEntry> &docs);
89
90
  void AppendSection(const char *sectionName,
                     cmDocumentationEntry &docs);
91

92
93
94
95
  /**
   * Print documentation in the given form.  All previously added
   * sections will be generated.
   */
96
  void Print(Form f, int manSection, std::ostream& os);
97

98
99
100
101
102
103
  /**
   * Print documentation in the current form.  All previously added
   * sections will be generated.
   */
  void Print(std::ostream& os);

104
  /**
105
106
   * Add a section of documentation. This can be used to generate custom help
   * documents.
107
   */
108
109
  void AddSectionToPrint(const char *section);

110
  /** Clear all previously added sections of help.  */
111
112
  void ClearSections();

113
114
  /** Set cmake root so we can find installed files */
  void SetCMakeRoot(const char* root)  { this->CMakeRoot = root;}
Alexander Neundorf's avatar
 
Alexander Neundorf committed
115

116
117
  static Form GetFormFromFilename(const std::string& filename,
                                  int* ManSection);
Alexander Neundorf's avatar
 
Alexander Neundorf committed
118

119
120
121
122
123
124
125
126
127
128
129
130
  /** Add common (to all tools) documentation section(s) */
  void addCommonStandardDocSections();

  /** Add the CMake standard documentation section(s) */
  void addCMakeStandardDocSections();

  /** Add the CTest standard documentation section(s) */
  void addCTestStandardDocSections();

  /** Add the CPack standard documentation section(s) */
  void addCPackStandardDocSections();

131
private:
132
  void SetForm(Form f, int manSection);
133

134
135
  bool PrintVersion(std::ostream& os);
  bool PrintDocumentationUsage(std::ostream& os);
136

137
138
  const char* GetNameString() const;
  bool IsOption(const char* arg) const;
139

140
141
  bool ShowGenerators;

142
  std::string NameString;
143
  std::map<std::string,cmDocumentationSection*> AllSections;
144

145
  std::string CMakeRoot;
146
  std::vector<const cmDocumentationSection *> PrintSections;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
147
148
149
150
  std::string CurrentArgument;

  struct RequestedHelpItem
  {
151
    RequestedHelpItem():HelpForm(TextForm), HelpType(None), ManSection(1) {}
Alexander Neundorf's avatar
 
Alexander Neundorf committed
152
153
    cmDocumentationEnums::Form HelpForm;
    cmDocumentationEnums::Type HelpType;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
154
155
    std::string Filename;
    std::string Argument;
156
    int ManSection;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
157
158
159
  };

  std::vector<RequestedHelpItem> RequestedHelpItems;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
160
161
  cmDocumentationFormatter* CurrentFormatter;
  cmDocumentationFormatterHTML HTMLFormatter;
162
  cmDocumentationFormatterDocbook DocbookFormatter;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
163
  cmDocumentationFormatterMan ManFormatter;
164
  cmDocumentationFormatterRST RSTFormatter;
Alexander Neundorf's avatar
 
Alexander Neundorf committed
165
166
  cmDocumentationFormatterText TextFormatter;
  cmDocumentationFormatterUsage UsageFormatter;
167
168
169
};

#endif