support building with C++11, adding linux github actions

toml-checker
MoAlyousef 4 years ago
parent ba2c52dd39
commit 5dc71f9ba1

@ -11,9 +11,9 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-10.15]
os: [windows-latest, macos-10.15, ubuntu-18.04]
steps:
- uses: actions/checkout@v2
- name: Build
run: cmake -S. -Bbin && cmake --build bin --config $BUILD_TYPE
run: cmake -S. -Bbin && cmake --build bin --parallel --config $BUILD_TYPE

@ -16,6 +16,13 @@ project(cmkr VERSION ${cmkr_PROJECT_VERSION})
include(FetchContent)
FetchContent_Declare(
filesystem
GIT_REPOSITORY https://github.com/gulrak/filesystem
)
FetchContent_MakeAvailable(filesystem)
FetchContent_Declare(
toml11
GIT_REPOSITORY https://github.com/ToruNiina/toml11
@ -39,10 +46,11 @@ target_include_directories(cmkrlib PUBLIC
target_link_libraries(cmkrlib PUBLIC
toml11::toml11
ghc_filesystem
)
target_compile_features(cmkrlib PUBLIC
cxx_std_17
cxx_std_11
)
set(CMKR_SOURCES

@ -7,14 +7,15 @@ version = "0.1.2"
[fetch-content]
toml11 = { git = "https://github.com/ToruNiina/toml11" }
filesystem = { git = "https://github.com/gulrak/filesystem" }
[[bin]]
name = "cmkrlib"
type = "static"
sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"]
include-dirs = ["include"]
features = ["cxx_std_17"]
link-libs = ["toml11::toml11"]
features = ["cxx_std_11"]
link-libs = ["toml11::toml11", "ghc_filesystem"]
[[bin]]
name = "cmkr"

@ -4,14 +4,12 @@
#include "help.h"
#include <exception>
#include <filesystem>
#include "fs.hpp"
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
namespace fs = std::filesystem;
namespace cmkr::args {
const char *handle_args(int argc, char **argv) {
std::vector<std::string> args;

@ -3,15 +3,13 @@
#include "error.h"
#include "gen.h"
#include <filesystem>
#include "fs.hpp"
#include <sstream>
#include <stddef.h>
#include <stdexcept>
#include <stdlib.h>
#include <system_error>
namespace fs = std::filesystem;
namespace cmkr::build {
int run(int argc, char **argv) {

@ -1,11 +1,9 @@
#include "cmake.hpp"
#include <filesystem>
#include "fs.hpp"
#include <stdexcept>
#include <toml.hpp>
namespace fs = std::filesystem;
namespace cmkr::cmake {
namespace detail {

@ -1,17 +1,45 @@
#pragma once
#include <map>
#include <stdexcept>
#include <string>
#include <vector>
#include <variant>
namespace cmkr::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;
std::variant<bool, std::string> val;
detail::Variant<bool, std::string> val;
bool cache = false;
bool force = false;
};

@ -0,0 +1,15 @@
#pragma once
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || \
(defined(__cplusplus) && __cplusplus >= 201703L)) && \
defined(__has_include)
#if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS
#include <filesystem>
namespace fs = std::filesystem;
#endif
#endif
#ifndef GHC_USE_STD_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
#endif

@ -3,7 +3,7 @@
#include "error.h"
#include "literals.h"
#include <filesystem>
#include "fs.hpp"
#include <fstream>
#include <new>
#include <sstream>
@ -12,8 +12,6 @@
#include <string.h>
#include <string>
namespace fs = std::filesystem;
namespace cmkr::gen {
namespace detail {
@ -221,9 +219,9 @@ int generate_cmake(const char *path) {
for (const auto &set : cmake.settings) {
std::string set_val;
if (set.val.index() == 1) {
set_val = std::get<std::string>(set.val);
set_val = set.val.second;
} else {
set_val = std::get<bool>(set.val) ? "ON" : "OFF";
set_val = set.val.first ? "ON" : "OFF";
}
ss << "set(" << set.name << " " << set_val;
;
@ -256,8 +254,8 @@ int generate_cmake(const char *path) {
bin_type = "";
add_command = "add_library";
} else {
throw std::runtime_error(
"[cmkr] error: Unknown binary type! Supported types are exe, lib, shared, static, interface");
throw std::runtime_error("[cmkr] error: Unknown binary type! Supported types "
"are exe, lib, shared, static, interface");
}
if (!bin.sources.empty()) {
@ -370,10 +368,10 @@ int generate_cmake(const char *path) {
}
}
ss << "\n\tDESTINATION " << inst.destination << "\n\t";
if (!inst.targets.empty())
if (!inst.targets.empty())
ss << "COMPONENT " << inst.targets[0] << "\n\t)\n\n";
else
ss << "\n\t)\n\n";
ss << "\n\t)\n\n";
}
}

Loading…
Cancel
Save