diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0acb446..59a9ad7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index baabf9c..c28d2ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake.toml b/cmake.toml index d589dc0..c4fbb73 100644 --- a/cmake.toml +++ b/cmake.toml @@ -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" diff --git a/src/args.cpp b/src/args.cpp index 59b6665..0c43eec 100644 --- a/src/args.cpp +++ b/src/args.cpp @@ -4,14 +4,12 @@ #include "help.h" #include -#include +#include "fs.hpp" #include #include #include #include -namespace fs = std::filesystem; - namespace cmkr::args { const char *handle_args(int argc, char **argv) { std::vector args; diff --git a/src/build.cpp b/src/build.cpp index 8483ae0..ee0c3af 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -3,15 +3,13 @@ #include "error.h" #include "gen.h" -#include +#include "fs.hpp" #include #include #include #include #include -namespace fs = std::filesystem; - namespace cmkr::build { int run(int argc, char **argv) { diff --git a/src/cmake.cpp b/src/cmake.cpp index 0250609..a69ef56 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -1,11 +1,9 @@ #include "cmake.hpp" -#include +#include "fs.hpp" #include #include -namespace fs = std::filesystem; - namespace cmkr::cmake { namespace detail { diff --git a/src/cmake.hpp b/src/cmake.hpp index ae79680..f9902cb 100644 --- a/src/cmake.hpp +++ b/src/cmake.hpp @@ -1,17 +1,45 @@ #pragma once #include +#include #include #include -#include namespace cmkr::cmake { +namespace detail { +template +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 val; + detail::Variant val; bool cache = false; bool force = false; }; diff --git a/src/fs.hpp b/src/fs.hpp new file mode 100644 index 0000000..58f6e92 --- /dev/null +++ b/src/fs.hpp @@ -0,0 +1,15 @@ +#pragma once + +#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || \ + (defined(__cplusplus) && __cplusplus >= 201703L)) && \ + defined(__has_include) +#if __has_include() && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) +#define GHC_USE_STD_FS +#include +namespace fs = std::filesystem; +#endif +#endif +#ifndef GHC_USE_STD_FS +#include +namespace fs = ghc::filesystem; +#endif \ No newline at end of file diff --git a/src/gen.cpp b/src/gen.cpp index 40045c1..34dea32 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -3,7 +3,7 @@ #include "error.h" #include "literals.h" -#include +#include "fs.hpp" #include #include #include @@ -12,8 +12,6 @@ #include #include -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(set.val); + set_val = set.val.second; } else { - set_val = std::get(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"; } }