cmMakefile.h 5.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) 2000 National Library of Medicine
  All rights reserved.

  See COPYRIGHT.txt for copyright details.

=========================================================================*/
/**
17
18
 * cmMakefile - used to parse and store the contents of a
 * CMakeLists.txt makefile in memory.
19
20
21
 */
#ifndef cmMakefile_h
#define cmMakefile_h
22
#include "cmStandardIncludes.h"
23
#include "cmClassFile.h"
24
25
26
27
#include "cmSystemTools.h"
class cmRuleMaker;
class cmMakefileGenerator;

28
29
30
31
32

class cmMakefile
{
public:
  cmMakefile();
33
34
35
36
37
38
39
40
41
42
  ~cmMakefile();
  // Parse a CMakeLists.txt file
  bool ReadMakefile(const char* makefile, bool inheriting = false); 
  // Add a wrap generator 
  void AddRuleMaker(cmRuleMaker* );
  // Set the make file 
  void SetMakefileGenerator(cmMakefileGenerator*);
  // Generate the output file
  void GenerateMakefile();
  
43
44
  // Print useful stuff to stdout
  void Print();
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  
  // cmRuleMaker interfaces
  void AddCustomRule(const char* source,
                     const char* result,
                     const char* command,
                     std::vector<std::string>& depends);
  void AddDefineFlag(const char* definition);
  void AddExecutable(cmClassFile&);
  void AddLinkLibrary(const char*);
  void AddLinkDirectory(const char*);
  void AddSubDirectory(const char*);
  void AddIncludeDirectory(const char*);
  void AddDefinition(const char* name, const char* value);
  void SetProjectName(const char*);
  void SetLibraryName(const char*);
  void AddClass(cmClassFile& );
  void AddExtraDirectory(const char* dir);
  
63
64
65
66
  // Set the home directory for the project
  void SetHomeDirectory(const char* dir) 
    {
      m_cmHomeDirectory = dir;
67
      cmSystemTools::ConvertToUnixSlashes(m_cmHomeDirectory);
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
    }
  const char* GetHomeDirectory() 
    {
      return m_cmHomeDirectory.c_str();
    }
  // Set the current directory in the project
  void SetCurrentDirectory(const char* dir) 
    {
      m_cmCurrentDirectory = dir;
    }
  const char* GetCurrentDirectory() 
    {
      return m_cmCurrentDirectory.c_str();
    }
  // Set the name of the library that is built by this makefile
  const char* GetLibraryName()
    {
      return m_LibraryName.c_str();
    }
87

88
89
90
91
  const char* GetProjectName()
    {
      return m_ProjectName.c_str();
    }
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  
  // Set the name of the library that is built by this makefile
  void SetOutputDirectory(const char* lib)
    {
      m_OutputDirectory = lib;
    }
  const char* GetOutputDirectory()
    {
      return m_OutputDirectory.c_str();
    }
  
  // Set the name of the library that is built by this makefile
  void SetOutputHomeDirectory(const char* lib)
    {
      m_OutputHomeDirectory = lib;
    }
  const char* GetOutputHomeDirectory()
    {
      return m_OutputHomeDirectory.c_str();
    }
112
113
114
115
  const std::vector<std::string>& GetSubDirectories()
    { 
      return m_SubDirectories;
    }
116
  
117
118
119
120
121
  bool HasExecutables() 
    {
      return m_Executables;
    }
  
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  std::vector<std::string>& GetIncludeDirectories()
    { 
      return m_IncludeDirectories;
    }
  
  std::vector<std::string>& GetLinkDirectories()
    { 
      return m_LinkDirectories;
    }
  
  std::vector<std::string>& GetLinkLibraries()
    { 
      return m_LinkLibraries;
    }
  
  std::vector<std::string>& GetLinkLibrariesWin32()
    { 
      return m_LinkLibrariesWin32;
    }
  
  std::vector<std::string>& GetLinkLibrariesUnix()
    { 
      return m_LinkLibrariesUnix;
    }
  std::vector<cmClassFile>& GetClasses(){ return  m_Classes;}
  std::vector<std::string>& GetAuxSourceDirectories()
    { return m_AuxSourceDirectories; }
  std::vector<std::string>& GetMakeVerbatim() 
    { return m_MakeVerbatim;}
  const char* GetDefinition(const char*);

  const char* GetDefineFlags()
    { return m_DefineFlags.c_str();}

156
private:
157
158
159
160
161
162
163
164
165
166
   /**
   * Look for CMakeLists.txt files to parse in dir,
   * then in dir's parents, until the SourceHome directory
   * is found.
   */
  void ParseDirectory(const char* dir);
  /**
   * Parse a file for includes links and libs
   */
  void ExpandVaribles();
167
168
  void ReadClasses(std::ifstream& fin, bool t);
  friend class cmMakeDepend;	// make depend needs direct access 
169
170
171
				// to the m_Classes array 
  void PrintStringVector(const char* s, std::vector<std::string>& v);
  void AddDefaultRules();
172
173
174
protected:
  bool m_Executables;
  std::string m_Prefix;
175
  std::vector<std::string> m_AuxSourceDirectories; // 
176
177
178
179
180
  std::string m_OutputDirectory; // Current output directory for makefile
  std::string m_OutputHomeDirectory; // Top level output directory
  std::string m_cmHomeDirectory; // Home directory for source
  std::string m_cmCurrentDirectory; // current directory in source
  std::string m_LibraryName;	// library name
181
  std::string m_ProjectName;	// project name
182
183
  std::vector<cmClassFile> m_Classes; // list of classes in makefile
  std::vector<std::string> m_SubDirectories; // list of sub directories
184
  std::vector<std::string> m_MakeVerbatim; // lines copied from input file
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  std::vector<std::string> m_IncludeDirectories;
  std::vector<std::string> m_LinkDirectories;
  std::vector<std::string> m_LinkLibraries;
  std::vector<std::string> m_LinkLibrariesWin32;
  std::vector<std::string> m_LinkLibrariesUnix;
  std::string m_DefineFlags;
  std::string m_SourceHomeDirectory;
  struct customRule
  {
    std::string m_Source;
    std::string m_Result;
    std::string m_Command;
    std::vector<std::string> m_Depends;
  };
  std::vector<customRule> m_CustomRules;
  typedef std::map<std::string, cmRuleMaker*> StringRuleMakerMap;
  typedef std::map<std::string, std::string> DefinitionMap;
  DefinitionMap m_Definitions;
  StringRuleMakerMap m_RuleMakers;
  std::vector<cmRuleMaker*> m_UsedRuleMakers;
  cmMakefileGenerator* m_MakefileGenerator;
206
207
208
209
};


#endif