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

self-hosting
MoAlyousef 4 years ago
parent ba2c52dd39
commit 5dc71f9ba1

@ -11,9 +11,9 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [windows-latest, macos-10.15] os: [windows-latest, macos-10.15, ubuntu-18.04]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Build - 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) include(FetchContent)
FetchContent_Declare(
filesystem
GIT_REPOSITORY https://github.com/gulrak/filesystem
)
FetchContent_MakeAvailable(filesystem)
FetchContent_Declare( FetchContent_Declare(
toml11 toml11
GIT_REPOSITORY https://github.com/ToruNiina/toml11 GIT_REPOSITORY https://github.com/ToruNiina/toml11
@ -39,10 +46,11 @@ target_include_directories(cmkrlib PUBLIC
target_link_libraries(cmkrlib PUBLIC target_link_libraries(cmkrlib PUBLIC
toml11::toml11 toml11::toml11
ghc_filesystem
) )
target_compile_features(cmkrlib PUBLIC target_compile_features(cmkrlib PUBLIC
cxx_std_17 cxx_std_11
) )
set(CMKR_SOURCES set(CMKR_SOURCES

@ -7,14 +7,15 @@ version = "0.1.2"
[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" }
[[bin]] [[bin]]
name = "cmkrlib" name = "cmkrlib"
type = "static" 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_17"] features = ["cxx_std_11"]
link-libs = ["toml11::toml11"] link-libs = ["toml11::toml11", "ghc_filesystem"]
[[bin]] [[bin]]
name = "cmkr" name = "cmkr"

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

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

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

@ -1,17 +1,45 @@
#pragma once #pragma once
#include <map> #include <map>
#include <stdexcept>
#include <string> #include <string>
#include <vector> #include <vector>
#include <variant>
namespace cmkr::cmake { 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 { struct Setting {
std::string name; std::string name;
std::string comment; std::string comment;
std::variant<bool, std::string> val; detail::Variant<bool, std::string> val;
bool cache = false; bool cache = false;
bool force = 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 "error.h"
#include "literals.h" #include "literals.h"
#include <filesystem> #include "fs.hpp"
#include <fstream> #include <fstream>
#include <new> #include <new>
#include <sstream> #include <sstream>
@ -12,8 +12,6 @@
#include <string.h> #include <string.h>
#include <string> #include <string>
namespace fs = std::filesystem;
namespace cmkr::gen { namespace cmkr::gen {
namespace detail { namespace detail {
@ -221,9 +219,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 = std::get<std::string>(set.val); set_val = set.val.second;
} else { } else {
set_val = std::get<bool>(set.val) ? "ON" : "OFF"; set_val = set.val.first ? "ON" : "OFF";
} }
ss << "set(" << set.name << " " << set_val; ss << "set(" << set.name << " " << set_val;
; ;
@ -256,8 +254,8 @@ int generate_cmake(const char *path) {
bin_type = ""; bin_type = "";
add_command = "add_library"; add_command = "add_library";
} else { } else {
throw std::runtime_error( throw std::runtime_error("[cmkr] error: Unknown binary type! Supported types "
"[cmkr] error: Unknown binary type! Supported types are exe, lib, shared, static, interface"); "are exe, lib, shared, static, interface");
} }
if (!bin.sources.empty()) { if (!bin.sources.empty()) {
@ -370,10 +368,10 @@ int generate_cmake(const char *path) {
} }
} }
ss << "\n\tDESTINATION " << inst.destination << "\n\t"; ss << "\n\tDESTINATION " << inst.destination << "\n\t";
if (!inst.targets.empty()) if (!inst.targets.empty())
ss << "COMPONENT " << inst.targets[0] << "\n\t)\n\n"; ss << "COMPONENT " << inst.targets[0] << "\n\t)\n\n";
else else
ss << "\n\t)\n\n"; ss << "\n\t)\n\n";
} }
} }

Loading…
Cancel
Save