add mpark_variant

vcpkg-wip
Mohammed Alyousef 4 years ago
parent 369ef8f68d
commit 8d0c8678c4

@ -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.

@ -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})

@ -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"

@ -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"

@ -4,43 +4,15 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <mpark/variant.hpp>
namespace cmkr {
namespace cmake {
namespace detail {
template <typename T, typename O>
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<bool, std::string> val;
mpark::variant<bool, std::string> val;
bool cache = false;
bool force = false;
};

@ -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";
}

Loading…
Cancel
Save