Compare commits

...

16 Commits

Author SHA1 Message Date
Duncan Ogilvie dea41d80b5 Bump to 0.2.37 2024-11-27 14:17:48 +01:00
Duncan Ogilvie b52cf5b241 Merge pull request #158 from build-cpp/vcpkg-default-features
Allow disabling default features with vcpkg
2024-11-27 14:16:25 +01:00
Duncan Ogilvie e9480a625f Allow disabling default features with vcpkg 2024-11-27 14:13:37 +01:00
Duncan Ogilvie 13a7a8788a Bump to 0.2.36 2024-11-26 13:36:24 +01:00
Duncan Ogilvie 45ca74099c Merge pull request #156 from build-cpp/vcpkg-overlay-ports
Add [vcpkg].overlay-ports feature
2024-11-26 13:35:32 +01:00
Duncan Ogilvie ae3d73896e Add [vcpkg].overlay-ports feature 2024-11-26 12:33:29 +01:00
Duncan Ogilvie 57042565d1 Merge pull request #154 from build-cpp/configure-depends
Use CMAKE_CONFIGURE_DEPENDS when supported
2024-11-03 11:44:02 +01:00
deep d02ee3ed24 Added check to make sure hash is valid hex (#153) 2024-11-03 10:49:33 +01:00
Duncan Ogilvie 4a15d2ba55 Use CMAKE_CONFIGURE_DEPENDS when supported 2024-11-03 10:33:32 +01:00
Duncan Ogilvie 87c0295f93 Fix CI 2024-10-14 13:02:20 +02:00
Duncan Ogilvie a608e6b778 Bump to 0.2.35 2024-10-13 16:16:36 +02:00
Duncan Ogilvie 523f5f4a8a Merge pull request #150 from build-cpp/msvc-runtime-root
Only emit `MSVC_RUNTIME_LIBRARY` in the root project
2024-09-06 14:39:47 +02:00
Duncan Ogilvie 510cf71af5 Only emit MSVC_RUNTIME_LIBRARY in the root project 2024-09-06 14:33:04 +02:00
Duncan Ogilvie 87d90138b4 Merge pull request #149 from build-cpp/relative-libs
Improve relative path functionality for link-libraries
2024-09-06 14:25:33 +02:00
Duncan Ogilvie 50615e0c27 Bump clang-format-lint-action
https://github.com/DoozyX/clang-format-lint-action/issues/73
2024-09-06 14:22:12 +02:00
Duncan Ogilvie 42ed3048b3 Improve relative path functionality for link-libraries 2024-09-06 13:50:43 +02:00
8 changed files with 82 additions and 36 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ jobs:
- name: clang-format
id: clang-format
uses: DoozyX/clang-format-lint-action@c3b2c943e924028b93a707a5b1b017976ab8d50c # v0.15
uses: DoozyX/clang-format-lint-action@c71d0bf4e21876ebec3e5647491186f8797fde31 # v0.18.2
with:
exclude: './third_party'
extensions: 'c,h,cpp,hpp'
+1 -1
View File
@@ -22,7 +22,7 @@ project(cmkr
LANGUAGES
CXX
VERSION
0.2.34
0.2.37
DESCRIPTION
"CMakeLists generator from TOML"
)
+1 -1
View File
@@ -4,7 +4,7 @@ cmkr-include = false
[project]
name = "cmkr"
version = "0.2.34"
version = "0.2.37"
description = "CMakeLists generator from TOML"
languages = ["CXX"]
include-after = [
+1 -1
View File
@@ -2,7 +2,7 @@ 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.34" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
set(CMKR_TAG "v0.2.37" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE)
set(CMKR_COMMIT_HASH "" CACHE STRING "cmkr git commit hash (optional)" FORCE)
# To bootstrap/generate a cmkr project: cmake -P cmkr.cmake
+4 -1
View File
@@ -163,11 +163,14 @@ Variables emit a [`set`](https://cmake.org/cmake/help/latest/command/set.html) a
version = "2024.03.25"
url = "https://github.com/microsoft/vcpkg/archive/refs/tags/2024.03.25.tar.gz"
packages = ["fmt", "zlib"]
overlay-ports = ["my-ports"]
```
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]`.
To specify package features you can use the following syntax: `imgui[docking-experimental,freetype,sdl2-binding,opengl3-binding]`. To disable the [default features](https://learn.microsoft.com/en-us/vcpkg/concepts/default-features) you can do: `cpp-httplib[core,openssl]`
The `overlay-ports` feature allows you to embed vcpkg ports inside your project, without having to fork the main vcpkg registry or creating a custom registry. You can find more information in the relevant [documentation](https://learn.microsoft.com/en-us/vcpkg/concepts/overlay-ports).
## Packages
+2
View File
@@ -45,9 +45,11 @@ struct Vcpkg {
struct Package {
std::string name;
std::vector<std::string> features;
bool default_features = true;
};
std::vector<Package> packages;
std::vector<std::string> overlay_ports;
bool enabled() const {
return !packages.empty();
+49 -19
View File
@@ -731,7 +731,6 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
if (is_root_project) {
cmd("cmake_minimum_required")("VERSION", project.cmake_version).endl();
// clang-format on
if (!project.allow_in_tree) {
// clang-format off
cmd("if")("CMAKE_SOURCE_DIR", "STREQUAL", "CMAKE_BINARY_DIR");
@@ -740,6 +739,11 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
// clang-format on
}
if (project.project_msvc_runtime != parser::msvc_last) {
comment("Enable support for MSVC_RUNTIME_LIBRARY");
cmd("cmake_policy")("SET", "CMP0091", "NEW").endl();
}
cmd("set")("CMKR_ROOT_PROJECT", "OFF");
// clang-format off
cmd("if")("CMAKE_CURRENT_SOURCE_DIR", "STREQUAL", "CMAKE_SOURCE_DIR");
@@ -757,16 +761,14 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
cmd("set_property")("GLOBAL", "PROPERTY", "USE_FOLDERS", "ON").endl();
comment("Create a configure-time dependency on cmake.toml to improve IDE support");
cmd("configure_file")("cmake.toml", "cmake.toml", "COPYONLY");
cmd("endif")().endl();
// clang-format on
if (project.cmake_minimum_version(3, 0)) {
cmd("set_property")("DIRECTORY", "APPEND", "PROPERTY", "CMAKE_CONFIGURE_DEPENDS", "cmake.toml");
} else {
cmd("configure_file")("cmake.toml", "cmake.toml", "COPYONLY");
}
if (project.project_msvc_runtime != parser::msvc_last) {
comment("Enable support for MSVC_RUNTIME_LIBRARY");
cmd("cmake_policy")("SET", "CMP0091", "NEW");
// clang-format off
cmd("if")("NOT", "DEFINED", "CMAKE_MSVC_RUNTIME_LIBRARY");
if (project.project_msvc_runtime != parser::msvc_last) {
cmd("if")("NOT", "DEFINED", "CMAKE_MSVC_RUNTIME_LIBRARY");
switch (project.project_msvc_runtime) {
case parser::msvc_dynamic:
cmd("set")("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL");
@@ -777,21 +779,24 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
default:
break;
}
cmd("endif")().endl();
// clang-format on
}
cmd("endif")().endl();
}
cmd("endif")().endl();
// clang-format on
fs::path cmkr_include(project.cmkr_include);
if (!project.cmkr_include.empty() && !fs::exists(cmkr_include) && cmkr_include.is_relative()) {
create_file(cmkr_include, resources::cmkr);
}
} else {
// clang-format off
comment("Create a configure-time dependency on cmake.toml to improve IDE support");
cmd("if")("CMKR_ROOT_PROJECT");
if (project.cmake_minimum_version(3, 0)) {
cmd("set_property")("DIRECTORY", "APPEND", "PROPERTY", "CMAKE_CONFIGURE_DEPENDS", "cmake.toml");
} else {
cmd("configure_file")("cmake.toml", "cmake.toml", "COPYONLY");
}
cmd("endif")().endl();
// clang-format on
}
// TODO: remove support and replace with global compile-features
@@ -931,7 +936,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
ofs << R"({
"$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",
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
)";
@@ -952,17 +957,20 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
throw std::runtime_error("Invalid vcpkg package feature '" + feature + "', name is reserved");
}
}
if (features.empty()) {
if (features.empty() && package.default_features) {
ofs << " \"" << package.name << '\"';
} else {
ofs << " {\n";
ofs << " \"name\": \"" << package.name << "\",\n";
if (!package.default_features) {
ofs << " \"default-features\": false,\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 << ", ";
}
}
ofs << "]\n";
@@ -988,7 +996,29 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
ofs << " ],\n";
ofs << " \"description\": \"" << escape(project.project_description) << "\",\n";
ofs << " \"name\": \"" << escape(vcpkg_escape_identifier(project.project_name)) << "\",\n";
ofs << R"( "version-string": "")" << '\n';
ofs << " \"version-string\": \"none\"";
const auto &overlay_ports = project.vcpkg.overlay_ports;
if (!overlay_ports.empty()) {
ofs << ",\n";
// Reference: https://learn.microsoft.com/en-us/vcpkg/reference/vcpkg-json#vcpkg-configuration
ofs << " \"vcpkg-configuration\": {\n";
ofs << " \"overlay-ports\": [\n";
for (size_t i = 0; i < overlay_ports.size(); i++) {
const auto &directory = overlay_ports[i];
if (!fs::is_directory(directory)) {
throw std::runtime_error("[vcpkg].overlay-ports is not a directory: " + directory);
}
ofs << " \"" << escape(directory) << "\"";
if (i > 0) {
ofs << ",";
}
ofs << "\n";
}
ofs << " ]\n";
ofs << " }\n";
} else {
ofs << "\n";
}
ofs << "}\n";
}
+23 -12
View File
@@ -550,6 +550,14 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
algo.push_back(ch);
}
key = "URL_HASH";
if (value.empty()) {
throw_key_error("Empty hash value", argItr.first, argItr.second);
}
for (char c : value) {
if (!std::isxdigit(c)) {
throw_key_error("Hash value must be a hex string", argItr.first, argItr.second);
}
}
value = algo + "=" + value;
} else if (key == "hash") {
key = "URL_HASH";
@@ -657,20 +665,16 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
continue;
}
// Skip paths that don't contain backwards or forwards slashes
if (library_path.find_first_of(R"(\/)") == std::string::npos) {
continue;
}
// Check if the new file path exists, otherwise emit an error
const auto expected_library_file_path = fs::path{path} / library_path;
if (!fs::exists(expected_library_file_path)) {
if (fs::exists(fs::path(path) / library_path)) {
// If the file path is relative, prepend ${CMAKE_CURRENT_SOURCE_DIR}
library_path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/");
} else if (library_path.find_first_of(R"(\/)") != std::string::npos) {
// Error if the path contains a directory separator and the file doesn't exist
throw std::runtime_error("Attempted to link against a library file that doesn't exist for target \"" + name + "\" in \"" +
key + "\": " + library_path);
} else {
// NOTE: We cannot check if system libraries exist, so we leave them as-is
}
// Prepend ${CMAKE_CURRENT_SOURCE_DIR} to the path
library_path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}/");
}
}
};
@@ -843,13 +847,20 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
std::istringstream feature_stream{features};
std::string feature;
while (std::getline(feature_stream, feature, ',')) {
package.features.emplace_back(feature);
// Disable default features with package-name[core,feature1]
if (feature == "core") {
package.default_features = false;
} else {
package.features.emplace_back(feature);
}
}
} else {
throw_key_error("Invalid package name '" + package_str + "'", "packages", p);
}
vcpkg.packages.emplace_back(std::move(package));
}
v.optional("overlay-ports", vcpkg.overlay_ports);
}
checker.check(conditions, true);