mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 00121c261f | |||
| df41d3eaff | |||
| e29c408854 | |||
| 8d0c8678c4 | |||
| 369ef8f68d | |||
| 861bd59676 | |||
| 1d1ea3fdfd |
@@ -16,4 +16,4 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Build
|
||||
run: cmake -S. -Bbin && cmake --build bin --parallel --config $BUILD_TYPE
|
||||
run: cmake -S. -Bbin -DCMAKE_BUILD_TYPE=$BUILD_TYPE && cmake --build bin --parallel --config $BUILD_TYPE
|
||||
|
||||
+6
-1
@@ -1,9 +1,14 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 0.1.4 - 2021-04-11
|
||||
- Use `GIT_SHALLOW ON` by default when getting git dependencies.
|
||||
- Add cmake.description field.
|
||||
- Change bin.defines to bin.definitions.
|
||||
|
||||
## 0.1.3 - 2020-11-27
|
||||
- Support building with C++11.
|
||||
- @mrexodia implemented CMake integration and bootstrapping.
|
||||
- Add dependency on ghc_filesystem which is fetched automatically using FetchContent.
|
||||
- Add dependency on ghc_filesystem and mpark_variant which are fetched automatically using FetchContent.
|
||||
|
||||
## 0.1.2 - 2020-11-20
|
||||
- Add support for target properties.
|
||||
|
||||
+23
-10
@@ -11,42 +11,55 @@ cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(cmkr_PROJECT_VERSION 0.1.3)
|
||||
project(cmkr VERSION ${cmkr_PROJECT_VERSION})
|
||||
project(cmkr
|
||||
VERSION 0.1.4
|
||||
LANGUAGES C CXX
|
||||
DESCRIPTION "CMakeLists generator from TOML"
|
||||
)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
filesystem
|
||||
GIT_REPOSITORY https://github.com/gulrak/filesystem
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(filesystem)
|
||||
|
||||
FetchContent_Declare(
|
||||
mpark_variant
|
||||
URL https://github.com/mpark/variant/archive/v1.4.0.tar.gz
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(mpark_variant)
|
||||
|
||||
FetchContent_Declare(
|
||||
toml11
|
||||
GIT_REPOSITORY https://github.com/ToruNiina/toml11
|
||||
GIT_SHALLOW ON
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(toml11)
|
||||
|
||||
set(CMKRLIB_SOURCES
|
||||
"src/cmake.cpp"
|
||||
"src/gen.cpp"
|
||||
"src/help.cpp"
|
||||
"src/build.cpp"
|
||||
"src/error.cpp"
|
||||
src/cmake.cpp
|
||||
src/gen.cpp
|
||||
src/help.cpp
|
||||
src/build.cpp
|
||||
src/error.cpp
|
||||
)
|
||||
|
||||
add_library(cmkrlib STATIC ${CMKRLIB_SOURCES})
|
||||
|
||||
target_include_directories(cmkrlib PUBLIC
|
||||
"include"
|
||||
include
|
||||
)
|
||||
|
||||
target_link_libraries(cmkrlib PUBLIC
|
||||
toml11::toml11
|
||||
ghc_filesystem
|
||||
mpark_variant
|
||||
)
|
||||
|
||||
target_compile_features(cmkrlib PUBLIC
|
||||
@@ -54,8 +67,8 @@ target_compile_features(cmkrlib PUBLIC
|
||||
)
|
||||
|
||||
set(CMKR_SOURCES
|
||||
"src/main.cpp"
|
||||
"src/args.cpp"
|
||||
src/main.cpp
|
||||
src/args.cpp
|
||||
)
|
||||
|
||||
add_executable(cmkr ${CMKR_SOURCES})
|
||||
|
||||
@@ -4,7 +4,7 @@ cmkr, pronounced "cmaker", is A CMakeLists.txt generator from TOML.
|
||||
|
||||
|
||||
## Building
|
||||
cmkr requires a C++17 compiler, cmake >= 3.15.
|
||||
cmkr requires a C++11 compiler, cmake >= 3.15.
|
||||
```
|
||||
git clone https://github.com/moalyousef/cmkr
|
||||
cd cmkr
|
||||
@@ -35,11 +35,13 @@ minimum = "3.15"
|
||||
|
||||
[project]
|
||||
name = "cmkr"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
description = "CMakeLists generator from TOML"
|
||||
|
||||
[fetch-content]
|
||||
toml11 = { git = "https://github.com/ToruNiina/toml11" }
|
||||
filesystem = { git = "https://github.com/gulrak/filesystem" }
|
||||
mpark_variant = { url = "https://github.com/mpark/variant/archive/v1.4.0.tar.gz" }
|
||||
|
||||
[[bin]]
|
||||
name = "cmkrlib"
|
||||
@@ -64,6 +66,7 @@ Currently supported fields:
|
||||
```toml
|
||||
[cmake] # required for top-level project
|
||||
minimum = "3.15" # required
|
||||
description = "" # optional
|
||||
subdirs = [] # optional
|
||||
bin-dir = "bin" # optional
|
||||
cpp-flags = [] # optional
|
||||
@@ -101,7 +104,7 @@ sources = ["src/*.cpp"] # required, supports globbing
|
||||
include-dirs = ["include"] # optional
|
||||
alias = "" # optional
|
||||
features = [] # optional
|
||||
defines = [] # optional
|
||||
definitions = [] # optional
|
||||
link-libs = [] # optional
|
||||
properties = { PROPERTY1 = "property1", ... } # optional
|
||||
|
||||
|
||||
+4
-2
@@ -1,13 +1,15 @@
|
||||
[cmake]
|
||||
minimum = "3.15"
|
||||
description = "CMakeLists generator from TOML"
|
||||
|
||||
[project]
|
||||
name = "cmkr"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
|
||||
[fetch-content]
|
||||
toml11 = { git = "https://github.com/ToruNiina/toml11" }
|
||||
filesystem = { git = "https://github.com/gulrak/filesystem" }
|
||||
mpark_variant = { url = "https://github.com/mpark/variant/archive/v1.4.0.tar.gz" }
|
||||
|
||||
[[bin]]
|
||||
name = "cmkrlib"
|
||||
@@ -15,7 +17,7 @@ type = "static"
|
||||
sources = ["src/cmake.cpp", "src/gen.cpp", "src/help.cpp", "src/build.cpp", "src/error.cpp"]
|
||||
include-dirs = ["include"]
|
||||
features = ["cxx_std_11"]
|
||||
link-libs = ["toml11::toml11", "ghc_filesystem"]
|
||||
link-libs = ["toml11::toml11", "ghc_filesystem", "mpark_variant"]
|
||||
|
||||
[[bin]]
|
||||
name = "cmkr"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
# Regenerate CMakeLists.txt file when necessary
|
||||
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
|
||||
|
||||
if(CMKR_INCLUDE_RESULT)
|
||||
cmkr()
|
||||
endif()
|
||||
@@ -14,7 +15,7 @@ set(example_PROJECT_VERSION 0.1.0)
|
||||
project(example VERSION ${example_PROJECT_VERSION})
|
||||
|
||||
set(EXAMPLE_SOURCES
|
||||
"src/example.cpp"
|
||||
src/example.cpp
|
||||
)
|
||||
|
||||
add_executable(example ${EXAMPLE_SOURCES})
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ sources = ["src/*.cpp"]
|
||||
include-dirs = ["include"]
|
||||
# alias = ""
|
||||
# features = []
|
||||
# defines = []
|
||||
# definitions = []
|
||||
# link-libs = []
|
||||
|
||||
[[install]]
|
||||
|
||||
+6
-2
@@ -48,6 +48,10 @@ CMake::CMake(const std::string &path, bool build) {
|
||||
const auto &cmake = toml::find(toml, "cmake");
|
||||
cmake_version = toml::find(cmake, "minimum").as_string();
|
||||
|
||||
if (cmake.contains("description")) {
|
||||
desc = toml::find(cmake, "description").as_string();
|
||||
}
|
||||
|
||||
if (cmake.contains("cpp-flags")) {
|
||||
cppflags = detail::to_string_vec(toml::find(cmake, "cpp-flags").as_array());
|
||||
}
|
||||
@@ -182,8 +186,8 @@ CMake::CMake(const std::string &path, bool build) {
|
||||
b.features = detail::to_string_vec(toml::find(bin, "features").as_array());
|
||||
}
|
||||
|
||||
if (bin.contains("defines")) {
|
||||
b.defines = detail::to_string_vec(toml::find(bin, "defines").as_array());
|
||||
if (bin.contains("definitions")) {
|
||||
b.defines = detail::to_string_vec(toml::find(bin, "definitions").as_array());
|
||||
}
|
||||
|
||||
if (bin.contains("alias")) {
|
||||
|
||||
+3
-30
@@ -4,43 +4,15 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <mpark/variant.hpp>
|
||||
|
||||
namespace cmkr {
|
||||
namespace 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;
|
||||
detail::Variant<bool, std::string> val;
|
||||
mpark::variant<bool, std::string> val;
|
||||
bool cache = false;
|
||||
bool force = false;
|
||||
};
|
||||
@@ -86,6 +58,7 @@ struct Install {
|
||||
|
||||
struct CMake {
|
||||
std::string cmake_version = "3.15";
|
||||
std::string desc;
|
||||
std::string bin_dir = "bin";
|
||||
std::string generator;
|
||||
std::string config;
|
||||
|
||||
+25
-14
@@ -38,17 +38,21 @@ std::string format(const char *fmt, Args... args) {
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::vector<fs::path> expand_path(const fs::path &p) {
|
||||
std::vector<fs::path> temp;
|
||||
static std::vector<std::string> expand_cmake_path(const fs::path &p) {
|
||||
std::vector<std::string> temp;
|
||||
if (p.filename().stem().string() == "*") {
|
||||
auto ext = p.extension();
|
||||
for (const auto &f : fs::directory_iterator(p.parent_path())) {
|
||||
if (f.path().extension() == ext) {
|
||||
temp.push_back(f.path());
|
||||
temp.push_back(f.path().string());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
temp.push_back(p);
|
||||
temp.push_back(p.string());
|
||||
}
|
||||
// Normalize all paths to work with CMake (it needs a / on Windows as well)
|
||||
for (auto &path : temp) {
|
||||
std::replace(path.begin(), path.end(), '\\', '/');
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
@@ -155,11 +159,13 @@ int generate_cmake(const char *path) {
|
||||
ss << "\n\n";
|
||||
}
|
||||
|
||||
std::string desc = "";
|
||||
if (!cmake.desc.empty())
|
||||
desc = "\n\tLANGUAGES C CXX\n\tDESCRIPTION \"" + cmake.desc + "\"";
|
||||
|
||||
if (!cmake.proj_name.empty() && !cmake.proj_version.empty()) {
|
||||
ss << "set(" << cmake.proj_name << "_PROJECT_VERSION " << cmake.proj_version << ")\n"
|
||||
<< "project(" << cmake.proj_name << " VERSION "
|
||||
<< "${" << cmake.proj_name << "_PROJECT_VERSION}"
|
||||
<< ")\n\n";
|
||||
ss << "project(" << cmake.proj_name << "\n\tVERSION " << cmake.proj_version << desc
|
||||
<< "\n\t)\n\n";
|
||||
}
|
||||
|
||||
if (!cmake.packages.empty()) {
|
||||
@@ -202,7 +208,12 @@ int generate_cmake(const char *path) {
|
||||
} else {
|
||||
// don't change arg
|
||||
}
|
||||
ss << "\t" << first_arg << " " << arg.second << "\n";
|
||||
if (first_arg != "GIT_REPOSITORY")
|
||||
ss << "\t" << first_arg << " " << arg.second << "\n";
|
||||
else
|
||||
ss << "\t" << first_arg << " " << arg.second << "\n\t"
|
||||
<< "GIT_SHALLOW "
|
||||
<< "ON\n";
|
||||
}
|
||||
ss << "\t)\n\n"
|
||||
<< "FetchContent_MakeAvailable(" << dep.first << ")\n\n";
|
||||
@@ -220,9 +231,9 @@ int generate_cmake(const char *path) {
|
||||
for (const auto &set : cmake.settings) {
|
||||
std::string set_val;
|
||||
if (set.val.index() == 1) {
|
||||
set_val = set.val.second;
|
||||
set_val = mpark::get<1>(set.val);
|
||||
} else {
|
||||
set_val = set.val.first ? "ON" : "OFF";
|
||||
set_val = mpark::get<0>(set.val) ? "ON" : "OFF";
|
||||
}
|
||||
ss << "set(" << set.name << " " << set_val;
|
||||
;
|
||||
@@ -263,7 +274,7 @@ int generate_cmake(const char *path) {
|
||||
ss << "set(" << detail::to_upper(bin.name) << "_SOURCES\n";
|
||||
for (const auto &src : bin.sources) {
|
||||
auto path = fs::path(src);
|
||||
auto expanded = detail::expand_path(path);
|
||||
auto expanded = detail::expand_cmake_path(path);
|
||||
for (const auto &f : expanded) {
|
||||
ss << "\t" << f << "\n";
|
||||
}
|
||||
@@ -286,7 +297,7 @@ int generate_cmake(const char *path) {
|
||||
if (!bin.include_dirs.empty()) {
|
||||
ss << "target_include_directories(" << bin.name << " PUBLIC\n\t";
|
||||
for (const auto &inc : bin.include_dirs) {
|
||||
ss << fs::path(inc) << "\n\t";
|
||||
ss << fs::path(inc).string() << "\n\t";
|
||||
}
|
||||
ss << ")\n\n";
|
||||
}
|
||||
@@ -357,7 +368,7 @@ int generate_cmake(const char *path) {
|
||||
if (!inst.files.empty()) {
|
||||
ss << "\tFILES ";
|
||||
for (const auto &file : inst.files) {
|
||||
auto path = detail::expand_path(fs::path(file));
|
||||
auto path = detail::expand_cmake_path(fs::path(file));
|
||||
for (const auto &f : path)
|
||||
ss << f << " ";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user