throw when no cmake.toml is found

self-hosting
MoAlyousef 4 years ago
parent b64d5a370d
commit 7ec2279a77

@ -1,6 +1,7 @@
#include "cmake.hpp" #include "cmake.hpp"
#include <filesystem> #include <filesystem>
#include <stdexcept>
#include <toml.hpp> #include <toml.hpp>
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -19,7 +20,9 @@ std::vector<std::string> to_string_vec(
} // namespace detail } // namespace detail
CMake::CMake(const std::string &path, bool build) { CMake::CMake(const std::string &path, bool build) {
if (fs::exists(fs::path(path) / "cmake.toml")) { if (!fs::exists(fs::path(path) / "cmake.toml")) {
throw std::runtime_error("No cmake.toml was found!");
}
if (build) { if (build) {
const auto toml = toml::parse("cmake.toml"); const auto toml = toml::parse("cmake.toml");
if (toml.contains("cmake")) { if (toml.contains("cmake")) {
@ -92,8 +95,7 @@ CMake::CMake(const std::string &path, bool build) {
} }
if (bin.contains("link-libs")) { if (bin.contains("link-libs")) {
b.link_libs = b.link_libs = detail::to_string_vec(toml::find(bin, "link-libs").as_array());
detail::to_string_vec(toml::find(bin, "link-libs").as_array());
} }
if (bin.contains("features")) { if (bin.contains("features")) {
@ -107,6 +109,5 @@ CMake::CMake(const std::string &path, bool build) {
} }
} }
} }
}
} }
} // namespace cmkr::cmake } // namespace cmkr::cmake

Loading…
Cancel
Save