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

Configures and builds an existing CMake project. More...

#include <siplasplas/cmake/project.hpp>

Inheritance diagram for cpp::CMakeProject:
cpp::SignalEmitter

Public Member Functions

 CMakeProject (const std::string &sourceDir, const std::string &binaryDir)
 Creates a cmake project given its source and build directories. More...
 
void configure ()
 Configures the cmake project. More...
 
void buildTarget (const std::string &targetName)
 Builds the given target. More...
 
CMakeTargetaddTarget (const std::string &name)
 Adds a target to the set of project watched targets. More...
 
CMakeTargetaddTarget (const CMakeTarget::Metadata &metadata)
 Adds a target to the set of project watched targets. More...
 
efsw::WatchID addSourceDirWatch (const std::string &sourceDir)
 Registers a watch to a subtree of the source directory in the project internal filesystem watcher. More...
 
efsw::WatchID addIncludeDirWatch (const std::string &includeDir)
 Registers a watch to a subtree of the source directory in the project internal filesystem watcher. The directory is an include directory. More...
 
efsw::WatchID addBinaryDirWatch (const std::string &binaryDir)
 Registers a watch to a subtree of the binary directory in the project internal filesystem watcher. More...
 
void startWatch ()
 Starts target watching. More...
 
cpp::FileSystemListenerfileSystemListener ()
 Returns a reference to the internal filesystem listener. More...
 
const std::string & sourceDir () const
 Returns the project source directory. More...
 
const std::string & binaryDir () const
 Returns the project binary directory. More...
 
signals
void configureFinished (bool successful)
 Project configuration has finished. More...
 
void buildStarted (const std::string &target)
 A target build started. More...
 
void buildFinished (const std::string &target, bool successful)
 A target build has finished. More...
 
void stdoutLine (const std::string &targetName, const std::string &line)
 stdout line feed from target build. More...
 
- Public Member Functions inherited from cpp::SignalEmitter
 SignalEmitter (SignalEmitter &&)=default
 
SignalEmitteroperator= (SignalEmitter &&)=default
 
void poll ()
 Polls this object for incomming signal emissions. More...
 

Additional Inherited Members

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

Detailed Description

Configures and builds an existing CMake project.

CMakeProject class handles an existing CMake project given its source and build directories. The project can be configured and built manually (See CMakeProject::configure() and CMakeProject::buildTarget() functions) or targets can be registered to be watched and rebuilt on source changes.

The class notifies project events through signals, such as when the configuration finished, a target build started, etc.

Examples:
cmake/cmake-project.cpp.

Constructor & Destructor Documentation

cpp::CMakeProject::CMakeProject ( const std::string &  sourceDir,
const std::string &  binaryDir 
)

Creates a cmake project given its source and build directories.

Source and build directories are inmutable and can only be set during construction. Once the cmake project is initialized, target watching is not launched by default and no targets are registered.

Parameters
sourceDirPath to the project source directory
binaryDirPath to the project binary directory

Member Function Documentation

efsw::WatchID cpp::CMakeProject::addBinaryDirWatch ( const std::string &  binaryDir)

Registers a watch to a subtree of the binary directory in the project internal filesystem watcher.

This function is invoked by CMakeTarget instances as part of their initialization to watch for changes in target build artifacts (Binaries, cache files, etc).

Parameters
binaryDirRelative path to the subtree to watch (Relative to the project binary directory).
Returns
a filesystem watch ID representing the watch (See fswatch).
efsw::WatchID cpp::CMakeProject::addIncludeDirWatch ( const std::string &  includeDir)

Registers a watch to a subtree of the source directory in the project internal filesystem watcher. The directory is an include directory.

This function is invoked by CMakeTarget instances as part of their initialization to watch for target include directories changes.

Parameters
sourceDirRelative path to the subtree to watch (Relative to the project source directory).
Returns
a filesystem watch ID representing the watch (See fswatch).
efsw::WatchID cpp::CMakeProject::addSourceDirWatch ( const std::string &  sourceDir)

