Compare commits

..

4 Commits

Author SHA1 Message Date
Duncan Ogilvie 6162e86329 Respect default members while building 2021-04-05 18:54:24 +02:00
Duncan Ogilvie 5a20c0fe42 Initial vcpkg support 2021-04-05 16:47:18 +02:00
Duncan Ogilvie b5752b7c2b Breaking change, rename 'cmake.minimum' to 'cmake.version' and make it optional 2021-04-05 14:49:32 +02:00
Duncan Ogilvie 5c942599a5 Recursively bootstrap cmkr.cmake 2021-04-04 17:12:24 +02:00
7 changed files with 73 additions and 37 deletions
+9 -6
View File
@@ -1,24 +1,26 @@
# This file was generated automatically by cmkr.
# Create a configure-time dependency on cmake.toml to improve IDE support
configure_file(cmake.toml cmake.toml COPYONLY)
cmake_minimum_required(VERSION 2.8...3.8)
# Regenerate CMakeLists.txt file when necessary
# Regenerate CMakeLists.txt automatically in the root project
set(CMKR_ROOT_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CMKR_ROOT_PROJECT ON)
# Bootstrap cmkr
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
if(CMKR_INCLUDE_RESULT)
cmkr()
endif()
# Enable folder support
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()
# Enable folder support
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Create a configure-time dependency on cmake.toml to improve IDE support
if(CMKR_ROOT_PROJECT)
configure_file(cmake.toml cmake.toml COPYONLY)
endif()
# Hack to hide a warning during cmkr bootstrapping on Windows
if(CMAKE_BUILD_TYPE)
@@ -34,6 +36,7 @@ project(cmkr
"CMakeLists generator from TOML"
)
# third_party
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
if(CMAKE_FOLDER)
set(CMAKE_FOLDER "${CMAKE_FOLDER}/third_party")
+1 -1
View File
@@ -1,5 +1,5 @@
[cmake]
minimum = "2.8...3.8"
version = "2.8...3.8"
[project]
cmake-before = """
+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/MoAlyousef/cmkr" CACHE STRING "cmkr git repository")
set(CMKR_TAG "archive_67ac9a43" CACHE STRING "cmkr git tag (this needs to be available forever)")
set(CMKR_TAG "archive_84f6b39f" CACHE STRING "cmkr git tag (this needs to be available forever)")
set(CMKR_EXECUTABLE "" CACHE FILEPATH "cmkr executable")
set(CMKR_SKIP_GENERATION OFF CACHE BOOL "skip automatic cmkr generation")
+1 -1
View File
@@ -11,7 +11,7 @@ int %s() {
static const char *cmake_toml = R"lit(
[cmake]
minimum = "3.15"
version = "3.15"
# subdirs = []
# build-dir = ""
# cpp-flags = []
+24 -10
View File
@@ -50,16 +50,16 @@ CMake::CMake(const std::string &path, bool build) {
throw std::runtime_error("bin-dir has been renamed to build-dir");
}
build_dir = toml::find_or(cmake, "build-dir", "");
generator = toml::find_or(cmake, "generator", "");
config = toml::find_or(cmake, "config", "");
build_dir = toml::find_or(cmake, "build-dir", build_dir);
generator = toml::find_or(cmake, "generator", generator);
config = toml::find_or(cmake, "config", config);
gen_args = optional_array(cmake, "arguments");
}
} else {
if (toml.contains("cmake")) {
const auto &cmake = toml::find(toml, "cmake");
cmake_version = toml::find(cmake, "minimum").as_string();
cmkr_include = toml::find_or(cmake, "cmkr-include", "cmkr.cmake");
cmake_version = toml::find(cmake, "version").as_string();
cmkr_include = toml::find_or(cmake, "cmkr-include", cmkr_include);
cppflags = optional_array(cmake, "cpp-flags");
cflags = optional_array(cmake, "c-flags");
linkflags = optional_array(cmake, "link-flags");
@@ -130,9 +130,10 @@ CMake::CMake(const std::string &path, bool build) {
if (pkg.second.is_string()) {
p.version = pkg.second.as_string();
} else {
p.version = toml::find_or(pkg.second, "version", "");
p.required = toml::find_or(pkg.second, "required", false);
p.components = toml::find_or(pkg.second, "components", std::vector<std::string>());
p.version = toml::find_or(pkg.second, "version", p.version);
p.required = toml::find_or(pkg.second, "required", p.required);
p.config = toml::find_or(pkg.second, "config", p.config);
p.components = toml::find_or(pkg.second, "components", p.components);
}
packages.push_back(p);
}
@@ -186,8 +187,8 @@ CMake::CMake(const std::string &path, bool build) {
target.properties = toml::find<prop_map>(t, "properties");
}
target.cmake_before = toml::find_or(t, "cmake-before", "");
target.cmake_after = toml::find_or(t, "cmake-after", "");
target.cmake_before = toml::find_or(t, "cmake-before", target.cmake_before);
target.cmake_after = toml::find_or(t, "cmake-after", target.cmake_after);
target.include_before = optional_array(t, "include-before");
target.include_after = optional_array(t, "include-after");
@@ -218,6 +219,19 @@ CMake::CMake(const std::string &path, bool build) {
installs.push_back(inst);
}
}
if (toml.contains("vcpkg")) {
const auto &v = toml::find(toml, "vcpkg");
vcpkg.version = toml::find(v, "version").as_string();
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";
}
}
}
}
} // namespace cmake
+10 -2
View File
@@ -28,9 +28,15 @@ struct Package {
std::string name;
std::string version;
bool required = true;
bool config = true;
std::vector<std::string> components;
};
struct Vcpkg {
std::string version;
std::vector<std::string> packages;
};
enum TargetType {
target_executable,
target_library,
@@ -79,8 +85,9 @@ struct Install {
};
struct CMake {
std::string cmake_version;
std::string cmkr_include;
// This is the CMake version required to use all cmkr versions.
std::string cmake_version = "3.15";
std::string cmkr_include = "cmkr.cmake";
std::string build_dir = "build";
std::string generator;
std::string config;
@@ -101,6 +108,7 @@ struct CMake {
std::vector<Setting> settings;
std::vector<Option> options;
std::vector<Package> packages;
Vcpkg vcpkg;
tsl::ordered_map<std::string, std::map<std::string, std::string>> contents;
std::vector<Target> targets;
std::vector<Test> tests;
+27 -16
View File
@@ -231,10 +231,6 @@ struct Command {
template <class K, class V>
bool print_arg(const std::pair<K, V> &kv) {
std::stringstream tmp;
tmp << kv.second;
auto str = tmp.str();
if (kv.second.empty()) {
return true;
}
@@ -242,7 +238,7 @@ struct Command {
had_newline = true;
print_arg(kv.first);
depth++;
print_arg(str);
print_arg(kv.second);
depth--;
return true;
@@ -410,17 +406,6 @@ int generate_cmake(const char *path, bool root) {
inject_includes(cmake.include_after);
inject_cmake(cmake.cmake_after);
if (!cmake.packages.empty()) {
for (const auto &dep : cmake.packages) {
auto version = dep.version;
if (version == "*")
version.clear();
auto required = dep.required ? "REQUIRED" : "";
auto components = std::make_pair("COMPONENTS", dep.components);
cmd("find_package")(dep.name, version, required, components).endl();
}
}
if (!cmake.contents.empty()) {
cmd("include")("FetchContent").endl();
for (const auto &dep : cmake.contents) {
@@ -450,7 +435,32 @@ 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.packages.empty()) {
comment("Packages");
for (const auto &dep : cmake.packages) {
auto version = dep.version;
if (version == "*")
version.clear();
auto required = dep.required ? "REQUIRED" : "";
auto config = dep.config ? "CONFIG" : "";
auto components = std::make_pair("COMPONENTS", dep.components);
cmd("find_package")(dep.name, version, required, config, components).endl();
}
}
if (!cmake.options.empty()) {
comment("Options");
for (const auto &opt : cmake.options) {
cmd("option")(opt.name, opt.comment, opt.val ? "ON" : "OFF");
}
@@ -458,6 +468,7 @@ int generate_cmake(const char *path, bool root) {
}
if (!cmake.settings.empty()) {
comment("Settings");
for (const auto &set : cmake.settings) {
std::string set_val;
if (set.val.index() == 1) {