Build tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SourceFile.h 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include <vector>
  3. #include <string>
  4. #include <optional>
  5. #include "BBParser.h"
  6. #include "sys.h"
  7. class SourceFile {
  8. public:
  9. enum FileType {
  10. UNKNOWN, C, CXX,
  11. };
  12. static FileType fileTypeFrom(const std::string &name);
  13. SourceFile(
  14. std::string dir, std::string name,
  15. FileType type, BBParser::Variables vars);
  16. const std::string &dir() const { return dir_; }
  17. const std::string &name() const { return name_; }
  18. std::string path() const { return dir_ + '/' + name_; }
  19. FileType type() const { return type_; }
  20. const BBParser::Variables &vars() const { return vars_; }
  21. std::string objectPath(const std::string &outDir) const;
  22. const std::vector<std::string> *variable(const std::string &name) const;
  23. const std::vector<std::string> &compileFlags() const;
  24. std::vector<std::string> ldFlags() const;
  25. std::vector<std::string> ldLibs() const;
  26. std::vector<std::string> dependencies() const;
  27. bool needsRecompile(const std::string &outDir) const;
  28. void compile(const std::string &outDir) const;
  29. std::vector<std::string> compileCommand(const std::string &outDir) const;
  30. private:
  31. std::string dir_;
  32. std::string name_;
  33. FileType type_;
  34. BBParser::Variables vars_;
  35. // Compile flags are cached, because they're used multiple times
  36. mutable std::vector<std::string> compileFlags_;
  37. mutable bool hasCompileFlags_ = false;
  38. };