diff --git a/CMakeLists.txt b/CMakeLists.txt index f9aac1c..b67dd89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ target_link_libraries(cmkrlib PUBLIC toml11 ghc_filesystem mpark_variant + ordered_map ) target_compile_features(cmkrlib PUBLIC diff --git a/cmake.toml b/cmake.toml index cd8f185..4afc89a 100644 --- a/cmake.toml +++ b/cmake.toml @@ -6,16 +6,14 @@ name = "cmkr" version = "0.1.3" inject-after = "add_subdirectory(third_party)" -[[target]] -name = "cmkrlib" +[target.cmkrlib] type = "static" sources = ["src/cmkrlib/*.cpp", "src/cmkrlib/*.hpp", "include/*.h"] include-directories = ["include"] compile-features = ["cxx_std_11"] -link-libraries = ["toml11", "ghc_filesystem", "mpark_variant"] +link-libraries = ["toml11", "ghc_filesystem", "mpark_variant", "ordered_map"] -[[target]] -name = "cmkr" +[target.cmkr] type = "executable" sources = ["src/main.cpp"] link-libraries = ["cmkrlib"] diff --git a/src/cmkrlib/cmake.cpp b/src/cmkrlib/cmake.cpp index 193ff0d..014015b 100644 --- a/src/cmkrlib/cmake.cpp +++ b/src/cmkrlib/cmake.cpp @@ -3,14 +3,15 @@ #include "fs.hpp" #include #include +#include namespace cmkr { namespace cmake { +using TomlBasicValue = toml::basic_value; + namespace detail { -std::vector to_string_vec( - const std::vector> - &vals) { +std::vector to_string_vec(const std::vector &vals) { std::vector temp; for (const auto &val : vals) temp.push_back(val.as_string()); @@ -22,7 +23,7 @@ CMake::CMake(const std::string &path, bool build) { if (!fs::exists(fs::path(path) / "cmake.toml")) { throw std::runtime_error("No cmake.toml was found!"); } - const auto toml = toml::parse((fs::path(path) / "cmake.toml").string()); + const auto toml = toml::parse((fs::path(path) / "cmake.toml").string()); if (build) { if (toml.contains("cmake")) { const auto &cmake = toml::find(toml, "cmake"); @@ -88,9 +89,7 @@ CMake::CMake(const std::string &path, bool build) { } if (toml.contains("settings")) { - using set_map = - std::map>; + using set_map = std::map; const auto &sets = toml::find(toml, "settings"); for (const auto set : sets) { Setting s; @@ -123,9 +122,7 @@ CMake::CMake(const std::string &path, bool build) { } if (toml.contains("options")) { - using opts_map = - std::map>; + using opts_map = tsl::ordered_map; const auto &opts = toml::find(toml, "options"); for (const auto opt : opts) { Option o; @@ -145,9 +142,7 @@ CMake::CMake(const std::string &path, bool build) { } if (toml.contains("find-package")) { - using pkg_map = - std::map>; + using pkg_map = tsl::ordered_map; const auto &pkgs = toml::find(toml, "find-package"); for (const auto &pkg : pkgs) { Package p; @@ -162,16 +157,16 @@ CMake::CMake(const std::string &path, bool build) { p.required = toml::find(pkg.second, "required").as_boolean(); } if (pkg.second.contains("components")) { - p.components = - detail::to_string_vec(toml::find(pkg.second, "components").as_array()); + p.components = detail::to_string_vec(toml::find(pkg.second, "components").as_array()); } } packages.push_back(p); } } + // TODO: refactor to std::vector instead of this hacky thing? if (toml.contains("fetch-content")) { - using content_map = std::map>; + using content_map = tsl::ordered_map>; contents = toml::find(toml, "fetch-content"); } @@ -180,18 +175,19 @@ CMake::CMake(const std::string &path, bool build) { } if (toml.contains("target")) { - const auto &ts = toml::find(toml, "target").as_array(); + const auto &ts = toml::find(toml, "target").as_table(); - for (const auto &t : ts) { + for (const auto &itr : ts) { + const auto &t = itr.second; Target target; - target.name = toml::find(t, "name").as_string(); + target.name = itr.first; target.type = toml::find(t, "type").as_string(); target.sources = detail::to_string_vec(toml::find(t, "sources").as_array()); -#define renamed(from, to) \ - if (t.contains(from)) { \ - throw std::runtime_error(from "has been renamed to " to); \ +#define renamed(from, to) \ + if (t.contains(from)) { \ + throw std::runtime_error(from "has been renamed to " to); \ } renamed("include-dirs", "include-directories"); @@ -202,23 +198,19 @@ CMake::CMake(const std::string &path, bool build) { #undef renamed if (t.contains("include-directories")) { - target.include_directories = - detail::to_string_vec(toml::find(t, "include-directories").as_array()); + target.include_directories = detail::to_string_vec(toml::find(t, "include-directories").as_array()); } if (t.contains("link-libraries")) { - target.link_libraries = - detail::to_string_vec(toml::find(t, "link-libraries").as_array()); + target.link_libraries = detail::to_string_vec(toml::find(t, "link-libraries").as_array()); } if (t.contains("compile-features")) { - target.compile_features = - detail::to_string_vec(toml::find(t, "compile-features").as_array()); + target.compile_features = detail::to_string_vec(toml::find(t, "compile-features").as_array()); } if (t.contains("compile-definitions")) { - target.compile_definitions = - detail::to_string_vec(toml::find(t, "compile-definitions").as_array()); + target.compile_definitions = detail::to_string_vec(toml::find(t, "compile-definitions").as_array()); } if (t.contains("alias")) { diff --git a/src/cmkrlib/cmake.hpp b/src/cmkrlib/cmake.hpp index 48d4434..2d91772 100644 --- a/src/cmkrlib/cmake.hpp +++ b/src/cmkrlib/cmake.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace cmkr { namespace cmake { @@ -76,7 +77,7 @@ struct CMake { std::vector settings; std::vector