Skip to content

Commit 8d0c867

Browse files
committed
add mpark_variant
1 parent 369ef8f commit 8d0c867

File tree

6 files changed

+26
-43
lines changed

6 files changed

+26
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## 0.1.3 - 2020-11-27
44
- Support building with C++11.
55
- @mrexodia implemented CMake integration and bootstrapping.
6-
- Add dependency on ghc_filesystem which is fetched automatically using FetchContent.
6+
- Add dependency on ghc_filesystem and mpark_variant which are fetched automatically using FetchContent.
77

88
## 0.1.2 - 2020-11-20
99
- Add support for target properties.

CMakeLists.txt

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ FetchContent_Declare(
2323

2424
FetchContent_MakeAvailable(filesystem)
2525

26+
FetchContent_Declare(
27+
mpark_variant
28+
GIT_REPOSITORY https://github.com/mpark/variant
29+
GIT_TAG v1.4.0
30+
)
31+
32+
FetchContent_MakeAvailable(mpark_variant)
33+
2634
FetchContent_Declare(
2735
toml11
2836
GIT_REPOSITORY https://github.com/ToruNiina/toml11
@@ -31,31 +39,32 @@ FetchContent_Declare(
3139
FetchContent_MakeAvailable(toml11)
3240

3341
set(CMKRLIB_SOURCES
34-
"src/cmake.cpp"
35-
"src/gen.cpp"
36-
"src/help.cpp"
37-
"src/build.cpp"
38-
"src/error.cpp"
42+
src/cmake.cpp
43+
src/gen.cpp
44+
src/help.cpp
45+
src/build.cpp
46+
src/error.cpp
3947
)
4048

4149
add_library(cmkrlib STATIC ${CMKRLIB_SOURCES})
4250

4351
target_include_directories(cmkrlib PUBLIC
44-
"include"
52+
include
4553
)
4654

4755
target_link_libraries(cmkrlib PUBLIC
4856
toml11::toml11
4957
ghc_filesystem
58+
mpark_variant
5059
)
5160

5261
target_compile_features(cmkrlib PUBLIC
5362
cxx_std_11
5463
)
5564

5665
set(CMKR_SOURCES
57-
"src/main.cpp"
58-
"src/args.cpp"
66+
src/main.cpp
67+
src/args.cpp
5968
)
6069

6170
add_executable(cmkr ${CMKR_SOURCES})

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ version = "0.1.3"
4040
[fetch-content]
4141
toml11 = { git = "https://github.com/ToruNiina/toml11" }
4242
filesystem = { git = "https://github.com/gulrak/filesystem" }
43+
mpark_variant = { git = "https://github.com/mpark/variant", tag = "v1.4.0" }
4344

4445
[[bin]]
4546
name = "cmkrlib"

cmake.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ version = "0.1.3"
88
[fetch-content]
99
toml11 = { git = "https://github.com/ToruNiina/toml11" }
1010
filesystem = { git = "https://github.com/gulrak/filesystem" }
11+
mpark_variant = { git = "https://github.com/mpark/variant", tag = "v1.4.0" }
1112

1213
[[bin]]
1314
name = "cmkrlib"
1415
type = "static"
1516
sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"]
1617
include-dirs = ["include"]
1718
features = ["cxx_std_11"]
18-
link-libs = ["toml11::toml11", "ghc_filesystem"]
19+
link-libs = ["toml11::toml11", "ghc_filesystem", "mpark_variant"]
1920

2021
[[bin]]
2122
name = "cmkr"

src/cmake.hpp

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,15 @@
44
#include <stdexcept>
55
#include <string>
66
#include <vector>
7+
#include <mpark/variant.hpp>
78

89
namespace cmkr {
910
namespace cmake {
1011

11-
namespace detail {
12-
template <typename T, typename O>
13-
struct Variant {
14-
T first;
15-
O second;
16-
Variant() {}
17-
Variant(const T &t) : first(t), tag(0) {}
18-
Variant(const O &o) : second(o), tag(1) {}
19-
Variant &operator=(const T &t) {
20-
tag = 0;
21-
first = t;
22-
return *this;
23-
}
24-
Variant &operator=(const O &o) {
25-
tag = 1;
26-
second = o;
27-
return *this;
28-
}
29-
char index() const {
30-
if (tag == -1)
31-
throw std::runtime_error("[cmkr] error: Internal error!");
32-
return tag;
33-
}
34-
35-
private:
36-
char tag = -1;
37-
};
38-
} // namespace detail
39-
4012
struct Setting {
4113
std::string name;
4214
std::string comment;
43-
detail::Variant<bool, std::string> val;
15+
mpark::variant<bool, std::string> val;
4416
bool cache = false;
4517
bool force = false;
4618
};

src/gen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ int generate_cmake(const char *path) {
224224
for (const auto &set : cmake.settings) {
225225
std::string set_val;
226226
if (set.val.index() == 1) {
227-
set_val = set.val.second;
227+
set_val = mpark::get<1>(set.val);
228228
} else {
229-
set_val = set.val.first ? "ON" : "OFF";
229+
set_val = mpark::get<0>(set.val) ? "ON" : "OFF";
230230
}
231231
ss << "set(" << set.name << " " << set_val;
232232
;
@@ -290,7 +290,7 @@ int generate_cmake(const char *path) {
290290
if (!bin.include_dirs.empty()) {
291291
ss << "target_include_directories(" << bin.name << " PUBLIC\n\t";
292292
for (const auto &inc : bin.include_dirs) {
293-
ss << fs::path(inc) << "\n\t";
293+
ss << fs::path(inc).string() << "\n\t";
294294
}
295295
ss << ")\n\n";
296296
}

0 commit comments

Comments
 (0)