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.

78 lines
2.1KB

  1. #pragma once
  2. #include <dds/util/fs.hpp>
  3. #include <optional>
  4. #include <string>
  5. #include <string_view>
  6. #include <vector>
  7. namespace dds {
  8. std::vector<std::string> split_shell_string(std::string_view s);
  9. enum class language {
  10. automatic,
  11. c,
  12. cxx,
  13. };
  14. struct compile_file_spec {
  15. fs::path source_path;
  16. fs::path out_path;
  17. std::vector<std::string> definitions = {};
  18. std::vector<fs::path> include_dirs = {};
  19. language lang = language::automatic;
  20. bool enable_warnings = false;
  21. };
  22. struct archive_spec {
  23. std::vector<fs::path> input_files;
  24. fs::path out_path;
  25. };
  26. struct link_exe_spec {
  27. std::vector<fs::path> inputs;
  28. fs::path output;
  29. };
  30. struct toolchain_prep;
  31. class toolchain {
  32. using string_seq = std::vector<std::string>;
  33. string_seq _c_compile;
  34. string_seq _cxx_compile;
  35. string_seq _inc_template;
  36. string_seq _def_template;
  37. string_seq _link_archive;
  38. string_seq _link_exe;
  39. string_seq _warning_flags;
  40. std::string _archive_prefix;
  41. std::string _archive_suffix;
  42. std::string _object_prefix;
  43. std::string _object_suffix;
  44. std::string _exe_prefix;
  45. std::string _exe_suffix;
  46. public:
  47. toolchain() = default;
  48. static toolchain realize(const toolchain_prep&);
  49. auto& archive_suffix() const noexcept { return _archive_suffix; }
  50. auto& object_suffix() const noexcept { return _object_suffix; }
  51. auto& executable_suffix() const noexcept { return _exe_suffix; }
  52. std::vector<std::string> definition_args(std::string_view s) const noexcept;
  53. std::vector<std::string> include_args(const fs::path& p) const noexcept;
  54. std::vector<std::string> create_compile_command(const compile_file_spec&) const noexcept;
  55. std::vector<std::string> create_archive_command(const archive_spec&) const noexcept;
  56. std::vector<std::string> create_link_executable_command(const link_exe_spec&) const noexcept;
  57. static std::optional<toolchain> get_builtin(std::string_view key) noexcept;
  58. };
  59. } // namespace dds