add mpark_variant

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

@ -3,7 +3,7 @@
## 0.1.3 - 2020-11-27 ## 0.1.3 - 2020-11-27
- Support building with C++11. - Support building with C++11.
- @mrexodia implemented CMake integration and bootstrapping. - @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 ## 0.1.2 - 2020-11-20
- Add support for target properties. - Add support for target properties.

@ -23,6 +23,14 @@ FetchContent_Declare(
FetchContent_MakeAvailable(filesystem) 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( FetchContent_Declare(
toml11 toml11
GIT_REPOSITORY https://github.com/ToruNiina/toml11 GIT_REPOSITORY https://github.com/ToruNiina/toml11
@ -31,22 +39,23 @@ FetchContent_Declare(
FetchContent_MakeAvailable(toml11) FetchContent_MakeAvailable(toml11)
set(CMKRLIB_SOURCES set(CMKRLIB_SOURCES
"src/cmake.cpp" src/cmake.cpp
"src/gen.cpp" src/gen.cpp
"src/help.cpp" src/help.cpp
"src/build.cpp" src/build.cpp
"src/error.cpp" src/error.cpp
) )
add_library(cmkrlib STATIC ${CMKRLIB_SOURCES}) add_library(cmkrlib STATIC ${CMKRLIB_SOURCES})
target_include_directories(cmkrlib PUBLIC target_include_directories(cmkrlib PUBLIC
"include" include
) )
target_link_libraries(cmkrlib PUBLIC target_link_libraries(cmkrlib PUBLIC
toml11::toml11 toml11::toml11
ghc_filesystem ghc_filesystem
mpark_variant
) )
target_compile_features(cmkrlib PUBLIC target_compile_features(cmkrlib PUBLIC
@ -54,8 +63,8 @@ target_compile_features(cmkrlib PUBLIC
) )
set(CMKR_SOURCES set(CMKR_SOURCES
"src/main.cpp" src/main.cpp
"src/args.cpp" src/args.cpp
) )
add_executable(cmkr ${CMKR_SOURCES}) add_executable(cmkr ${CMKR_SOURCES})

@ -40,6 +40,7 @@ version = "0.1.3"
[fetch-content] [fetch-content]
toml11 = { git = "https://github.com/ToruNiina/toml11" } toml11 = { git = "https://github.com/ToruNiina/toml11" }
filesystem = { git = "https://github.com/gulrak/filesystem" } filesystem = { git = "https://github.com/gulrak/filesystem" }
mpark_variant = { git = "https://github.com/mpark/variant", tag = "v1.4.0" }
[[bin]] [[bin]]
name = "cmkrlib" name = "cmkrlib"

@ -8,6 +8,7 @@ version = "0.1.3"
[fetch-content] [fetch-content]
toml11 = { git = "https://github.com/ToruNiina/toml11" } toml11 = { git = "https://github.com/ToruNiina/toml11" }
filesystem = { git = "https://github.com/gulrak/filesystem" } filesystem = { git = "https://github.com/gulrak/filesystem" }
mpark_variant = { git = "https://github.com/mpark/variant", tag = "v1.4.0" }
[[bin]] [[bin]]
name = "cmkrlib" name = "cmkrlib"
@ -15,7 +16,7 @@ type = "static"
sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"] sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"]
include-dirs = ["include"] include-dirs = ["include"]
features = ["cxx_std_11"] features = ["cxx_std_11"]
link-libs = ["toml11::toml11", "ghc_filesystem"] link-libs = ["toml11::toml11", "ghc_filesystem", "mpark_variant"]
[[bin]] [[bin]]
name = "cmkr" name = "cmkr"

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

@ -224,9 +224,9 @@ int generate_cmake(const char *path) {
for (const auto &set : cmake.settings) { for (const auto &set : cmake.settings) {
std::string set_val; std::string set_val;
if (set.val.index() == 1) { if (set.val.index() == 1) {
set_val = set.val.second; set_val = mpark::get<1>(set.val);
} else { } else {
set_val = set.val.first ? "ON" : "OFF"; set_val = mpark::get<0>(set.val) ? "ON" : "OFF";
} }
ss << "set(" << set.name << " " << set_val; ss << "set(" << set.name << " " << set_val;
; ;
@ -290,7 +290,7 @@ int generate_cmake(const char *path) {
if (!bin.include_dirs.empty()) { if (!bin.include_dirs.empty()) {
ss << "target_include_directories(" << bin.name << " PUBLIC\n\t"; ss << "target_include_directories(" << bin.name << " PUBLIC\n\t";
for (const auto &inc : bin.include_dirs) { for (const auto &inc : bin.include_dirs) {
ss << fs::path(inc) << "\n\t"; ss << fs::path(inc).string() << "\n\t";
} }
ss << ")\n\n"; ss << ")\n\n";
} }

Loading…
Cancel
Save