#pragma once #include #include #include #include #include "breeze/Project.hpp" /// A project's modules: the directories under source/ (and source/tests/, source/examples/) that /// each register one CMake target with one of the SDK's add_*_module macros. They are read from the /// CMakeLists.txt files themselves, so what the CLI shows is what CMake will do, and the files it /// writes are the ones a person would have written. namespace breeze { enum class ModuleKind { Exec, Lib, Obj, Test, Example }; enum class LibType { Unspecified, Static, Shared }; /// "exec", "lib", "obj", "test" or "example". std::string kindName(ModuleKind kind); struct Module { /// The CMake target: what DEPENDS, `breeze run` and `breeze deps` call it. std::string id; /// The directory's name. std::string dirName; std::filesystem::path dir; ModuleKind kind = ModuleKind::Exec; LibType libType = LibType::Unspecified; std::string outputName; std::vector deps; /// The macro that registered it, e.g. add_lib_module. std::string macro; }; /// Every module, main ones first (by directory name), then tests, then examples. std::vector scanModules(const Project& project); /// By id, else by directory name. Null when there is no such module. const Module* findModule(const std::vector& modules, const std::string& idOrDir); struct NewModule { ModuleKind kind = ModuleKind::Exec; std::string name; std::optional id; std::vector deps; LibType libType = LibType::Unspecified; }; /// Creates the module's directory, CMakeLists.txt and starter files. Throws Error on anything /// it would have to guess about or overwrite. Module addModule(const Project& project, const NewModule& request); /// Removes the module's directory. Refuses while another module still depends on it. void deleteModule(const Project& project, const std::string& idOrDir); struct RenameResult { std::string oldId; std::string newId; std::string oldDir; std::string newDir; /// Modules whose CMakeLists.txt had a DEPENDS entry updated. std::vector updatedDependents; }; /// Renames the directory and/or the id, and rewrites DEPENDS entries elsewhere to the new id. RenameResult renameModule(const Project& project, const std::string& idOrDir, const std::optional& newName, const std::optional& newId); /// What `module` depends on, without repeats, in the order met (nearest first). Entries that /// are not modules of the project (fmt::fmt, pthread) are included as they were written. std::vector dependenciesOf(const std::vector& modules, const Module& module, bool recursive); /// The modules that depend on `module`, directly or (recursive) through others. std::vector dependentsOf(const std::vector& modules, const Module& module, bool recursive); }