Add support for include-before and include-after

vcpkg-wip
Duncan Ogilvie 4 years ago
parent 00969ee77d
commit 0e2cddcbe6

@ -71,8 +71,14 @@ CMake::CMake(const std::string &path, bool build) {
if (toml.contains("project")) { if (toml.contains("project")) {
const auto &project = toml::find(toml, "project"); const auto &project = toml::find(toml, "project");
proj_name = toml::find(project, "name").as_string(); project_name = toml::find(project, "name").as_string();
proj_version = toml::find(project, "version").as_string(); project_version = toml::find(project, "version").as_string();
if (project.contains("include-before")) {
include_before = detail::to_string_vec(toml::find(project, "include-before").as_array());
}
if (project.contains("include-after")) {
include_after = detail::to_string_vec(toml::find(project, "include-after").as_array());
}
} }
if (toml.contains("settings")) { if (toml.contains("settings")) {

@ -67,8 +67,10 @@ struct CMake {
std::vector<std::string> linkflags; std::vector<std::string> linkflags;
std::vector<std::string> gen_args; std::vector<std::string> gen_args;
std::vector<std::string> build_args; std::vector<std::string> build_args;
std::string proj_name; std::string project_name;
std::string proj_version; std::string project_version;
std::vector<std::string> include_before;
std::vector<std::string> include_after;
std::vector<Setting> settings; std::vector<Setting> settings;
std::vector<Option> options; std::vector<Option> options;
std::vector<Package> packages; std::vector<Package> packages;

@ -230,6 +230,15 @@ int generate_cmake(const char *path) {
comment("This file was generated automatically by cmkr.").endl(); comment("This file was generated automatically by cmkr.").endl();
if (!cmake.include_before.empty()) {
for (const auto &file : cmake.include_before) {
// TODO: warn/error if file doesn't exist?
cmd("include")(file);
}
endl();
}
// TODO: make this a setting in the toml?
comment("Regenerate CMakeLists.txt file when necessary"); comment("Regenerate CMakeLists.txt file when necessary");
cmd("include")("cmkr.cmake", "OPTIONAL", "RESULT_VARIABLE", "CMKR_INCLUDE_RESULT").endl(); cmd("include")("cmkr.cmake", "OPTIONAL", "RESULT_VARIABLE", "CMKR_INCLUDE_RESULT").endl();
@ -273,16 +282,24 @@ int generate_cmake(const char *path) {
for (const auto &dir : cmake.subdirs) { for (const auto &dir : cmake.subdirs) {
cmd("add_subdirectory")(dir); cmd("add_subdirectory")(dir);
} }
ss << '\n'; endl();
} }
if (!cmake.proj_name.empty() && !cmake.proj_version.empty()) { if (!cmake.project_name.empty() && !cmake.project_version.empty()) {
auto name = cmake.proj_name; auto name = cmake.project_name;
auto version = cmake.proj_version; auto version = cmake.project_version;
cmd("set")(name + "_PROJECT_VERSION", version); cmd("set")(name + "_PROJECT_VERSION", version);
cmd("project")(name, "VERSION", "${" + name + "_PROJECT_VERSION}").endl(); cmd("project")(name, "VERSION", "${" + name + "_PROJECT_VERSION}").endl();
} }
if (!cmake.include_after.empty()) {
for (const auto &file : cmake.include_after) {
// TODO: warn/error if file doesn't exist?
cmd("include")(file);
}
endl();
}
if (!cmake.packages.empty()) { if (!cmake.packages.empty()) {
for (const auto &dep : cmake.packages) { for (const auto &dep : cmake.packages) {
ss << "find_package(" << dep.name << ' '; ss << "find_package(" << dep.name << ' ';

Loading…
Cancel
Save