Registers a watch to a subtree of the source directory in the project internal filesystem watcher.

This function is invoked by CMakeTarget instances as part of their initialization to watch for target source changes.

Parameters
sourceDirRelative path to the subtree to watch (Relative to the project source directory).
Returns
a filesystem watch ID representing the watch (See fswatch).
CMakeTarget& cpp::CMakeProject::addTarget ( const std::string &  name)

Adds a target to the set of project watched targets.

This function enables watching of target <name>. The target properties are loaded from a <\p name>.json file in the root of the project binary dir (See CMakeTarget::Metadata::loadFromFile()). Passing the name of a target that does not belong to the project has undefined behavior (Loading of properties from JSON file may fail). After starting watch (See CMakeTarget::startWatch()) the target is rebuilt automaticallly whenever a source change occurs.

Parameters
nameName of the target to add to the project.
Returns
A CMakeTarget reference representing the target to watch.
Examples:
cmake/cmake-project.cpp.
CMakeTarget& cpp::CMakeProject::addTarget ( const CMakeTarget::Metadata metadata)

Adds a target to the set of project watched targets.

This function enables watching of a target. Passing properties of a target that does not belong to the project has undefined behavior. After starting watch (See CMakeTarget::startWatch()) the target is rebuilt automaticallly whenever a source change occurs.

Parameters
metadataProperties of the target to watch.
Returns
A CMakeTarget reference representing the target to watch.
const std::string& cpp::CMakeProject::binaryDir ( ) const

Returns the project binary directory.

Returns
Full path to the project binary directory.
void cpp::CMakeProject::buildFinished ( const std::string &  target,
bool  successful 
)
inline

A target build has finished.

Parameters
targetName of the target built.
successfulTrue if the build was successful. False otherwise.
Examples:
cmake/cmake-project.cpp.
void cpp::CMakeProject::buildStarted ( const std::string &  target)
inline

A target build started.

Parameters
targetName of the target being built.
Examples:
cmake/cmake-project.cpp.
void cpp::CMakeProject::buildTarget ( const std::string &  targetName)

Builds the given target.

Invokes "cmake --build <binary dir> --target <target name>" command.

The signal CMakeProject::stdoutLine() is emitted for every line sent to stdout from the cmake process. When the build finishes, CMakeProject::buildFinished() signal is emitted.

Parameters
targetNamename of the target to build.
void cpp::CMakeProject::configure ( )

Configures the cmake project.

Invokes "cmake <source dir>" command from the project binary dir. The signal CMakeProject::configureFinished(bool) is emitted when the configuration finishes.

void cpp::CMakeProject::configureFinished ( bool  successful)
inline

Project configuration has finished.

Parameters
successfulTrue if the configuration was successful. False otherwise.
cpp::FileSystemListener& cpp::CMakeProject::fileSystemListener ( )

Returns a reference to the internal filesystem listener.

This function is invoked by CMakeTargets to listen to changes on sources and include directories. Both the fs watcher and the listener are unique to the project.

Returns
A reference to the internal FileSystemListener listening to project changes.
const std::string& cpp::CMakeProject::sourceDir ( ) const

Returns the project source directory.

Returns
Full path to the project source directory.
void cpp::CMakeProject::startWatch ( )

Starts target watching.

This function starts the internal filesystem watcher. Whenever a file event occurs, the internal filesystem watcher notifies registered targets, and them filter and react to events accordingly. Targets are directly-connected to the fs watcher (See SignalEmitter::connect()) so all target events (And their resulting actions) are processed and signaled from the watcher background thread.

Examples:
cmake/cmake-project.cpp.
void cpp::CMakeProject::stdoutLine ( const std::string &  targetName,
const std::string &  line 
)
inline

stdout line feed from target build.

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

Todo:
Rename to "buildProcessStdout() or something similar.
Parameters
targetNameName of the target being build.
lineLine from build process stdout.
Examples:
cmake/cmake-project.cpp.

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