aboutsummaryrefslogtreecommitdiff
path: root/backend/ninja/Ninja.hpp
blob: ea73c81487d668c1894564168fb4a880ab39efe2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef BACKEND_NINJA_HPP
#define BACKEND_NINJA_HPP

#include "../../include/Dependency.hpp"
#include "../../include/Result.hpp"
#include "../../include/Linker.hpp"
#include "../../include/Conf.hpp"
#include <vector>
#include <string>
#include <functional>


namespace backend
{
    class Ninja
    {
    public:
        enum class LibraryType
        {
            EXECUTABLE,
            STATIC,
            DYNAMIC,
        };

        Ninja(LibraryType libraryType = LibraryType::EXECUTABLE);

        void addSourceFile(const char *filepath);
        void addTestSourceDir(const char *dir);
        void addDependency(const std::string &binaryFile);
        const std::vector<std::string>& getSourceFiles() const;
        sibs::Result<bool> build(const sibs::SibsConfig &config, const char *savePath, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc = nullptr, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback = nullptr);
    private:
        sibs::Result<bool> buildTests(const std::string &projectGeneratedBinary);
        bool containsSourceFile(const std::string &filepath) const;
        bool containsTestSourceDir(const std::string &dir) const;
        bool containsDependency(const std::string &dependency) const;
        sibs::Result<bool> getLinkerFlags(const std::vector<sibs::Dependency> &dependencies, sibs::LinkerFlagCallbackFunc staticLinkerFlagCallbackFunc, sibs::LinkerFlagCallbackFunc dynamicLinkerFlagCallback) const;
        sibs::Result<bool> build(const char *buildFilePath);
    private:
        std::vector<std::string> sourceFiles;
        std::vector<std::string> testSourceDirs;
        std::vector<std::string> binaryDependencies;
        LibraryType libraryType;
    };
}

#endif //BACKEND_NINJA_HPP