Skip to content

Commit

Permalink
Emit options and settings before the project()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Dec 27, 2021
1 parent df1dbf7 commit fa3b7a3
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/cmake_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,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); });

Expand Down Expand Up @@ -673,35 +702,6 @@ void generate_cmake(const char *path, const parser::Project *parent_project) {
}
}

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);
Expand Down

0 comments on commit fa3b7a3

Please sign in to comment.