From fa3b7a346c6ac5cdc1fc4eeef2c262d0293bf5cf Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Mon, 27 Dec 2021 11:45:23 +0100 Subject: [PATCH] Emit options and settings before the project() --- src/cmake_generator.cpp | 58 ++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index 1c1d815..5c91f90 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -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 &includes) { inject_includes(includes); }); gen.handle_condition(project.cmake_before, [&](const std::string &, const std::string &cmake) { inject_cmake(cmake); }); @@ -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);