|
|
@ -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,92 +20,92 @@ 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")) {
|
|
|
|
if (build) {
|
|
|
|
throw std::runtime_error("No cmake.toml was found!");
|
|
|
|
const auto toml = toml::parse("cmake.toml");
|
|
|
|
}
|
|
|
|
if (toml.contains("cmake")) {
|
|
|
|
if (build) {
|
|
|
|
const auto &cmake = toml::find(toml, "cmake");
|
|
|
|
const auto toml = toml::parse("cmake.toml");
|
|
|
|
|
|
|
|
if (toml.contains("cmake")) {
|
|
|
|
if (cmake.contains("bin-dir")) {
|
|
|
|
const auto &cmake = toml::find(toml, "cmake");
|
|
|
|
bin_dir = toml::find(cmake, "bin-dir").as_string();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("generator")) {
|
|
|
|
|
|
|
|
generator = toml::find(cmake, "generator").as_string();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("arguments")) {
|
|
|
|
if (cmake.contains("bin-dir")) {
|
|
|
|
gen_args = detail::to_string_vec(toml::find(cmake, "arguments").as_array());
|
|
|
|
bin_dir = toml::find(cmake, "bin-dir").as_string();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const auto toml = toml::parse((fs::path(path) / "cmake.toml").string());
|
|
|
|
|
|
|
|
if (toml.contains("cmake")) {
|
|
|
|
|
|
|
|
const auto &cmake = toml::find(toml, "cmake");
|
|
|
|
|
|
|
|
cmake_version = toml::find(cmake, "minimum").as_string();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("cpp-flags")) {
|
|
|
|
|
|
|
|
cppflags = detail::to_string_vec(toml::find(cmake, "cpp-flags").as_array());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("c-flags")) {
|
|
|
|
if (cmake.contains("generator")) {
|
|
|
|
cflags = detail::to_string_vec(toml::find(cmake, "c-flags").as_array());
|
|
|
|
generator = toml::find(cmake, "generator").as_string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("link-flags")) {
|
|
|
|
|
|
|
|
linkflags = detail::to_string_vec(toml::find(cmake, "link-flags").as_array());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("subdirs")) {
|
|
|
|
if (cmake.contains("arguments")) {
|
|
|
|
subdirs = detail::to_string_vec(toml::find(cmake, "subdirs").as_array());
|
|
|
|
gen_args = detail::to_string_vec(toml::find(cmake, "arguments").as_array());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const auto toml = toml::parse((fs::path(path) / "cmake.toml").string());
|
|
|
|
|
|
|
|
if (toml.contains("cmake")) {
|
|
|
|
|
|
|
|
const auto &cmake = toml::find(toml, "cmake");
|
|
|
|
|
|
|
|
cmake_version = toml::find(cmake, "minimum").as_string();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmake.contains("cpp-flags")) {
|
|
|
|
|
|
|
|
cppflags = detail::to_string_vec(toml::find(cmake, "cpp-flags").as_array());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (toml.contains("project")) {
|
|
|
|
if (cmake.contains("c-flags")) {
|
|
|
|
const auto &project = toml::find(toml, "project");
|
|
|
|
cflags = detail::to_string_vec(toml::find(cmake, "c-flags").as_array());
|
|
|
|
proj_name = toml::find(project, "name").as_string();
|
|
|
|
|
|
|
|
proj_version = toml::find(project, "version").as_string();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (toml.contains("find-package")) {
|
|
|
|
if (cmake.contains("link-flags")) {
|
|
|
|
using pkg_map = std::map<std::string, std::string>;
|
|
|
|
linkflags = detail::to_string_vec(toml::find(cmake, "link-flags").as_array());
|
|
|
|
packages = toml::find<pkg_map>(toml, "find-package");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (toml.contains("fetch-content")) {
|
|
|
|
if (cmake.contains("subdirs")) {
|
|
|
|
using content_map = std::map<std::string, std::map<std::string, std::string>>;
|
|
|
|
subdirs = detail::to_string_vec(toml::find(cmake, "subdirs").as_array());
|
|
|
|
contents = toml::find<content_map>(toml, "fetch-content");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (toml.contains("project")) {
|
|
|
|
|
|
|
|
const auto &project = toml::find(toml, "project");
|
|
|
|
|
|
|
|
proj_name = toml::find(project, "name").as_string();
|
|
|
|
|
|
|
|
proj_version = toml::find(project, "version").as_string();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (toml.contains("bin")) {
|
|
|
|
if (toml.contains("find-package")) {
|
|
|
|
const auto &bins = toml::find(toml, "bin").as_array();
|
|
|
|
using pkg_map = std::map<std::string, std::string>;
|
|
|
|
|
|
|
|
packages = toml::find<pkg_map>(toml, "find-package");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &bin : bins) {
|
|
|
|
if (toml.contains("fetch-content")) {
|
|
|
|
Bin b;
|
|
|
|
using content_map = std::map<std::string, std::map<std::string, std::string>>;
|
|
|
|
b.name = toml::find(bin, "name").as_string();
|
|
|
|
contents = toml::find<content_map>(toml, "fetch-content");
|
|
|
|
b.type = toml::find(bin, "type").as_string();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
b.sources = detail::to_string_vec(toml::find(bin, "sources").as_array());
|
|
|
|
if (toml.contains("bin")) {
|
|
|
|
|
|
|
|
const auto &bins = toml::find(toml, "bin").as_array();
|
|
|
|
|
|
|
|
|
|
|
|
if (bin.contains("include-dirs")) {
|
|
|
|
for (const auto &bin : bins) {
|
|
|
|
b.include_dirs =
|
|
|
|
Bin b;
|
|
|
|
detail::to_string_vec(toml::find(bin, "include-dirs").as_array());
|
|
|
|
b.name = toml::find(bin, "name").as_string();
|
|
|
|
}
|
|
|
|
b.type = toml::find(bin, "type").as_string();
|
|
|
|
|
|
|
|
|
|
|
|
if (bin.contains("link-libs")) {
|
|
|
|
b.sources = detail::to_string_vec(toml::find(bin, "sources").as_array());
|
|
|
|
b.link_libs =
|
|
|
|
|
|
|
|
detail::to_string_vec(toml::find(bin, "link-libs").as_array());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bin.contains("features")) {
|
|
|
|
if (bin.contains("include-dirs")) {
|
|
|
|
b.features = detail::to_string_vec(toml::find(bin, "features").as_array());
|
|
|
|
b.include_dirs =
|
|
|
|
}
|
|
|
|
detail::to_string_vec(toml::find(bin, "include-dirs").as_array());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bin.contains("link-libs")) {
|
|
|
|
|
|
|
|
b.link_libs = detail::to_string_vec(toml::find(bin, "link-libs").as_array());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (bin.contains("features")) {
|
|
|
|
|
|
|
|
b.features = detail::to_string_vec(toml::find(bin, "features").as_array());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bin.contains("defines")) {
|
|
|
|
if (bin.contains("defines")) {
|
|
|
|
b.defines = detail::to_string_vec(toml::find(bin, "defines").as_array());
|
|
|
|
b.defines = detail::to_string_vec(toml::find(bin, "defines").as_array());
|
|
|
|
}
|
|
|
|
|
|
|
|
binaries.push_back(b);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
binaries.push_back(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|