mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 04905371b8 | |||
| 5a6ac44fcf | |||
| 9db82dfd05 | |||
| 459ebb14b5 | |||
| 490869b9a2 | |||
| 8ae2754994 | |||
| 18419297f4 | |||
| bdaf5c94e6 | |||
| fa3b7a346c | |||
| df1dbf7953 | |||
| 5951f6930e | |||
| a6d5f1c99b | |||
| dc852b9a2f | |||
| 66621a9818 | |||
| 2cd8ad0f18 | |||
| 084cbd6159 | |||
| b4b0f533a9 | |||
| 0acc9b4e5a | |||
| 61dfb0eb60 | |||
| 3201fd052e |
Generated
+1
-1
@@ -25,7 +25,7 @@ project(cmkr
|
||||
LANGUAGES
|
||||
CXX
|
||||
VERSION
|
||||
0.2.0
|
||||
0.2.4
|
||||
DESCRIPTION
|
||||
"CMakeLists generator from TOML"
|
||||
)
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ cmkr-include = false
|
||||
|
||||
[project]
|
||||
name = "cmkr"
|
||||
version = "0.2.0"
|
||||
version = "0.2.4"
|
||||
description = "CMakeLists generator from TOML"
|
||||
languages = ["CXX"]
|
||||
subdirs = ["third_party", "tests"]
|
||||
|
||||
+4
-4
@@ -1,5 +1,9 @@
|
||||
include_guard()
|
||||
|
||||
# Change these defaults to point to your infrastructure if desired
|
||||
set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE)
|
||||
set(CMKR_TAG "v0.2.4" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
|
||||
|
||||
# To bootstrap/generate a cmkr project: cmake -P cmkr.cmake
|
||||
if(CMAKE_SCRIPT_MODE_FILE)
|
||||
set(CMAKE_BINARY_DIR "${CMAKE_BINARY_DIR}/build")
|
||||
@@ -7,10 +11,6 @@ if(CMAKE_SCRIPT_MODE_FILE)
|
||||
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
# Change these defaults to point to your infrastructure if desired
|
||||
set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE)
|
||||
set(CMKR_TAG "v0.2.0" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
|
||||
|
||||
# Set these from the command line to customize for development/debugging purposes
|
||||
set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable")
|
||||
set(CMKR_SKIP_GENERATION OFF CACHE BOOL "skip automatic cmkr generation")
|
||||
|
||||
@@ -46,14 +46,14 @@ function(generate_documentation)
|
||||
string(REGEX MATCH "^(\n*(#[^\n]+\n)+\n*)" EXAMPLE_HEADER "${test_contents}")
|
||||
string(LENGTH "${EXAMPLE_HEADER}" header_length)
|
||||
string(STRIP "${EXAMPLE_HEADER}" EXAMPLE_HEADER)
|
||||
string(REGEX REPLACE "\n# ?" "\n" EXAMPLE_HEADER "\n${EXAMPLE_HEADER}")
|
||||
string(REGEX REPLACE "\n# ?" "\n\n" EXAMPLE_HEADER "\n${EXAMPLE_HEADER}")
|
||||
string(STRIP "${EXAMPLE_HEADER}" EXAMPLE_HEADER)
|
||||
|
||||
# Extract footer text
|
||||
string(REGEX MATCH "(((#[^\n]+)(\n+|$))+)$" EXAMPLE_FOOTER "${test_contents}")
|
||||
string(LENGTH "${EXAMPLE_FOOTER}" footer_length)
|
||||
string(STRIP "${EXAMPLE_FOOTER}" EXAMPLE_FOOTER)
|
||||
string(REGEX REPLACE "\n# ?" "\n" EXAMPLE_FOOTER "\n${EXAMPLE_FOOTER}")
|
||||
string(REGEX REPLACE "\n# ?" "\n\n" EXAMPLE_FOOTER "\n${EXAMPLE_FOOTER}")
|
||||
string(STRIP "${EXAMPLE_FOOTER}" EXAMPLE_FOOTER)
|
||||
|
||||
# Extract toml body
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
_site/
|
||||
.jekyll-metadata
|
||||
assets/
|
||||
|
||||
+21
-13
@@ -47,6 +47,8 @@ arch64 = "CMAKE_SIZEOF_VOID_P EQUALS 8"
|
||||
arch32 = "CMAKE_SIZEOF_VOID_P EQUALS 4"
|
||||
```
|
||||
|
||||
This will make the `arch64` and `arch32` conditions available with their respective CMake expressions.
|
||||
|
||||
You can also prefix most keys with `condition.` to represent a conditional:
|
||||
|
||||
```toml
|
||||
@@ -56,7 +58,7 @@ sources = ["src/main.cpp"]
|
||||
windows.sources = ["src/windows_specific.cpp"]
|
||||
```
|
||||
|
||||
This will make the `arch64` and `arch32` conditions available with their respective CMake expressions. The following conditions are predefined (you can override them if you desire):
|
||||
The following conditions are predefined (you can override them if you desire):
|
||||
|
||||
```toml
|
||||
[conditions]
|
||||
@@ -74,7 +76,7 @@ msvc = "MSVC"
|
||||
|
||||
```toml
|
||||
[subdir.mysubdir]
|
||||
condition = "linux"
|
||||
condition = "mycondition"
|
||||
cmake-before = """
|
||||
message(STATUS "CMake injected before the add_subdirectory() call"
|
||||
"""
|
||||
@@ -96,14 +98,13 @@ packages = ["fmt", "zlib"]
|
||||
|
||||
The vcpkg `version` will automatically generate the `url` from the [official repository](https://github.com/microsoft/vcpkg/releases). For a custom registry you can specify your own `url` (and omit the `version`). You can browse available packages on [vcpkg.io](https://vcpkg.io/en/packages.html).
|
||||
|
||||
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`.
|
||||
|
||||
## Packages
|
||||
|
||||
```toml
|
||||
[find-package]
|
||||
mypackage = { version = "1.0", required = true, config = true, components = ["mycomponent"] }
|
||||
|
||||
# Alternative syntax
|
||||
[find-package.mypackage]
|
||||
condition = "mycondition"
|
||||
version = "1.0"
|
||||
required = true
|
||||
config = true
|
||||
@@ -115,22 +116,27 @@ components = ["mycomponent"]
|
||||
**Note**: The `[fetch-content]` feature is unpolished and will likely change in a future release.
|
||||
|
||||
```toml
|
||||
[fetch-content]
|
||||
gitcontent = { git = "https://github.com/myuser/gitcontent", tag = "v0.1" }
|
||||
svncontent = { svn = "https://svn-host.com/url", rev = "svn_rev" }
|
||||
urlcontent = { url = "https://content-host.com/urlcontent.zip", hash = "123123123123" }
|
||||
|
||||
# Alternative syntax
|
||||
[fetch-content.gitcontent]
|
||||
condition = "mycondition"
|
||||
git = "https://github.com/myuser/gitcontent"
|
||||
tag = "v0.1"
|
||||
|
||||
[fetch-content.svncontent]
|
||||
condition = "mycondition"
|
||||
svn = "https://svn-host.com/url"
|
||||
rev = "svn_rev"
|
||||
|
||||
[fetch-content.urlcontent]
|
||||
condition = "mycondition"
|
||||
url = "https://content-host.com/urlcontent.zip"
|
||||
hash = "123123123123"
|
||||
```
|
||||
|
||||
## Targets
|
||||
|
||||
```toml
|
||||
[target.mytarget]
|
||||
condition = "linux"
|
||||
condition = "mycondition"
|
||||
alias = "mytarget::mytarget"
|
||||
type = "static" # executable, shared (DLL), static, interface, object, library, custom
|
||||
headers = ["src/mytarget.h"]
|
||||
@@ -178,6 +184,7 @@ FOLDER = "MyFolder"
|
||||
```toml
|
||||
# You can declare as many as you want like this, but the name has to be unique
|
||||
[[test]]
|
||||
condition = "mycondition"
|
||||
name = "mytest"
|
||||
command = "$<TARGET_FILE:mytest>"
|
||||
arguments = ["arg1", "arg2"]
|
||||
@@ -187,6 +194,7 @@ working-directory = "mytest-dir"
|
||||
|
||||
```toml
|
||||
[[install]]
|
||||
condition = "mycondition"
|
||||
targets = ["mytarget", "mytest"]
|
||||
destination = ["bin"]
|
||||
files = ["content/my.png"]
|
||||
|
||||
@@ -33,4 +33,6 @@ link-libraries = ["fmt::fmt"]
|
||||
|
||||
The bootstrapping of vcpkg is fully automated and no user interaction is necessary. You can disable vcpkg by setting `CMKR_DISABLE_VCPKG=ON`.
|
||||
|
||||
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`.
|
||||
|
||||
<sup><sub>This page was automatically generated from [tests/vcpkg/cmake.toml](https://github.com/build-cpp/cmkr/tree/main/tests/vcpkg/cmake.toml).</sub></sup>
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
namespace cmkr {
|
||||
namespace parser {
|
||||
|
||||
template <typename T>
|
||||
using Condition = tsl::ordered_map<std::string, T>;
|
||||
|
||||
using ConditionVector = Condition<std::vector<std::string>>;
|
||||
|
||||
struct Setting {
|
||||
std::string name;
|
||||
std::string comment;
|
||||
@@ -24,6 +29,7 @@ struct Option {
|
||||
|
||||
struct Package {
|
||||
std::string name;
|
||||
std::string condition;
|
||||
std::string version;
|
||||
bool required = true;
|
||||
bool config = false;
|
||||
@@ -33,7 +39,13 @@ struct Package {
|
||||
struct Vcpkg {
|
||||
std::string version;
|
||||
std::string url;
|
||||
std::vector<std::string> packages;
|
||||
|
||||
struct Package {
|
||||
std::string name;
|
||||
std::vector<std::string> features;
|
||||
};
|
||||
|
||||
std::vector<Package> packages;
|
||||
};
|
||||
|
||||
enum TargetType {
|
||||
@@ -46,11 +58,6 @@ enum TargetType {
|
||||
target_object,
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using Condition = tsl::ordered_map<std::string, T>;
|
||||
|
||||
using ConditionVector = Condition<std::vector<std::string>>;
|
||||
|
||||
struct Target {
|
||||
std::string name;
|
||||
TargetType type = {};
|
||||
@@ -95,6 +102,7 @@ struct Target {
|
||||
|
||||
struct Test {
|
||||
std::string name;
|
||||
std::string condition;
|
||||
std::vector<std::string> configurations;
|
||||
std::string working_directory;
|
||||
std::string command;
|
||||
@@ -102,6 +110,7 @@ struct Test {
|
||||
};
|
||||
|
||||
struct Install {
|
||||
std::string condition;
|
||||
std::vector<std::string> targets;
|
||||
std::vector<std::string> files;
|
||||
std::vector<std::string> dirs;
|
||||
@@ -120,6 +129,7 @@ struct Subdir {
|
||||
|
||||
struct Content {
|
||||
std::string name;
|
||||
std::string condition;
|
||||
tsl::ordered_map<std::string, std::string> arguments;
|
||||
};
|
||||
|
||||
|
||||
+112
-79
@@ -316,10 +316,10 @@ static std::string tolf(const std::string &str) {
|
||||
};
|
||||
|
||||
struct Generator {
|
||||
Generator(parser::Project &project) : project(project) {}
|
||||
Generator(const parser::Project &project) : project(project) {}
|
||||
Generator(const Generator &) = delete;
|
||||
|
||||
parser::Project &project;
|
||||
const parser::Project &project;
|
||||
std::stringstream ss;
|
||||
int indent = 0;
|
||||
|
||||
@@ -383,11 +383,7 @@ struct Generator {
|
||||
for (const auto &itr : value) {
|
||||
const auto &condition = itr.first;
|
||||
if (!condition.empty()) {
|
||||
if (project.conditions.count(condition) == 0) {
|
||||
// TODO: somehow print line number information here?
|
||||
throw std::runtime_error("Unknown condition '" + condition + "'");
|
||||
}
|
||||
cmd("if", condition)(RawArg(project.conditions[condition]));
|
||||
cmd("if", condition)(RawArg(project.conditions.at(condition)));
|
||||
}
|
||||
|
||||
if (!itr.second.empty()) {
|
||||
@@ -403,6 +399,27 @@ struct Generator {
|
||||
}
|
||||
};
|
||||
|
||||
struct ConditionScope {
|
||||
Generator &gen;
|
||||
bool endif = false;
|
||||
|
||||
ConditionScope(Generator &gen, const std::string &condition) : gen(gen) {
|
||||
if (!condition.empty()) {
|
||||
gen.cmd("if", condition)(RawArg(gen.project.conditions.at(condition)));
|
||||
endif = true;
|
||||
}
|
||||
}
|
||||
|
||||
ConditionScope(const ConditionScope &) = delete;
|
||||
ConditionScope(ConditionScope &&) = delete;
|
||||
|
||||
~ConditionScope() {
|
||||
if (endif) {
|
||||
gen.cmd("endif")();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static bool vcpkg_valid_identifier(const std::string &name) {
|
||||
// prn|aux|nul|con|lpt[1-9]|com[1-9]|core|default
|
||||
auto is_reserved = [](const std::string &s) {
|
||||
@@ -541,6 +558,35 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
ss << "\")\n\n";
|
||||
}
|
||||
|
||||
if (!project.options.empty()) {
|
||||
comment("Options");
|
||||
for (const auto &opt : project.options) {
|
||||
cmd("option")(opt.name, opt.comment, opt.val ? "ON" : "OFF");
|
||||
}
|
||||
endl();
|
||||
}
|
||||
|
||||
if (!project.settings.empty()) {
|
||||
comment("Settings");
|
||||
for (const auto &set : project.settings) {
|
||||
std::string set_val;
|
||||
if (set.val.index() == 1) {
|
||||
set_val = mpark::get<1>(set.val);
|
||||
} else {
|
||||
set_val = mpark::get<0>(set.val) ? "ON" : "OFF";
|
||||
}
|
||||
|
||||
if (set.cache) {
|
||||
auto typ = set.val.index() == 1 ? "STRING" : "BOOL";
|
||||
auto force = set.force ? "FORCE" : "";
|
||||
cmd("set")(set.name, set_val, typ, set.comment, force);
|
||||
} else {
|
||||
cmd("set")(set.name, set_val);
|
||||
}
|
||||
}
|
||||
endl();
|
||||
}
|
||||
|
||||
gen.handle_condition(project.include_before, [&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
||||
gen.handle_condition(project.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
||||
|
||||
@@ -554,19 +600,6 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
gen.handle_condition(project.include_after, [&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
||||
gen.handle_condition(project.cmake_after, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
||||
|
||||
if (!project.contents.empty()) {
|
||||
cmd("include")("FetchContent").endl();
|
||||
for (const auto &content : project.contents) {
|
||||
cmd("message")("STATUS", "Fetching " + content.name + "...");
|
||||
ss << "FetchContent_Declare(\n\t" << content.name << "\n";
|
||||
for (const auto &arg : content.arguments) {
|
||||
ss << "\t" << arg.first << "\n\t\t" << arg.second << "\n";
|
||||
}
|
||||
ss << ")\n";
|
||||
cmd("FetchContent_MakeAvailable")(content.name).endl();
|
||||
}
|
||||
}
|
||||
|
||||
if (!project.vcpkg.packages.empty()) {
|
||||
// Allow the user to specify a url or derive it from the version
|
||||
auto url = project.vcpkg.url;
|
||||
@@ -579,8 +612,8 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
|
||||
// Show a nicer error than vcpkg when specifying an invalid package name
|
||||
for (const auto &package : project.vcpkg.packages) {
|
||||
if (!vcpkg_valid_identifier(package)) {
|
||||
throw std::runtime_error("Invalid [vcpkg].packages name '" + package + "' (needs to be lowercase alphanumeric)");
|
||||
if (!vcpkg_valid_identifier(package.name)) {
|
||||
throw std::runtime_error("Invalid [vcpkg].packages name '" + package.name + "' (needs to be lowercase alphanumeric)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,10 +644,31 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
const auto &packages = project.vcpkg.packages;
|
||||
for (size_t i = 0; i < packages.size(); i++) {
|
||||
const auto &package = packages[i];
|
||||
if (!vcpkg_valid_identifier(package)) {
|
||||
throw std::runtime_error("Invalid vcpkg package name '" + package + "'");
|
||||
const auto &features = package.features;
|
||||
if (!vcpkg_valid_identifier(package.name)) {
|
||||
throw std::runtime_error("Invalid vcpkg package name '" + package.name + "'");
|
||||
}
|
||||
for (const auto &feature : features) {
|
||||
if (!vcpkg_valid_identifier(feature)) {
|
||||
throw std::runtime_error("Invalid vcpkg package feature '" + feature + "'");
|
||||
}
|
||||
}
|
||||
if (features.empty()) {
|
||||
ofs << " \"" << package.name << '\"';
|
||||
} else {
|
||||
ofs << " {\n";
|
||||
ofs << " \"name\": \"" << package.name << "\",\n";
|
||||
ofs << " \"features\": [";
|
||||
for (size_t j = 0; j < features.size(); j++) {
|
||||
const auto &feature = features[j];
|
||||
ofs << '\"' << feature << '\"';
|
||||
if (j + 1 < features.size()) {
|
||||
ofs << ',';
|
||||
}
|
||||
}
|
||||
ofs << "]\n";
|
||||
ofs << " }";
|
||||
}
|
||||
ofs << " \"" << package << '\"';
|
||||
if (i + 1 < packages.size()) {
|
||||
ofs << ',';
|
||||
}
|
||||
@@ -639,6 +693,26 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
ofs << "}\n";
|
||||
}
|
||||
|
||||
if (!project.contents.empty()) {
|
||||
cmd("include")("FetchContent").endl();
|
||||
for (const auto &content : project.contents) {
|
||||
ConditionScope cs(gen, content.condition);
|
||||
std::string version_info = "";
|
||||
if (content.arguments.contains("GIT_TAG")) {
|
||||
version_info = " (" + content.arguments.at("GIT_TAG") + ")";
|
||||
} else if (content.arguments.contains("SVN_REVISION")) {
|
||||
version_info = " (" + content.arguments.at("SVN_REVISION") + ")";
|
||||
}
|
||||
cmd("message")("STATUS", "Fetching " + content.name + version_info + "...");
|
||||
ss << "FetchContent_Declare(\n\t" << content.name << "\n";
|
||||
for (const auto &arg : content.arguments) {
|
||||
ss << "\t" << arg.first << "\n\t\t" << arg.second << "\n";
|
||||
}
|
||||
ss << ")\n";
|
||||
cmd("FetchContent_MakeAvailable")(content.name).endl();
|
||||
}
|
||||
}
|
||||
|
||||
if (!project.packages.empty()) {
|
||||
comment("Packages");
|
||||
for (const auto &dep : project.packages) {
|
||||
@@ -648,39 +722,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
auto required = dep.required ? "REQUIRED" : "";
|
||||
auto config = dep.config ? "CONFIG" : "";
|
||||
auto components = std::make_pair("COMPONENTS", dep.components);
|
||||
ConditionScope cs(gen, dep.condition);
|
||||
cmd("find_package")(dep.name, version, required, config, components).endl();
|
||||
}
|
||||
}
|
||||
|
||||
if (!project.options.empty()) {
|
||||
comment("Options");
|
||||
for (const auto &opt : project.options) {
|
||||
cmd("option")(opt.name, opt.comment, opt.val ? "ON" : "OFF");
|
||||
}
|
||||
endl();
|
||||
}
|
||||
|
||||
if (!project.settings.empty()) {
|
||||
comment("Settings");
|
||||
for (const auto &set : project.settings) {
|
||||
std::string set_val;
|
||||
if (set.val.index() == 1) {
|
||||
set_val = mpark::get<1>(set.val);
|
||||
} else {
|
||||
set_val = mpark::get<0>(set.val) ? "ON" : "OFF";
|
||||
}
|
||||
|
||||
if (set.cache) {
|
||||
auto typ = set.val.index() == 1 ? "STRING" : "BOOL";
|
||||
auto force = set.force ? "FORCE" : "";
|
||||
cmd("set")(set.name, set_val, typ, set.comment, force);
|
||||
} else {
|
||||
cmd("set")(set.name, set_val);
|
||||
}
|
||||
}
|
||||
endl();
|
||||
}
|
||||
|
||||
auto add_subdir = [&](const std::string &dir) {
|
||||
// clang-format off
|
||||
comment(dir);
|
||||
@@ -706,13 +752,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
endl();
|
||||
}
|
||||
for (const auto &subdir : project.subdirs) {
|
||||
if (!subdir.condition.empty()) {
|
||||
const auto &condition = subdir.condition;
|
||||
if (project.conditions.count(condition) == 0) {
|
||||
throw std::runtime_error("Unknown condition '" + condition + "' for [subdir." + subdir.name + "]");
|
||||
}
|
||||
gen.cmd("if", condition)(RawArg(project.conditions[condition]));
|
||||
}
|
||||
ConditionScope cs(gen, subdir.condition);
|
||||
|
||||
gen.handle_condition(subdir.include_before,
|
||||
[&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
||||
@@ -722,23 +762,18 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
|
||||
gen.handle_condition(subdir.include_after, [&](const std::string &, const std::vector<std::string> &includes) { inject_includes(includes); });
|
||||
gen.handle_condition(subdir.cmake_after, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); });
|
||||
|
||||
if (!subdir.condition.empty()) {
|
||||
cmd("endif")();
|
||||
}
|
||||
}
|
||||
|
||||
if (!project.targets.empty()) {
|
||||
for (const auto &target : project.targets) {
|
||||
for (size_t i = 0; i < project.targets.size(); i++) {
|
||||
if (i > 0) {
|
||||
endl();
|
||||
}
|
||||
|
||||
const auto &target = project.targets[i];
|
||||
comment("Target " + target.name);
|
||||
|
||||
if (!target.condition.empty()) {
|
||||
const auto &condition = target.condition;
|
||||
if (project.conditions.count(condition) == 0) {
|
||||
throw std::runtime_error("Unknown condition '" + condition + "' for [target." + target.name + "]");
|
||||
}
|
||||
gen.cmd("if", condition)(RawArg(project.conditions[condition]));
|
||||
}
|
||||
ConditionScope cs(gen, target.condition);
|
||||
|
||||
cmd("set")("CMKR_TARGET", target.name);
|
||||
|
||||
@@ -880,13 +915,9 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
|
||||
cmd("unset")("CMKR_TARGET");
|
||||
cmd("unset")("CMKR_SOURCES");
|
||||
|
||||
if (!target.condition.empty()) {
|
||||
cmd("endif")();
|
||||
}
|
||||
|
||||
endl();
|
||||
}
|
||||
|
||||
endl();
|
||||
}
|
||||
|
||||
if (!project.tests.empty()) {
|
||||
@@ -901,6 +932,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
auto working_directory = std::make_pair("WORKING_DIRECTORY", dir);
|
||||
auto command = std::make_pair("COMMAND", test.command);
|
||||
auto arguments = std::make_pair("", test.arguments);
|
||||
ConditionScope cs(gen, test.condition);
|
||||
cmd("add_test")(name, configurations, working_directory, command, arguments).endl();
|
||||
}
|
||||
}
|
||||
@@ -920,6 +952,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
|
||||
auto configs = std::make_pair("CONFIGURATIONS", inst.configs);
|
||||
auto destination = std::make_pair("DESTINATION", inst.destination);
|
||||
auto component = std::make_pair("COMPONENT", inst.targets.empty() ? "" : inst.targets.front());
|
||||
ConditionScope cs(gen, inst.condition);
|
||||
cmd("install")(targets, dirs, files, configs, destination, component);
|
||||
}
|
||||
}
|
||||
|
||||
+33
-1
@@ -145,6 +145,11 @@ class TomlChecker {
|
||||
}
|
||||
}
|
||||
throw std::runtime_error(format_key_error("Unknown key '" + ky + "'", ky, itr.second));
|
||||
} else if (ky == "condition") {
|
||||
std::string condition = itr.second.as_string();
|
||||
if (!conditions.contains(condition)) {
|
||||
throw std::runtime_error(format_key_error("Unknown condition '" + condition + "'", condition, itr.second));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,6 +335,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
|
||||
p.version = itr.second.as_string();
|
||||
} else {
|
||||
auto &pkg = checker.create(value);
|
||||
pkg.optional("condition", p.condition);
|
||||
pkg.optional("version", p.version);
|
||||
pkg.optional("required", p.required);
|
||||
pkg.optional("config", p.config);
|
||||
@@ -347,6 +353,11 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
|
||||
content.name = itr.first;
|
||||
for (const auto &argItr : itr.second.as_table()) {
|
||||
auto key = argItr.first;
|
||||
if (key == "condition") {
|
||||
content.condition = argItr.second.as_string();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key == "git") {
|
||||
key = "GIT_REPOSITORY";
|
||||
} else if (key == "tag") {
|
||||
@@ -469,6 +480,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
|
||||
auto &t = checker.create(value);
|
||||
Test test;
|
||||
t.required("name", test.name);
|
||||
t.optional("condition", test.condition);
|
||||
t.optional("configurations", test.configurations);
|
||||
t.optional("working-directory", test.working_directory);
|
||||
t.required("command", test.command);
|
||||
@@ -482,6 +494,7 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
|
||||
for (const auto &value : is) {
|
||||
auto &i = checker.create(value);
|
||||
Install inst;
|
||||
i.optional("condition", inst.condition);
|
||||
i.optional("targets", inst.targets);
|
||||
i.optional("files", inst.files);
|
||||
i.optional("dirs", inst.dirs);
|
||||
@@ -495,7 +508,26 @@ Project::Project(const Project *parent, const std::string &path, bool build) {
|
||||
auto &v = checker.create(toml, "vcpkg");
|
||||
v.optional("url", vcpkg.url);
|
||||
v.optional("version", vcpkg.version);
|
||||
v.required("packages", vcpkg.packages);
|
||||
for (const auto &p : v.find("packages").as_array()) {
|
||||
Vcpkg::Package package;
|
||||
const auto &package_str = p.as_string().str;
|
||||
const auto open_bracket = package_str.find('[');
|
||||
const auto close_bracket = package_str.find(']', open_bracket);
|
||||
if (open_bracket == std::string::npos && close_bracket == std::string::npos) {
|
||||
package.name = package_str;
|
||||
} else if (close_bracket != std::string::npos) {
|
||||
package.name = package_str.substr(0, open_bracket);
|
||||
const auto features = package_str.substr(open_bracket + 1, close_bracket - open_bracket - 1);
|
||||
std::istringstream feature_stream{features};
|
||||
std::string feature;
|
||||
while (std::getline(feature_stream, feature, ',')) {
|
||||
package.features.emplace_back(feature);
|
||||
}
|
||||
} else {
|
||||
throw std::runtime_error("Invalid vcpkg package '" + package_str + "'");
|
||||
}
|
||||
vcpkg.packages.emplace_back(std::move(package));
|
||||
}
|
||||
}
|
||||
|
||||
checker.check(conditions);
|
||||
|
||||
@@ -18,4 +18,5 @@ type = "executable"
|
||||
sources = ["src/main.cpp"]
|
||||
link-libraries = ["fmt::fmt"]
|
||||
|
||||
# The bootstrapping of vcpkg is fully automated and no user interaction is necessary. You can disable vcpkg by setting `CMKR_DISABLE_VCPKG=ON`.
|
||||
# The bootstrapping of vcpkg is fully automated and no user interaction is necessary. You can disable vcpkg by setting `CMKR_DISABLE_VCPKG=ON`.
|
||||
# To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`.
|
||||
Reference in New Issue
Block a user