siplasplas
A library for C++ reflection and introspection
target.hpp
1 #ifndef SIPLASPLAS_CMAKE_TARGET_HPP
2 #define SIPLASPLAS_CMAKE_TARGET_HPP
3 
4 #include <siplasplas/signals/emitter.hpp>
5 #include <siplasplas/fswatch/fslistener.hpp>
6 #include <siplasplas/cmake/export.hpp>
7 #include <memory>
8 
9 namespace cpp
10 {
11 
12 class CMakeProject;
13 
32 class SIPLASPLAS_CMAKE_EXPORT CMakeTarget : public cpp::SignalEmitter
33 {
34 public:
51  struct Metadata
52  {
53  std::string name;
54  std::string sourceDir;
55  std::string binaryDir;
56  std::vector<std::string> sources;
57  std::vector<std::string> includeDirs;
58  std::string binary;
59  std::string binaryDebug;
60  std::string binaryRelease;
61 
82  static Metadata loadFromFile(const CMakeProject& project, const std::string& targetName);
83  };
84 
97  CMakeTarget(CMakeProject& project, const Metadata& metadata);
98 
99 
108  static CMakeTarget loadFromFile(CMakeProject& project, const std::string& file);
109 
117  void build();
118 
121 
125  void buildStarted(){}
126 
132  void buildFinished(bool successful){}
133 
144  void stdoutLine(const std::string& line){}
145 
151  void reloadBinary(const std::string& binary){}
153 
161  const Metadata& metadata() const;
162 
168  const std::string& name() const;
169 
170 private:
171  const Metadata _metadata;
172  CMakeProject& _project;
173  std::vector<efsw::WatchID> _inputWatches;
174  std::vector<efsw::WatchID> _outputWatches;
175  bool _building;
176 
177  void onFileChanged(efsw::WatchID watchId, const std::string& dir, const std::string& fileName);
178  static void filterErroredWatches(std::vector<efsw::WatchID>& watches);
179 };
180 
181 }
182 
183 #include <reflection/include/siplasplas/cmake/target.hpp>
184 
185 #endif // SIPLASPLAS_CMAKE_TARGET_HPP
Configures and builds an existing CMake project.
Definition: project.hpp:58
void buildFinished(bool successful)
Target build has finished.
Definition: target.hpp:132
void buildStarted()
Target build has started.
Definition: target.hpp:125
Class that can send and receive signals from other emitters.
Definition: emitter.hpp:66
Definition: canary_allocator.hpp:7
std::string binaryRelease
Definition: target.hpp:60
Represents a CMake target being watched by a project.
Definition: target.hpp:32
void stdoutLine(const std::string &line)
stdout line feed from target build.
Definition: target.hpp:144
Represents the set of properties that define a target.
Definition: target.hpp:51
void reloadBinary(const std::string &binary)
A binary artifact has changed and should be reloaded.
Definition: target.hpp:151