siplasplas
A library for C++ reflection and introspection
cpp::CMakeTarget Class Reference

Represents a CMake target being watched by a project. More...

#include <siplasplas/cmake/target.hpp>

Inheritance diagram for cpp::CMakeTarget:
cpp::SignalEmitter

Classes

struct  Metadata
 Represents the set of properties that define a target. More...
 

Public Member Functions

 CMakeTarget (CMakeProject &project, const Metadata &metadata)
 Creates a CMakeTarget. More...
 
void build ()
 Build the target. More...
 
const Metadatametadata () const
 Returns the target properties. More...
 
const std::string & name () const
 Returns the name of the target. More...
 
signals
void buildStarted ()
 Target build has started.
 
void buildFinished (bool successful)
 Target build has finished. More...
 
void stdoutLine (const std::string &line)
 stdout line feed from target build. More...
 
void reloadBinary (const std::string &binary)
 A binary artifact has changed and should be reloaded. More...
 
- Public Member Functions inherited from cpp::SignalEmitter
 SignalEmitter (SignalEmitter &&)=default
 
SignalEmitteroperator= (SignalEmitter &&)=default
 
void poll ()
 Polls this object for incomming signal emissions. More...
 

Static Public Member Functions

static CMakeTarget loadFromFile (CMakeProject &project, const std::string &file)
 Loads a target from a file. See CMakeTarget::Metadata::loadFromFile(). More...
 
- Static Public Member Functions inherited from cpp::SignalEmitter
template<typename Caller , typename Function , typename R , typename Class , typename... Args>
static std::shared_ptr< const SignalSinkconnect (Caller &caller, R(Class::*source)(Args...), Function function)
 Creates a direct connection from the given emitter object to the given function. More...
 
template<typename Caller , typename Callee , typename Function , typename R , typename Class , typename... Args>
static std::shared_ptr< const SignalSinkconnect (Caller &caller, R(Class::*source)(Args...), Callee &callee, Function function)
 Creates a direct connection from the given emitter object to the given function, using an specific callee object. More...
 
template<typename Caller , typename Function , typename R , typename Class , typename... Args>
static std::shared_ptr< const SignalSinkconnect_async (Caller &caller, R(Class::*source)(Args...), Function function)
 Creates an asynchronous connection between a signal and a function. More...
 
template<typename Caller , typename Callee , typename Function , typename R , typename Class , typename... Args>
static std::shared_ptr< const SignalSinkconnect_async (Caller &caller, R(Class::*source)(Args...), Callee &callee, Function function)
 Creates an asynchronous connection between a signal and a function using an specific callee object. More...
 
template<typename Caller , typename Callee , typename R , typename... Args>
static std::shared_ptr< const SignalSinkbypass (Caller &caller, R(Caller::*source)(Args...), Callee &callee, R(Callee::*dest)(Args...))
 Connects two signals synchronously. More...
 
template<typename Caller , typename Callee , typename R , typename... Args>
static std::shared_ptr< const SignalSinkbypass_async (Caller &caller, R(Caller::*source)(Args...), Callee &callee, R(Callee::*dest)(Args...))
 Connects two signals asynchronously. More...
 
template<typename Class , typename R , typename... FArgs, typename... Args>
static void emit (Class &emitter, R(Class::*function)(FArgs...), Args &&...args)
 Emits a signal on the given emitter. More...
 

Additional Inherited Members

- Protected Member Functions inherited from cpp::SignalEmitter
template<typename Function , typename... Args>
void invoke (Function function, Args &&...args)
 

Detailed Description

Represents a CMake target being watched by a project.

This class represents a CMake target that is registred in a CMakeProject for being watched and rebuilt automatically if any of its sources changes. This class has signals that notify target events (Build started, finished, etc) equivalent to those on CMakeProject but which are emitted for this target only (i.e. are not global to the project).

Todo:
This class is highly coupled with the CMakeProject one. Maybe it should be an implementation detail of CMakeTarget class instead, or at least a member class. Creating targets isolated from projects has no sense (And is actually error-prone since targets are not registred in projects during their construction, registration is handled by CMakeProject::addTarget() functions).

Constructor & Destructor Documentation

cpp::CMakeTarget::CMakeTarget ( CMakeProject project,
const Metadata metadata 
)

Creates a CMakeTarget.

During their initialization targets add the different source watches and connect for corresponding events in the project filesystem watcher. The target is not registered in the project set, so we suggest to never create isolated targets and call CMakeProject::addTarget() instead. (See CMakeTarget TODO).

Parameters
projectReference to the CMakeProject the target belongs to.
metadataTarget properties.

Member Function Documentation

void cpp::CMakeTarget::build ( )

Build the target.

This function invokes CMakeProject::build(<target name>). CMakeTarget::buildStarted() signal is emitted just after the build process starts. When the build process ends, CMakeTarget::buildFinished() is emitted with the result of the build.

void cpp::CMakeTarget::buildFinished ( bool  successful)
inline

Target build has finished.

Parameters
successfulTrue if the build was successful. False otherwise.
Examples:
cmake/cmake-project.cpp.
static CMakeTarget cpp::CMakeTarget::loadFromFile ( CMakeProject project,
const std::string &  file 
)
static

Loads a target from a file. See CMakeTarget::Metadata::loadFromFile().

Parameters
projectReference to the CMake project the target belongs to.
fileJSON file containing target properties.
Returns
A CMakeTarget instance with the properties read from the file.
const Metadata& cpp::CMakeTarget::metadata ( ) const

Returns the target properties.

Todo:
Rename to "properties".
Returns
Const reference to the target properties.
const std::string& cpp::CMakeTarget::name ( ) const

Returns the name of the target.

Returns
String containing the name of the target.
void cpp::CMakeTarget::reloadBinary ( const std::string &  binary)
inline

A binary artifact has changed and should be reloaded.

Parameters
binaryFull path to the binary artifact.
Examples:
cmake/cmake-project.cpp.
void cpp::CMakeTarget::stdoutLine ( const std::string &  line)
inline

stdout line feed from target build.

This signal is emitted for each line sent to stdout during a build process.

Todo:
Rename to "buildProcessStdout() or something similar.
Parameters
lineLine from build process stdout.

The documentation for this class was generated from the following file: