siplasplas
A library for C++ reflection and introspection
|
Configures and builds an existing CMake project. More...
#include <siplasplas/cmake/project.hpp>
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... | |
CMakeTarget & | addTarget (const std::string &name) |
Adds a target to the set of project watched targets. More... | |
CMakeTarget & | addTarget (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::FileSystemListener & | fileSystemListener () |
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 | |
SignalEmitter & | operator= (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 SignalSink > | connect (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 SignalSink > | connect (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 SignalSink > | connect_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 SignalSink > | connect_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 SignalSink > | bypass (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 SignalSink > | bypass_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) |
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.
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.
sourceDir | Path to the project source directory |
binaryDir | Path to the project binary directory |
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).
binaryDir | Relative path to the subtree to watch (Relative to the project binary directory). |
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.
sourceDir | Relative path to the subtree to watch (Relative to the project source directory). |
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.
sourceDir | Relative path to the subtree to watch (Relative to the project source directory). |
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.
name | Name of the target to add to the project. |
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.
metadata | Properties of the target to watch. |
const std::string& cpp::CMakeProject::binaryDir | ( | ) | const |
Returns the project binary directory.
|
inline |
A target build has finished.
target | Name of the target built. |
successful | True if the build was successful. False otherwise. |
|
inline |
A target build started.
target | Name of the target being built. |
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.
targetName | name 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.
|
inline |
Project configuration has finished.
successful | True 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.
const std::string& cpp::CMakeProject::sourceDir | ( | ) | const |
Returns 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.
|
inline |
stdout line feed from target build.
This signal is emitted for each line sent to stdout during a target build process.
targetName | Name of the target being build. |
line | Line from build process stdout. |