Skip to content

Commit 5dc71f9

Browse files
committed
support building with C++11, adding linux github actions
1 parent ba2c52d commit 5dc71f9

File tree

9 files changed

+69
-25
lines changed

9 files changed

+69
-25
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
14-
os: [windows-latest, macos-10.15]
14+
os: [windows-latest, macos-10.15, ubuntu-18.04]
1515

1616
steps:
1717
- uses: actions/checkout@v2
1818
- name: Build
19-
run: cmake -S. -Bbin && cmake --build bin --config $BUILD_TYPE
19+
run: cmake -S. -Bbin && cmake --build bin --parallel --config $BUILD_TYPE

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ project(cmkr VERSION ${cmkr_PROJECT_VERSION})
1616

1717
include(FetchContent)
1818

19+
FetchContent_Declare(
20+
filesystem
21+
GIT_REPOSITORY https://github.com/gulrak/filesystem
22+
)
23+
24+
FetchContent_MakeAvailable(filesystem)
25+
1926
FetchContent_Declare(
2027
toml11
2128
GIT_REPOSITORY https://github.com/ToruNiina/toml11
@@ -39,10 +46,11 @@ target_include_directories(cmkrlib PUBLIC
3946

4047
target_link_libraries(cmkrlib PUBLIC
4148
toml11::toml11
49+
ghc_filesystem
4250
)
4351

4452
target_compile_features(cmkrlib PUBLIC
45-
cxx_std_17
53+
cxx_std_11
4654
)
4755

4856
set(CMKR_SOURCES

cmake.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ version = "0.1.2"
77

88
[fetch-content]
99
toml11 = { git = "https://github.com/ToruNiina/toml11" }
10+
filesystem = { git = "https://github.com/gulrak/filesystem" }
1011

1112
[[bin]]
1213
name = "cmkrlib"
1314
type = "static"
1415
sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"]
1516
include-dirs = ["include"]
16-
features = ["cxx_std_17"]
17-
link-libs = ["toml11::toml11"]
17+
features = ["cxx_std_11"]
18+
link-libs = ["toml11::toml11", "ghc_filesystem"]
1819

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

src/args.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
#include "help.h"
55

66
#include <exception>
7-
#include <filesystem>
7+
#include "fs.hpp"
88
#include <iostream>
99
#include <stdexcept>
1010
#include <string>
1111
#include <vector>
1212

13-
namespace fs = std::filesystem;
14-
1513
namespace cmkr::args {
1614
const char *handle_args(int argc, char **argv) {
1715
std::vector<std::string> args;

src/build.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
#include "error.h"
44
#include "gen.h"
55

6-
#include <filesystem>
6+
#include "fs.hpp"
77
#include <sstream>
88
#include <stddef.h>
99
#include <stdexcept>
1010
#include <stdlib.h>
1111
#include <system_error>
1212

13-
namespace fs = std::filesystem;
14-
1513
namespace cmkr::build {
1614

1715
int run(int argc, char **argv) {

src/cmake.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#include "cmake.hpp"
22

3-
#include <filesystem>
3+
#include "fs.hpp"
44
#include <stdexcept>
55
#include <toml.hpp>
66

7-
namespace fs = std::filesystem;
8-
97
namespace cmkr::cmake {
108

119
namespace detail {

src/cmake.hpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
#pragma once
22

33
#include <map>
4+
#include <stdexcept>
45
#include <string>
56
#include <vector>
6-
#include <variant>
77

88
namespace cmkr::cmake {
99

10+
namespace detail {
11+
template <typename T, typename O>
12+
struct Variant {
13+
T first;
14+
O second;
15+
Variant() {}
16+
Variant(const T &t) : first(t), tag(0) {}
17+
Variant(const O &o) : second(o), tag(1) {}
18+
Variant &operator=(const T &t) {
19+
tag = 0;
20+
first = t;
21+
return *this;
22+
}
23+
Variant &operator=(const O &o) {
24+
tag = 1;
25+
second = o;
26+
return *this;
27+
}
28+
char index() const {
29+
if (tag == -1)
30+
throw std::runtime_error("[cmkr] error: Internal error!");
31+
return tag;
32+
}
33+
34+
private:
35+
char tag = -1;
36+
};
37+
} // namespace detail
1038

1139
struct Setting {
1240
std::string name;
1341
std::string comment;
14-
std::variant<bool, std::string> val;
42+
detail::Variant<bool, std::string> val;
1543
bool cache = false;
1644
bool force = false;
1745
};

src/fs.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || \
4+
(defined(__cplusplus) && __cplusplus >= 201703L)) && \
5+
defined(__has_include)
6+
#if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
7+
#define GHC_USE_STD_FS
8+
#include <filesystem>
9+
namespace fs = std::filesystem;
10+
#endif
11+
#endif
12+
#ifndef GHC_USE_STD_FS
13+
#include <ghc/filesystem.hpp>
14+
namespace fs = ghc::filesystem;
15+
#endif

src/gen.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "error.h"
44
#include "literals.h"
55

6-
#include <filesystem>
6+
#include "fs.hpp"
77
#include <fstream>
88
#include <new>
99
#include <sstream>
@@ -12,8 +12,6 @@
1212
#include <string.h>
1313
#include <string>
1414

15-
namespace fs = std::filesystem;
16-
1715
namespace cmkr::gen {
1816

1917
namespace detail {
@@ -221,9 +219,9 @@ int generate_cmake(const char *path) {
221219
for (const auto &set : cmake.settings) {
222220
std::string set_val;
223221
if (set.val.index() == 1) {
224-
set_val = std::get<std::string>(set.val);
222+
set_val = set.val.second;
225223
} else {
226-
set_val = std::get<bool>(set.val) ? "ON" : "OFF";
224+
set_val = set.val.first ? "ON" : "OFF";
227225
}
228226
ss << "set(" << set.name << " " << set_val;
229227
;
@@ -256,8 +254,8 @@ int generate_cmake(const char *path) {
256254
bin_type = "";
257255
add_command = "add_library";
258256
} else {
259-
throw std::runtime_error(
260-
"[cmkr] error: Unknown binary type! Supported types are exe, lib, shared, static, interface");
257+
throw std::runtime_error("[cmkr] error: Unknown binary type! Supported types "
258+
"are exe, lib, shared, static, interface");
261259
}
262260

263261
if (!bin.sources.empty()) {
@@ -370,10 +368,10 @@ int generate_cmake(const char *path) {
370368
}
371369
}
372370
ss << "\n\tDESTINATION " << inst.destination << "\n\t";
373-
if (!inst.targets.empty())
371+
if (!inst.targets.empty())
374372
ss << "COMPONENT " << inst.targets[0] << "\n\t)\n\n";
375373
else
376-
ss << "\n\t)\n\n";
374+
ss << "\n\t)\n\n";
377375
}
378376
}
379377

0 commit comments

Comments
 (0)