Introduce "generator expressions" to add_test()
[cmake.git] / Source / cmProcessTools.h
blob00321e6eede0afebb23d3f948f5b6a2f16a51abd
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmProcessTools.h,v $
5 Language: C++
6 Date: $Date: 2009-07-10 15:07:27 $
7 Version: $Revision: 1.3 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #ifndef cmProcessTools_h
18 #define cmProcessTools_h
20 #include "cmStandardIncludes.h"
22 /** \class cmProcessTools
23 * \brief Helper classes for process output parsing
26 class cmProcessTools
28 public:
29 /** Abstract interface for process output parsers. */
30 class OutputParser
32 public:
33 /** Process the given output data from a tool. Processing may be
34 done incrementally. Returns true if the parser is interested
35 in any more data and false if it is done. */
36 bool Process(const char* data, int length)
37 { return this->ProcessChunk(data, length); }
38 bool Process(const char* data)
39 { return this->Process(data, static_cast<int>(strlen(data))); }
41 virtual ~OutputParser() {}
42 protected:
43 /** Implement in a subclass to process a chunk of data. It should
44 return true only if it is interested in more data. */
45 virtual bool ProcessChunk(const char* data, int length) = 0;
48 /** Process output parser that extracts one line at a time. */
49 class LineParser: public OutputParser
51 public:
52 /** Construct with line separation character and choose whether to
53 ignore carriage returns. */
54 LineParser(char sep = '\n', bool ignoreCR = true);
56 /** Configure logging of lines as they are extracted. */
57 void SetLog(std::ostream* log, const char* prefix);
58 protected:
59 char Separator;
60 bool IgnoreCR;
61 std::ostream* Log;
62 const char* Prefix;
63 std::string Line;
64 virtual bool ProcessChunk(const char* data, int length);
66 /** Implement in a subclass to process one line of input. It
67 should return true only if it is interested in more data. */
68 virtual bool ProcessLine() = 0;
71 /** Trivial line handler for simple logging. */
72 class OutputLogger: public LineParser
74 public:
75 OutputLogger(std::ostream& log, const char* prefix = 0)
76 { this->SetLog(&log, prefix); }
77 private:
78 virtual bool ProcessLine() { return true; }
81 /** Run a process and send output to given parsers. */
82 static void RunProcess(struct cmsysProcess_s* cp,
83 OutputParser* out, OutputParser* err = 0);
86 #endif