mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eaf03eb785 | |||
| 8ea5b77ba5 | |||
| a12b3ae021 | |||
| 2450cfb2c9 | |||
| 8d024556e3 | |||
| af3807ca2b | |||
| 17f085c66d | |||
| 5ad6134e07 | |||
| 7b20d8c54c | |||
| ffdedbdace | |||
| bb7a0bc0ed | |||
| dd0003f8fe | |||
| a32caca8f0 | |||
| f565ad2af0 | |||
| dc4b59f05d | |||
| 4988f141e4 |
Generated
+3
@@ -71,6 +71,7 @@ generate_documentation()
|
||||
|
||||
unset(CMKR_TARGET)
|
||||
unset(CMKR_SOURCES)
|
||||
|
||||
# Target cmkr
|
||||
set(CMKR_TARGET cmkr)
|
||||
set(cmkr_SOURCES "")
|
||||
@@ -125,10 +126,12 @@ target_link_libraries(cmkr PRIVATE
|
||||
ghc_filesystem
|
||||
mpark_variant
|
||||
ordered_map
|
||||
nlohmann_json
|
||||
)
|
||||
|
||||
unset(CMKR_TARGET)
|
||||
unset(CMKR_SOURCES)
|
||||
|
||||
install(
|
||||
TARGETS
|
||||
cmkr
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ type = "executable"
|
||||
sources = ["src/*.cpp", "include/*.hpp"]
|
||||
include-directories = ["include"]
|
||||
compile-features = ["cxx_std_11"]
|
||||
link-libraries = ["toml11", "ghc_filesystem", "mpark_variant", "ordered_map"]
|
||||
link-libraries = ["toml11", "ghc_filesystem", "mpark_variant", "ordered_map", "nlohmann_json"]
|
||||
|
||||
[[install]]
|
||||
targets = ["cmkr"]
|
||||
|
||||
+8
-3
@@ -2,14 +2,14 @@ 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 "archive_7cdf36f3" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
|
||||
set(CMKR_TAG "archive_2450cfb2" 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")
|
||||
|
||||
# Disable cmkr if generation is disabled
|
||||
if(CMKR_SKIP_GENERATION)
|
||||
if(DEFINED ENV{CI} OR CMKR_SKIP_GENERATION)
|
||||
message(STATUS "[cmkr] Skipping automatic cmkr generation")
|
||||
macro(cmkr)
|
||||
endmacro()
|
||||
@@ -132,10 +132,15 @@ macro(cmkr)
|
||||
|
||||
file(SHA256 "${CMAKE_CURRENT_LIST_FILE}" CMKR_LIST_FILE_SHA256_POST)
|
||||
|
||||
# Delete the temporary file if it was left for some reason
|
||||
set(CMKR_TEMP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CMakerLists.txt")
|
||||
if(EXISTS "${CMKR_TEMP_FILE}")
|
||||
file(REMOVE "${CMKR_TEMP_FILE}")
|
||||
endif()
|
||||
|
||||
if(NOT CMKR_LIST_FILE_SHA256_PRE STREQUAL CMKR_LIST_FILE_SHA256_POST)
|
||||
# Copy the now-generated CMakeLists.txt to CMakerLists.txt
|
||||
# This is done because you cannot include() a file you are currently in
|
||||
set(CMKR_TEMP_FILE "${CMAKE_CURRENT_SOURCE_DIR}/CMakerLists.txt")
|
||||
configure_file(CMakeLists.txt "${CMKR_TEMP_FILE}" COPYONLY)
|
||||
|
||||
# Add the macro required for the hack at the start of the cmkr macro
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
# Automatically generated from tests/vcpkg/cmake.toml - DO NOT EDIT
|
||||
layout: default
|
||||
title: Dependencies from vcpkg
|
||||
permalink: /examples/vcpkg
|
||||
parent: Examples
|
||||
nav_order: 4
|
||||
---
|
||||
|
||||
# Dependencies from vcpkg
|
||||
|
||||
Downloads [fmt v7.1.3](https://fmt.dev/7.1.3/) using [vcpkg](https://vcpkg.io/) and links an `example` target to it:
|
||||
|
||||
```toml
|
||||
[project]
|
||||
name = "vcpkg"
|
||||
description = "Dependencies from vcpkg"
|
||||
|
||||
# See https://github.com/microsoft/vcpkg/releases for vcpkg versions
|
||||
# See https://vcpkg.io/en/packages.html for available packages
|
||||
[vcpkg]
|
||||
version = "2021.05.12"
|
||||
packages = ["fmt"]
|
||||
|
||||
[find-package]
|
||||
fmt = {}
|
||||
|
||||
[target.example]
|
||||
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`.
|
||||
|
||||
<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>
|
||||
+29
-10
@@ -34,6 +34,7 @@ struct Package {
|
||||
|
||||
struct Vcpkg {
|
||||
std::string version;
|
||||
std::string url;
|
||||
std::vector<std::string> packages;
|
||||
};
|
||||
|
||||
@@ -55,19 +56,37 @@ struct Target {
|
||||
std::string name;
|
||||
TargetType type = {};
|
||||
|
||||
// https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html#project-commands
|
||||
ConditionVector compile_definitions;
|
||||
ConditionVector compile_features;
|
||||
ConditionVector compile_options;
|
||||
ConditionVector include_directories;
|
||||
ConditionVector link_directories;
|
||||
ConditionVector link_libraries;
|
||||
ConditionVector link_options;
|
||||
ConditionVector precompile_headers;
|
||||
ConditionVector headers;
|
||||
ConditionVector sources;
|
||||
|
||||
// https://cmake.org/cmake/help/latest/manual/cmake-commands.7.html#project-commands
|
||||
ConditionVector compile_definitions;
|
||||
ConditionVector private_compile_definitions;
|
||||
|
||||
ConditionVector compile_features;
|
||||
ConditionVector private_compile_features;
|
||||
|
||||
ConditionVector compile_options;
|
||||
ConditionVector private_compile_options;
|
||||
|
||||
ConditionVector include_directories;
|
||||
ConditionVector private_include_directories;
|
||||
|
||||
ConditionVector link_directories;
|
||||
ConditionVector private_link_directories;
|
||||
|
||||
ConditionVector link_libraries;
|
||||
ConditionVector private_link_libraries;
|
||||
|
||||
ConditionVector link_options;
|
||||
ConditionVector private_link_options;
|
||||
|
||||
ConditionVector precompile_headers;
|
||||
ConditionVector private_precompile_headers;
|
||||
|
||||
std::string condition;
|
||||
std::string alias;
|
||||
tsl::ordered_map<std::string, std::string> properties;
|
||||
Condition<tsl::ordered_map<std::string, std::string>> properties;
|
||||
|
||||
Condition<std::string> cmake_before;
|
||||
Condition<std::string> cmake_after;
|
||||
|
||||
+49
-14
@@ -181,34 +181,75 @@ CMake::CMake(const std::string &path, bool build) {
|
||||
target.name = itr.first;
|
||||
target.type = to_enum<TargetType>(toml::find(t, "type").as_string(), "target type");
|
||||
|
||||
get_optional(t, "headers", target.headers);
|
||||
get_optional(t, "sources", target.sources);
|
||||
|
||||
get_optional(t, "compile-definitions", target.compile_definitions);
|
||||
get_optional(t, "private-compile-definitions", target.private_compile_definitions);
|
||||
|
||||
get_optional(t, "compile-features", target.compile_features);
|
||||
get_optional(t, "private-compile-features", target.private_compile_features);
|
||||
|
||||
get_optional(t, "compile-options", target.compile_options);
|
||||
get_optional(t, "private-compile-options", target.private_compile_options);
|
||||
|
||||
get_optional(t, "include-directories", target.include_directories);
|
||||
get_optional(t, "private-include-directories", target.private_include_directories);
|
||||
|
||||
get_optional(t, "link-directories", target.link_directories);
|
||||
get_optional(t, "private-link-directories", target.private_link_directories);
|
||||
|
||||
get_optional(t, "link-libraries", target.link_libraries);
|
||||
get_optional(t, "private-link-libraries", target.private_link_libraries);
|
||||
|
||||
get_optional(t, "link-options", target.link_options);
|
||||
get_optional(t, "private-link-options", target.private_link_options);
|
||||
|
||||
get_optional(t, "precompile-headers", target.precompile_headers);
|
||||
get_optional(t, "private-precompile-headers", target.private_precompile_headers);
|
||||
|
||||
if (!target.headers.empty()) {
|
||||
auto &sources = target.sources.nth(0).value();
|
||||
const auto &headers = target.headers.nth(0)->second;
|
||||
sources.insert(sources.end(), headers.begin(), headers.end());
|
||||
}
|
||||
|
||||
if (t.contains("condition")) {
|
||||
target.condition = toml::find(t, "condition").as_string();
|
||||
}
|
||||
|
||||
if (t.contains("alias")) {
|
||||
target.alias = toml::find(t, "alias").as_string();
|
||||
}
|
||||
|
||||
if (t.contains("properties")) {
|
||||
const auto &props = toml::find(t, "properties").as_table();
|
||||
for (const auto &propKv : props) {
|
||||
if (propKv.second.is_array()) {
|
||||
auto store_property = [&target](const toml::key &k, const TomlBasicValue &v, const std::string &condition) {
|
||||
if (v.is_array()) {
|
||||
std::string property_list;
|
||||
for (const auto &list_val : propKv.second.as_array()) {
|
||||
for (const auto &list_val : v.as_array()) {
|
||||
if (!property_list.empty()) {
|
||||
property_list += ';';
|
||||
}
|
||||
property_list += list_val.as_string();
|
||||
}
|
||||
target.properties[propKv.first] = property_list;
|
||||
target.properties[condition][k] = property_list;
|
||||
} else if (v.is_boolean()) {
|
||||
target.properties[condition][k] = v.as_boolean() ? "ON" : "OFF";
|
||||
} else {
|
||||
target.properties[propKv.first] = propKv.second.as_string();
|
||||
target.properties[condition][k] = v.as_string();
|
||||
}
|
||||
};
|
||||
|
||||
const auto &props = toml::find(t, "properties").as_table();
|
||||
for (const auto &propKv : props) {
|
||||
const auto &k = propKv.first;
|
||||
const auto &v = propKv.second;
|
||||
if (v.is_table()) {
|
||||
for (const auto &condKv : v.as_table()) {
|
||||
store_property(condKv.first, condKv.second, k);
|
||||
}
|
||||
} else {
|
||||
store_property(k, v, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,15 +291,9 @@ CMake::CMake(const std::string &path, bool build) {
|
||||
|
||||
if (toml.contains("vcpkg")) {
|
||||
const auto &v = toml::find(toml, "vcpkg");
|
||||
vcpkg.version = toml::find(v, "version").as_string();
|
||||
get_optional(v, "url", vcpkg.url);
|
||||
get_optional(v, "version", vcpkg.version);
|
||||
vcpkg.packages = toml::find<decltype(vcpkg.packages)>(v, "packages");
|
||||
|
||||
// This allows the user to use a custom pmm version if desired
|
||||
if (contents.count("pmm") == 0) {
|
||||
contents["pmm"]["url"] = "https://github.com/vector-of-bool/pmm/archive/refs/tags/1.5.1.tar.gz";
|
||||
// Hack to not execute pmm's example CMakeLists.txt
|
||||
contents["pmm"]["SOURCE_SUBDIR"] = "pmm";
|
||||
}
|
||||
}
|
||||
|
||||
// Reasonable default conditions (you can override these if you desire)
|
||||
|
||||
+130
-32
@@ -8,7 +8,10 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <new>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -155,12 +158,14 @@ struct Command {
|
||||
bool first_arg = true;
|
||||
bool had_newline = false;
|
||||
bool generated = false;
|
||||
std::string post_comment;
|
||||
|
||||
Command(std::stringstream &ss, int depth, const std::string &command) : ss(ss), depth(depth), command(command) {}
|
||||
Command(std::stringstream &ss, int depth, std::string command, std::string post_comment)
|
||||
: ss(ss), depth(depth), command(std::move(command)), post_comment(std::move(post_comment)) {}
|
||||
|
||||
~Command() {
|
||||
if (!generated) {
|
||||
assert(false && "Incorrect usage of cmd()");
|
||||
assert(false && "Incorrect usage of cmd(), you probably forgot ()");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +305,11 @@ struct Command {
|
||||
(void)std::initializer_list<bool>{print_arg(values)...};
|
||||
if (had_newline)
|
||||
ss << '\n' << indent(depth);
|
||||
ss << ")\n";
|
||||
ss << ")";
|
||||
if (!post_comment.empty()) {
|
||||
ss << " # " << post_comment;
|
||||
}
|
||||
ss << "\n";
|
||||
return CommandEndl(ss);
|
||||
}
|
||||
};
|
||||
@@ -323,18 +332,18 @@ struct Generator {
|
||||
std::stringstream ss;
|
||||
int indent = 0;
|
||||
|
||||
Command cmd(const std::string &command) {
|
||||
Command cmd(const std::string &command, const std::string &post_comment = "") {
|
||||
if (command.empty())
|
||||
throw std::invalid_argument("command cannot be empty");
|
||||
if (command == "if") {
|
||||
indent++;
|
||||
return Command(ss, indent - 1, command);
|
||||
return Command(ss, indent - 1, command, post_comment);
|
||||
} else if (command == "else" || command == "elseif") {
|
||||
return Command(ss, indent - 1, command);
|
||||
return Command(ss, indent - 1, command, post_comment);
|
||||
} else if (command == "endif") {
|
||||
indent--;
|
||||
}
|
||||
return Command(ss, indent, command);
|
||||
return Command(ss, indent, command, post_comment);
|
||||
}
|
||||
|
||||
CommandEndl comment(const std::string &comment) {
|
||||
@@ -387,7 +396,7 @@ struct Generator {
|
||||
// TODO: somehow print line number information here?
|
||||
throw std::runtime_error("Unknown condition '" + condition + "'");
|
||||
}
|
||||
cmd("if")(RawArg(cmake.conditions[condition]));
|
||||
cmd("if", condition)(RawArg(cmake.conditions[condition]));
|
||||
}
|
||||
|
||||
if (!itr.second.empty()) {
|
||||
@@ -403,6 +412,31 @@ struct Generator {
|
||||
}
|
||||
};
|
||||
|
||||
static std::string vcpkg_escape_identifier(const std::string &name) {
|
||||
// Do a reasonable effort to escape the project name for use with vcpkg
|
||||
std::string escaped;
|
||||
for (char ch : name) {
|
||||
if ((ch & 0x80) != 0) {
|
||||
throw std::runtime_error("Non-ASCII characters are not allowed in [project].name when using [vcpkg]");
|
||||
}
|
||||
|
||||
if (ch == '_' || ch == ' ') {
|
||||
ch = '-';
|
||||
}
|
||||
|
||||
escaped += std::tolower(ch);
|
||||
}
|
||||
|
||||
const std::regex reserved("prn|aux|nul|con|lpt[1-9]|com[1-9]|core|default");
|
||||
const std::regex ok("[a-z0-9]+(-[a-z0-9]+)*");
|
||||
std::cmatch m;
|
||||
if (!std::regex_match(escaped.c_str(), m, reserved) && std::regex_match(escaped.c_str(), m, ok)) {
|
||||
return escaped;
|
||||
} else {
|
||||
throw std::runtime_error("The escaped project name '" + escaped + "' is not usable with [vcpkg]");
|
||||
}
|
||||
}
|
||||
|
||||
int generate_cmake(const char *path, bool root) {
|
||||
if (!fs::exists(fs::path(path) / "cmake.toml")) {
|
||||
throw std::runtime_error("No cmake.toml found!");
|
||||
@@ -413,14 +447,15 @@ int generate_cmake(const char *path, bool root) {
|
||||
|
||||
// Helper lambdas for more convenient CMake generation
|
||||
auto &ss = gen.ss;
|
||||
auto cmd = [&gen](const std::string &comment) { return gen.cmd(comment); };
|
||||
auto cmd = [&gen](const std::string &command) { return gen.cmd(command); };
|
||||
auto comment = [&gen](const std::string &comment) { return gen.comment(comment); };
|
||||
auto endl = [&gen]() { gen.endl(); };
|
||||
auto inject_includes = [&gen](const std::vector<std::string> &includes) { gen.inject_includes(includes); };
|
||||
auto inject_cmake = [&gen](const std::string &cmake) { gen.inject_cmake(cmake); };
|
||||
|
||||
std::string cmkr_url = "https://github.com/build-cpp/cmkr";
|
||||
comment("This file is automatically generated from cmake.toml - DO NOT EDIT");
|
||||
comment("See https://github.com/build-cpp/cmkr for more information");
|
||||
comment("See " + cmkr_url + " for more information");
|
||||
endl();
|
||||
|
||||
if (root) {
|
||||
@@ -520,15 +555,46 @@ int generate_cmake(const char *path, bool root) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!cmake.vcpkg.version.empty()) {
|
||||
assert("pmm is required in fetch-content for vcpkg to work" && cmake.contents.count("pmm") != 0);
|
||||
comment("Bootstrap vcpkg");
|
||||
cmd("include")("${pmm_SOURCE_DIR}/pmm.cmake");
|
||||
tsl::ordered_map<std::string, std::vector<std::string>> vcpkg_args;
|
||||
vcpkg_args["REVISION"] = {cmake.vcpkg.version};
|
||||
vcpkg_args["REQUIRES"] = cmake.vcpkg.packages;
|
||||
auto vcpkg = std::make_pair("VCPKG", vcpkg_args);
|
||||
cmd("pmm")(vcpkg).endl();
|
||||
if (!cmake.vcpkg.packages.empty()) {
|
||||
// Allow the user to specify a url or derive it from the version
|
||||
auto url = cmake.vcpkg.url;
|
||||
if (url.empty()) {
|
||||
if (cmake.vcpkg.version.empty()) {
|
||||
throw std::runtime_error("You need either [vcpkg].version or [vcpkg].url");
|
||||
}
|
||||
url = "https://github.com/microsoft/vcpkg/archive/refs/tags/" + cmake.vcpkg.version + ".tar.gz";
|
||||
}
|
||||
|
||||
// CMake to bootstrap vcpkg and download the packages
|
||||
// clang-format off
|
||||
cmd("if")("CMKR_ROOT_PROJECT", "AND", "NOT", "CMKR_DISABLE_VCPKG");
|
||||
cmd("include")("FetchContent");
|
||||
cmd("message")("STATUS", "Fetching vcpkg...");
|
||||
cmd("FetchContent_Declare")("vcpkg", "URL", url);
|
||||
cmd("FetchContent_MakeAvailable")("vcpkg");
|
||||
cmd("include")("${vcpkg_SOURCE_DIR}/scripts/buildsystems/vcpkg.cmake");
|
||||
cmd("endif")();
|
||||
endl();
|
||||
// clang-format on
|
||||
|
||||
// Generate vcpkg.json
|
||||
using namespace nlohmann;
|
||||
json j;
|
||||
j["$cmkr"] = "This file is automatically generated from cmake.toml - DO NOT EDIT";
|
||||
j["$cmkr-url"] = cmkr_url;
|
||||
j["$schema"] = "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json";
|
||||
j["name"] = vcpkg_escape_identifier(cmake.project_name);
|
||||
j["version-string"] = cmake.project_version;
|
||||
j["dependencies"] = cmake.vcpkg.packages;
|
||||
if (!cmake.project_description.empty()) {
|
||||
j["description"] = cmake.project_description;
|
||||
}
|
||||
|
||||
std::ofstream ofs("vcpkg.json");
|
||||
if (!ofs) {
|
||||
throw std::runtime_error("Failed to create a vcpkg.json manifest file!");
|
||||
}
|
||||
ofs << std::setw(2) << j << std::endl;
|
||||
}
|
||||
|
||||
if (!cmake.packages.empty()) {
|
||||
@@ -597,6 +663,15 @@ int generate_cmake(const char *path, bool root) {
|
||||
if (!cmake.targets.empty()) {
|
||||
for (const auto &target : cmake.targets) {
|
||||
comment("Target " + target.name);
|
||||
|
||||
if (!target.condition.empty()) {
|
||||
const auto &condition = target.condition;
|
||||
if (cmake.conditions.count(condition) == 0) {
|
||||
throw std::runtime_error("Unknown condition '" + condition + "' for [target." + target.name + "]");
|
||||
}
|
||||
gen.cmd("if", condition)(RawArg(cmake.conditions[condition]));
|
||||
}
|
||||
|
||||
cmd("set")("CMKR_TARGET", target.name);
|
||||
|
||||
gen.handle_condition(target.include_before,
|
||||
@@ -683,29 +758,46 @@ int generate_cmake(const char *path, bool root) {
|
||||
}
|
||||
|
||||
if (!target.sources.empty()) {
|
||||
cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + target.name + "_SOURCES}").endl();
|
||||
cmd("source_group")("TREE", "${CMAKE_CURRENT_SOURCE_DIR}", "FILES", "${" + sources_var + "}").endl();
|
||||
}
|
||||
|
||||
if (!target.alias.empty()) {
|
||||
cmd("add_library")(target.alias, "ALIAS", target.name);
|
||||
}
|
||||
|
||||
auto target_cmd = [&](const char *command, const cmake::ConditionVector &cargs) {
|
||||
gen.handle_condition(
|
||||
cargs, [&](const std::string &, const std::vector<std::string> &args) { cmd(command)(target.name, target_scope, args); });
|
||||
auto target_cmd = [&](const char *command, const cmake::ConditionVector &cargs, const std::string &scope) {
|
||||
gen.handle_condition(cargs,
|
||||
[&](const std::string &, const std::vector<std::string> &args) { cmd(command)(target.name, scope, args); });
|
||||
};
|
||||
|
||||
target_cmd("target_compile_definitions", target.compile_definitions);
|
||||
target_cmd("target_compile_features", target.compile_features);
|
||||
target_cmd("target_compile_options", target.compile_options);
|
||||
target_cmd("target_include_directories", target.include_directories);
|
||||
target_cmd("target_link_directories", target.link_directories);
|
||||
target_cmd("target_link_libraries", target.link_libraries);
|
||||
target_cmd("target_link_options", target.link_options);
|
||||
target_cmd("target_precompile_headers", target.precompile_headers);
|
||||
target_cmd("target_compile_definitions", target.compile_definitions, target_scope);
|
||||
target_cmd("target_compile_definitions", target.private_compile_definitions, "PRIVATE");
|
||||
|
||||
target_cmd("target_compile_features", target.compile_features, target_scope);
|
||||
target_cmd("target_compile_features", target.private_compile_features, "PRIVATE");
|
||||
|
||||
target_cmd("target_compile_options", target.compile_options, target_scope);
|
||||
target_cmd("target_compile_options", target.private_compile_options, "PRIVATE");
|
||||
|
||||
target_cmd("target_include_directories", target.include_directories, target_scope);
|
||||
target_cmd("target_include_directories", target.private_include_directories, "PRIVATE");
|
||||
|
||||
target_cmd("target_link_directories", target.link_directories, target_scope);
|
||||
target_cmd("target_link_directories", target.private_link_directories, "PRIVATE");
|
||||
|
||||
target_cmd("target_link_libraries", target.link_libraries, target_scope);
|
||||
target_cmd("target_link_libraries", target.private_link_libraries, "PRIVATE");
|
||||
|
||||
target_cmd("target_link_options", target.link_options, target_scope);
|
||||
target_cmd("target_link_options", target.private_link_options, "PRIVATE");
|
||||
|
||||
target_cmd("target_precompile_headers", target.precompile_headers, target_scope);
|
||||
target_cmd("target_precompile_headers", target.private_precompile_headers, "PRIVATE");
|
||||
|
||||
if (!target.properties.empty()) {
|
||||
cmd("set_target_properties")(target.name, "PROPERTIES", target.properties).endl();
|
||||
gen.handle_condition(target.properties, [&](const std::string &, const tsl::ordered_map<std::string, std::string> &properties) {
|
||||
cmd("set_target_properties")(target.name, "PROPERTIES", properties);
|
||||
});
|
||||
}
|
||||
|
||||
gen.handle_condition(target.include_after,
|
||||
@@ -714,6 +806,12 @@ int generate_cmake(const char *path, bool root) {
|
||||
|
||||
cmd("unset")("CMKR_TARGET");
|
||||
cmd("unset")("CMKR_SOURCES");
|
||||
|
||||
if (!target.condition.empty()) {
|
||||
cmd("endif")();
|
||||
}
|
||||
|
||||
endl();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Generated
+10
@@ -48,3 +48,13 @@ add_test(
|
||||
build
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME
|
||||
vcpkg
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_LIST_DIR}/vcpkg"
|
||||
COMMAND
|
||||
$<TARGET_FILE:cmkr>
|
||||
build
|
||||
)
|
||||
|
||||
|
||||
@@ -20,4 +20,10 @@ arguments = ["build"]
|
||||
name = "conditions"
|
||||
command = "$<TARGET_FILE:cmkr>"
|
||||
working-directory = "conditions"
|
||||
arguments = ["build"]
|
||||
|
||||
[[test]]
|
||||
name = "vcpkg"
|
||||
command = "$<TARGET_FILE:cmkr>"
|
||||
working-directory = "vcpkg"
|
||||
arguments = ["build"]
|
||||
@@ -14,4 +14,10 @@ windows.cmake-after = "message(STATUS win32-after)"
|
||||
macos.cmake-after = "message(STATUS macos-after)"
|
||||
linux.cmake-after = "message(STATUS linux-after)"
|
||||
unix.cmake-after = "message(STATUS unix-after)"
|
||||
custom.cmake-after = "message(STATUS custom-after)"
|
||||
custom.cmake-after = "message(STATUS custom-after)"
|
||||
|
||||
[target.example.properties]
|
||||
AUTOMOC = false
|
||||
custom.OUTPUT_NAME = "example2"
|
||||
custom.AUTORCC = true
|
||||
AUTOGEN = "ON"
|
||||
@@ -0,0 +1,21 @@
|
||||
# Downloads [fmt v7.1.3](https://fmt.dev/7.1.3/) using [vcpkg](https://vcpkg.io/) and links an `example` target to it:
|
||||
|
||||
[project]
|
||||
name = "vcpkg"
|
||||
description = "Dependencies from vcpkg"
|
||||
|
||||
# See https://github.com/microsoft/vcpkg/releases for vcpkg versions
|
||||
# See https://vcpkg.io/en/packages.html for available packages
|
||||
[vcpkg]
|
||||
version = "2021.05.12"
|
||||
packages = ["fmt"]
|
||||
|
||||
[find-package]
|
||||
fmt = {}
|
||||
|
||||
[target.example]
|
||||
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`.
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <fmt/core.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
fmt::print("Hello, world!\n");
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"$cmkr": "This file is automatically generated from cmake.toml - DO NOT EDIT",
|
||||
"$cmkr-url": "https://github.com/build-cpp/cmkr",
|
||||
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
|
||||
"dependencies": [
|
||||
"fmt"
|
||||
],
|
||||
"description": "Example of using vcpkg",
|
||||
"name": "vcpkg",
|
||||
"version-string": ""
|
||||
}
|
||||
+4
@@ -16,3 +16,7 @@ target_include_directories(toml11 INTERFACE toml11-3.6.0)
|
||||
# https://github.com/mpark/variant (BSL-1.0)
|
||||
add_library(mpark_variant INTERFACE)
|
||||
target_include_directories(mpark_variant INTERFACE variant-1.4.0/include)
|
||||
|
||||
# https://github.com/nlohmann/json (MIT)
|
||||
add_library(nlohmann_json INTERFACE)
|
||||
target_include_directories(nlohmann_json INTERFACE nlohmann-3.9.1/include)
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013-2021 Niels Lohmann
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+25447
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user