Add support for project.description and project.languages

vcpkg-wip
Duncan Ogilvie 4 years ago
parent 206c658294
commit 105e0aaeb9

@ -11,8 +11,12 @@ cmake_minimum_required(VERSION 2.8...3.8)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(cmkr_PROJECT_VERSION 0.1.3)
project(cmkr VERSION ${cmkr_PROJECT_VERSION})
project(cmkr
LANGUAGES
CXX
VERSION 0.1.3
DESCRIPTION "CMakeLists generator from TOML"
)
add_subdirectory(third_party)

@ -4,6 +4,8 @@ minimum = "2.8...3.8"
[project]
name = "cmkr"
version = "0.1.3"
description = "CMakeLists generator from TOML"
languages = ["CXX"]
cmake-after = "add_subdirectory(third_party)"
[target.cmkrlib]

@ -64,6 +64,8 @@ CMake::CMake(const std::string &path, bool build) {
const auto &project = toml::find(toml, "project");
project_name = toml::find(project, "name").as_string();
project_version = toml::find_or(project, "version", "");
project_description = toml::find_or(project, "description", "");
project_languages = optional_array(project, "languages");
cmake_before = toml::find_or(project, "cmake-before", "");
cmake_after = toml::find_or(project, "cmake-after", "");
include_before = optional_array(project, "include-before");

@ -92,6 +92,8 @@ struct CMake {
std::vector<std::string> build_args;
std::string project_name;
std::string project_version;
std::string project_description;
std::vector<std::string> project_languages;
std::string cmake_before;
std::string cmake_after;
std::vector<std::string> include_before;

@ -121,6 +121,15 @@ struct CommandEndl {
void endl() { ss << '\n'; }
};
template <typename T>
struct NamedArg {
std::string name;
T value;
NamedArg() = default;
NamedArg(std::string name, T value) : name(std::move(name)), value(std::move(value)) {}
};
// Credit: JustMagic
struct Command {
std::stringstream &ss;
@ -158,11 +167,12 @@ struct Command {
return result;
}
const char *indent(int n) {
std::string indent(int n) {
std::string result;
for (int i = 0; i < n; i++) {
ss << '\t';
result += '\t';
}
return "";
return result;
}
template <class T>
@ -205,6 +215,32 @@ struct Command {
return true;
}
template <class K>
bool print_arg(const std::pair<K, std::vector<std::string>> &kv) {
if (kv.second.empty()) {
return true;
}
ss << '\n';
ss << indent(depth + 1) << kv.first << '\n';
for (const auto &s : kv.second) {
ss << indent(depth + 2) << quote(s) << '\n';
}
return true;
}
template <class K, class V>
bool print_arg(const std::pair<K, V> &kv) {
if (kv.second.empty()) {
return true;
}
ss << indent(depth + 1) << kv.first << ' ' << quote(kv.second) << '\n';
return true;
}
template <class T>
bool print_arg(const T &value) {
if (first_arg) {
@ -320,11 +356,11 @@ int generate_cmake(const char *path, bool root) {
ss << "\")\n\n";
}
if (!cmake.project_name.empty() && !cmake.project_version.empty()) {
auto name = cmake.project_name;
auto version = cmake.project_version;
cmd("set")(name + "_PROJECT_VERSION", version);
cmd("project")(name, "VERSION", "${" + name + "_PROJECT_VERSION}").endl();
if (!cmake.project_name.empty()) {
auto languages = std::make_pair("LANGUAGES", cmake.project_languages);
auto version = std::make_pair("VERSION", cmake.project_version);
auto description = std::make_pair("DESCRIPTION", cmake.project_description);
cmd("project")(cmake.project_name, languages, version, description).endl();
}
if (!cmake.cmake_after.empty()) {

Loading…
Cancel
Save