diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a144fa..96eeb44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 0.1.3 - 2020-11-27 - Support building with C++11. - @mrexodia implemented CMake integration and bootstrapping. -- Add dependency on ghc_filesystem which is fetched automatically using FetchContent. +- Add dependency on ghc_filesystem and mpark_variant which are fetched automatically using FetchContent. ## 0.1.2 - 2020-11-20 - Add support for target properties. diff --git a/CMakeLists.txt b/CMakeLists.txt index 755bcc4..49827bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,14 @@ FetchContent_Declare( FetchContent_MakeAvailable(filesystem) +FetchContent_Declare( + mpark_variant + GIT_REPOSITORY https://github.com/mpark/variant + GIT_TAG v1.4.0 + ) + +FetchContent_MakeAvailable(mpark_variant) + FetchContent_Declare( toml11 GIT_REPOSITORY https://github.com/ToruNiina/toml11 @@ -31,22 +39,23 @@ FetchContent_Declare( FetchContent_MakeAvailable(toml11) set(CMKRLIB_SOURCES - "src/cmake.cpp" - "src/gen.cpp" - "src/help.cpp" - "src/build.cpp" - "src/error.cpp" + src/cmake.cpp + src/gen.cpp + src/help.cpp + src/build.cpp + src/error.cpp ) add_library(cmkrlib STATIC ${CMKRLIB_SOURCES}) target_include_directories(cmkrlib PUBLIC - "include" + include ) target_link_libraries(cmkrlib PUBLIC toml11::toml11 ghc_filesystem + mpark_variant ) target_compile_features(cmkrlib PUBLIC @@ -54,8 +63,8 @@ target_compile_features(cmkrlib PUBLIC ) set(CMKR_SOURCES - "src/main.cpp" - "src/args.cpp" + src/main.cpp + src/args.cpp ) add_executable(cmkr ${CMKR_SOURCES}) diff --git a/README.md b/README.md index 10524ae..5222a85 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ version = "0.1.3" [fetch-content] toml11 = { git = "https://github.com/ToruNiina/toml11" } filesystem = { git = "https://github.com/gulrak/filesystem" } +mpark_variant = { git = "https://github.com/mpark/variant", tag = "v1.4.0" } [[bin]] name = "cmkrlib" diff --git a/cmake.toml b/cmake.toml index f26aa93..8a55823 100644 --- a/cmake.toml +++ b/cmake.toml @@ -8,6 +8,7 @@ version = "0.1.3" [fetch-content] toml11 = { git = "https://github.com/ToruNiina/toml11" } filesystem = { git = "https://github.com/gulrak/filesystem" } +mpark_variant = { git = "https://github.com/mpark/variant", tag = "v1.4.0" } [[bin]] name = "cmkrlib" @@ -15,7 +16,7 @@ type = "static" sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"] include-dirs = ["include"] features = ["cxx_std_11"] -link-libs = ["toml11::toml11", "ghc_filesystem"] +link-libs = ["toml11::toml11", "ghc_filesystem", "mpark_variant"] [[bin]] name = "cmkr" diff --git a/src/cmake.hpp b/src/cmake.hpp index 534ee4b..215b873 100644 --- a/src/cmake.hpp +++ b/src/cmake.hpp @@ -4,43 +4,15 @@ #include #include #include +#include namespace cmkr { namespace cmake { -namespace detail { -template -struct Variant { - T first; - O second; - Variant() {} - Variant(const T &t) : first(t), tag(0) {} - Variant(const O &o) : second(o), tag(1) {} - Variant &operator=(const T &t) { - tag = 0; - first = t; - return *this; - } - Variant &operator=(const O &o) { - tag = 1; - second = o; - return *this; - } - char index() const { - if (tag == -1) - throw std::runtime_error("[cmkr] error: Internal error!"); - return tag; - } - - private: - char tag = -1; -}; -} // namespace detail - struct Setting { std::string name; std::string comment; - detail::Variant val; + mpark::variant val; bool cache = false; bool force = false; }; diff --git a/src/gen.cpp b/src/gen.cpp index 1bd33dc..827e12f 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -224,9 +224,9 @@ int generate_cmake(const char *path) { for (const auto &set : cmake.settings) { std::string set_val; if (set.val.index() == 1) { - set_val = set.val.second; + set_val = mpark::get<1>(set.val); } else { - set_val = set.val.first ? "ON" : "OFF"; + set_val = mpark::get<0>(set.val) ? "ON" : "OFF"; } ss << "set(" << set.name << " " << set_val; ; @@ -290,7 +290,7 @@ int generate_cmake(const char *path) { if (!bin.include_dirs.empty()) { ss << "target_include_directories(" << bin.name << " PUBLIC\n\t"; for (const auto &inc : bin.include_dirs) { - ss << fs::path(inc) << "\n\t"; + ss << fs::path(inc).string() << "\n\t"; } ss << ")\n\n"; }