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.

68 lines
2.0KB

  1. #pragma once
  2. #include <dds/build/plan/base.hpp>
  3. #include <dds/source.hpp>
  4. #include <dds/toolchain/deps.hpp>
  5. #include <memory>
  6. namespace dds {
  7. struct compile_failure : std::runtime_error {
  8. using runtime_error::runtime_error;
  9. };
  10. class shared_compile_file_rules {
  11. struct rules_impl {
  12. std::vector<fs::path> inc_dirs;
  13. std::vector<std::string> defs;
  14. bool enable_warnings = false;
  15. };
  16. std::shared_ptr<rules_impl> _impl = std::make_shared<rules_impl>();
  17. public:
  18. shared_compile_file_rules() = default;
  19. auto clone() const noexcept {
  20. auto cp = *this;
  21. cp._impl = std::make_shared<rules_impl>(*_impl);
  22. return cp;
  23. }
  24. auto& include_dirs() noexcept { return _impl->inc_dirs; }
  25. auto& include_dirs() const noexcept { return _impl->inc_dirs; }
  26. auto& defs() noexcept { return _impl->defs; }
  27. auto& defs() const noexcept { return _impl->defs; }
  28. auto& enable_warnings() noexcept { return _impl->enable_warnings; }
  29. auto& enable_warnings() const noexcept { return _impl->enable_warnings; }
  30. };
  31. class compile_file_plan {
  32. shared_compile_file_rules _rules;
  33. source_file _source;
  34. std::string _qualifier;
  35. fs::path _subdir;
  36. public:
  37. compile_file_plan(shared_compile_file_rules rules,
  38. source_file sf,
  39. std::string_view qual,
  40. path_ref subdir)
  41. : _rules(rules)
  42. , _source(std::move(sf))
  43. , _qualifier(qual)
  44. , _subdir(subdir) {}
  45. compile_command_info generate_compile_command(build_env_ref) const noexcept;
  46. const source_file& source() const noexcept { return _source; }
  47. path_ref source_path() const noexcept { return _source.path; }
  48. fs::path calc_object_file_path(build_env_ref env) const noexcept;
  49. std::optional<deps_info> compile(build_env_ref) const;
  50. };
  51. } // namespace dds