mirror of
https://github.com/build-cpp/cmkr
synced 2026-06-08 13:22:55 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f8ab24e0a2 | |||
| 16e68d7542 | |||
| 5dc71f9ba1 | |||
| ba2c52dd39 | |||
| 41b00b4f98 | |||
| b016d7139c | |||
| 473926bcfd | |||
| f29f9fa365 | |||
| 4c59ca75da | |||
| 1114aaca94 | |||
| 887f9e4ece |
@@ -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
|
||||
|
||||
+2
-1
@@ -4,4 +4,5 @@ compile_commands.json
|
||||
.clangd
|
||||
temp.*
|
||||
.vs
|
||||
.cache
|
||||
.cache
|
||||
build*/
|
||||
@@ -1,11 +1,17 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 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.
|
||||
|
||||
## 0.1.2 - 2020-11-20
|
||||
- Add support for target properties.
|
||||
- Add installs.
|
||||
- Require cmake >= 3.15.
|
||||
- Support settings and caching settings.
|
||||
- Support config when running cmkr build.
|
||||
- Add prompt prior to CMakeLists.txt generation if already existent in the current dir.
|
||||
|
||||
## 0.1.1 - 2020-11-19
|
||||
- Add support for globbing.
|
||||
|
||||
+18
-2
@@ -1,14 +1,28 @@
|
||||
# This file was generated automatically by cmkr.
|
||||
|
||||
# Regenerate CMakeLists.txt file when necessary
|
||||
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
|
||||
|
||||
if(CMKR_INCLUDE_RESULT)
|
||||
cmkr()
|
||||
endif()
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(cmkr_PROJECT_VERSION 0.1.2)
|
||||
set(cmkr_PROJECT_VERSION 0.1.3)
|
||||
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
|
||||
@@ -32,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
|
||||
@@ -52,6 +67,7 @@ target_link_libraries(cmkr PUBLIC
|
||||
install(
|
||||
TARGETS cmkr
|
||||
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
|
||||
COMPONENT cmkr
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -35,18 +35,19 @@ minimum = "3.15"
|
||||
|
||||
[project]
|
||||
name = "cmkr"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
|
||||
[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
-3
@@ -3,18 +3,19 @@ minimum = "3.15"
|
||||
|
||||
[project]
|
||||
name = "cmkr"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
|
||||
[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"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# This file was generated automatically by cmkr.
|
||||
|
||||
# Regenerate CMakeLists.txt file when necessary
|
||||
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
|
||||
if(CMKR_INCLUDE_RESULT)
|
||||
cmkr()
|
||||
endif()
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(example_PROJECT_VERSION 0.1.0)
|
||||
project(example VERSION ${example_PROJECT_VERSION})
|
||||
|
||||
set(EXAMPLE_SOURCES
|
||||
"src/example.cpp"
|
||||
)
|
||||
|
||||
add_executable(example ${EXAMPLE_SOURCES})
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# This is a minimal example project used for testing the cmkr bootstrapping process
|
||||
|
||||
[cmake]
|
||||
minimum = "3.15"
|
||||
|
||||
[project]
|
||||
name = "example"
|
||||
version = "0.1.0"
|
||||
|
||||
[[bin]]
|
||||
name = "example"
|
||||
type = "exe"
|
||||
sources = ["src/example.cpp"]
|
||||
@@ -0,0 +1,112 @@
|
||||
include_guard()
|
||||
|
||||
# Disable cmkr if no cmake.toml file is found
|
||||
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/cmake.toml)
|
||||
message(STATUS "[cmkr] Not found: ${CMAKE_CURRENT_LIST_DIR}/cmake.toml")
|
||||
macro(cmkr)
|
||||
endmacro()
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Add a build-time dependency on the contents of cmake.toml to regenerate the CMakeLists.txt when modified
|
||||
configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake.toml ${CMAKE_CURRENT_BINARY_DIR}/cmake.toml COPYONLY)
|
||||
|
||||
# Helper macro to execute a process (COMMAND_ERROR_IS_FATAL ANY is 3.19 and higher)
|
||||
macro(cmkr_exec)
|
||||
execute_process(COMMAND ${ARGV} RESULT_VARIABLE CMKR_EXEC_RESULT)
|
||||
if(NOT CMKR_EXEC_RESULT EQUAL 0)
|
||||
message(FATAL_ERROR "cmkr_exec(${ARGV}) failed (exit code ${CMKR_EXEC_RESULT})")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Windows-specific hack (CMAKE_EXECUTABLE_PREFIX is not set at the moment)
|
||||
if(WIN32)
|
||||
set(CMKR_EXECUTABLE_NAME "cmkr.exe")
|
||||
else()
|
||||
set(CMKR_EXECUTABLE_NAME "cmkr")
|
||||
endif()
|
||||
|
||||
# Use cached cmkr if found
|
||||
if(DEFINED CACHE{CMKR_EXECUTABLE} AND EXISTS ${CMKR_EXECUTABLE})
|
||||
message(VERBOSE "[cmkr] Found cmkr: '${CMKR_EXECUTABLE}'")
|
||||
else()
|
||||
if(DEFINED CACHE{CMKR_EXECUTABLE})
|
||||
message(VERBOSE "[cmkr] '${CMKR_EXECUTABLE}' not found")
|
||||
endif()
|
||||
set(CMKR_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/_cmkr)
|
||||
set(CMKR_EXECUTABLE ${CMAKE_CURRENT_BINARY_DIR}/_cmkr/bin/${CMKR_EXECUTABLE_NAME} CACHE INTERNAL "Full path to cmkr executable")
|
||||
if(NOT EXISTS ${CMKR_EXECUTABLE})
|
||||
message(VERBOSE "[cmkr] Bootstrapping '${CMKR_EXECUTABLE}'")
|
||||
message(STATUS "[cmkr] Fetching cmkr...")
|
||||
if(EXISTS ${CMKR_DIRECTORY})
|
||||
cmkr_exec(${CMAKE_COMMAND} -E rm -rf ${CMKR_DIRECTORY})
|
||||
endif()
|
||||
find_package(Git QUIET REQUIRED)
|
||||
set(CMKR_REPO "https://github.com/moalyousef/cmkr")
|
||||
cmkr_exec(${GIT_EXECUTABLE} clone ${CMKR_REPO} ${CMKR_DIRECTORY})
|
||||
cmkr_exec(${CMAKE_COMMAND} ${CMKR_DIRECTORY} -B${CMKR_DIRECTORY}/build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${CMKR_DIRECTORY})
|
||||
cmkr_exec(${CMAKE_COMMAND} --build ${CMKR_DIRECTORY}/build --parallel --config Release)
|
||||
cmkr_exec(${CMAKE_COMMAND} --install ${CMKR_DIRECTORY}/build --config Release --prefix ${CMKR_DIRECTORY} --component cmkr)
|
||||
if(NOT EXISTS ${CMKR_EXECUTABLE})
|
||||
message(FATAL_ERROR "[cmkr] Failed to bootstrap '${CMKR_EXECUTABLE}'")
|
||||
endif()
|
||||
cmkr_exec(${CMKR_EXECUTABLE} version OUTPUT_VARIABLE CMKR_VERSION)
|
||||
string(STRIP ${CMKR_VERSION} CMKR_VERSION)
|
||||
message(STATUS "[cmkr] Bootstrapped ${CMKR_EXECUTABLE}")
|
||||
else()
|
||||
message(VERBOSE "[cmkr] Found cmkr: '${CMKR_EXECUTABLE}'")
|
||||
endif()
|
||||
endif()
|
||||
execute_process(COMMAND ${CMKR_EXECUTABLE} version
|
||||
OUTPUT_VARIABLE CMKR_VERSION
|
||||
RESULT_VARIABLE CMKR_EXEC_RESULT
|
||||
)
|
||||
if(NOT CMKR_EXEC_RESULT EQUAL 0)
|
||||
unset(CMKR_EXECUTABLE CACHE)
|
||||
message(FATAL_ERROR "[cmkr] Failed to get version, try clearing the cache and rebuilding")
|
||||
endif()
|
||||
string(STRIP ${CMKR_VERSION} CMKR_VERSION)
|
||||
message(STATUS "[cmkr] Using ${CMKR_VERSION}")
|
||||
|
||||
# This is the macro that contains black magic
|
||||
macro(cmkr)
|
||||
# When this macro is called from the generated file, fake some internal CMake variables
|
||||
get_source_file_property(CMKR_CURRENT_LIST_FILE ${CMAKE_CURRENT_LIST_FILE} CMKR_CURRENT_LIST_FILE)
|
||||
if(CMKR_CURRENT_LIST_FILE)
|
||||
set(CMAKE_CURRENT_LIST_FILE ${CMKR_CURRENT_LIST_FILE})
|
||||
get_filename_component(CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_FILE} DIRECTORY)
|
||||
endif()
|
||||
|
||||
# File-based include guard (include_guard is not documented to work)
|
||||
get_source_file_property(CMKR_INCLUDE_GUARD ${CMAKE_CURRENT_LIST_FILE} CMKR_INCLUDE_GUARD)
|
||||
if(NOT CMKR_INCLUDE_GUARD)
|
||||
set_source_files_properties(${CMAKE_CURRENT_LIST_FILE} PROPERTIES CMKR_INCLUDE_GUARD TRUE)
|
||||
|
||||
# Generate CMakeLists.txt
|
||||
cmkr_exec(${CMKR_EXECUTABLE} gen -y
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
|
||||
OUTPUT_VARIABLE CMKR_GEN_OUTPUT
|
||||
)
|
||||
string(STRIP ${CMKR_GEN_OUTPUT} CMKR_GEN_OUTPUT)
|
||||
message(STATUS "[cmkr] ${CMKR_GEN_OUTPUT}")
|
||||
|
||||
# Copy the now-generated CMakeLists.txt to CMakerLists.txt
|
||||
# This is done because you cannot include() a file you are currently in
|
||||
set(CMKR_TEMP_FILE ${CMAKE_CURRENT_LIST_DIR}/CMakerLists.txt)
|
||||
configure_file(CMakeLists.txt ${CMKR_TEMP_FILE} COPYONLY)
|
||||
|
||||
# Add the macro required for the hack at the start of the cmkr macro
|
||||
set_source_files_properties(${CMKR_TEMP_FILE} PROPERTIES
|
||||
CMKR_CURRENT_LIST_FILE ${CMAKE_CURRENT_LIST_FILE}
|
||||
)
|
||||
|
||||
# 'Execute' the newly-generated CMakeLists.txt
|
||||
include(${CMKR_TEMP_FILE})
|
||||
|
||||
# Delete the generated file
|
||||
file(REMOVE ${CMKR_TEMP_FILE})
|
||||
|
||||
# Do not execute the rest of the original CMakeLists.txt
|
||||
return()
|
||||
endif()
|
||||
endmacro()
|
||||
@@ -0,0 +1,6 @@
|
||||
#include <cstdio>
|
||||
|
||||
int main()
|
||||
{
|
||||
puts("Hello from cmkr!");
|
||||
}
|
||||
+5
-2
@@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr::args {
|
||||
namespace cmkr {
|
||||
namespace args {
|
||||
|
||||
const char *handle_args(int argc, char **argv);
|
||||
}
|
||||
|
||||
} // namespace args
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+4
-2
@@ -2,7 +2,8 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace cmkr::build {
|
||||
namespace cmkr {
|
||||
namespace build {
|
||||
|
||||
int run(int argc, char **argv);
|
||||
|
||||
@@ -10,7 +11,8 @@ int clean();
|
||||
|
||||
int install();
|
||||
|
||||
} // namespace cmkr::build
|
||||
} // namespace build
|
||||
} // namespace cmkr
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
+4
-2
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr::error {
|
||||
namespace cmkr {
|
||||
namespace error {
|
||||
|
||||
struct Status {
|
||||
enum class Code {
|
||||
@@ -21,7 +22,8 @@ struct Status {
|
||||
Code ec_ = Code::Success;
|
||||
};
|
||||
|
||||
} // namespace cmkr::error
|
||||
} // namespace error
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+4
-2
@@ -1,13 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr::gen {
|
||||
namespace cmkr {
|
||||
namespace gen {
|
||||
|
||||
int generate_project(const char *typ);
|
||||
|
||||
int generate_cmake(const char *path);
|
||||
|
||||
} // namespace cmkr::gen
|
||||
} // namespace gen
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+4
-2
@@ -1,13 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
namespace cmkr::help {
|
||||
namespace cmkr {
|
||||
namespace help {
|
||||
|
||||
const char *version() noexcept;
|
||||
|
||||
const char *message() noexcept;
|
||||
|
||||
} // namespace cmkr::help
|
||||
} // namespace help
|
||||
} // namespace cmkr
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+21
-4
@@ -3,13 +3,15 @@
|
||||
#include "gen.h"
|
||||
#include "help.h"
|
||||
|
||||
#include "fs.hpp"
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cmkr::args {
|
||||
namespace cmkr {
|
||||
namespace args {
|
||||
const char *handle_args(int argc, char **argv) {
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
@@ -19,7 +21,21 @@ const char *handle_args(int argc, char **argv) {
|
||||
return "Please provide command line arguments!";
|
||||
std::string main_arg = args[1];
|
||||
if (main_arg == "gen") {
|
||||
auto ret = cmkr::gen::generate_cmake(std::filesystem::current_path().string().c_str());
|
||||
bool cont = false;
|
||||
if (args.size() > 2 && args[2] == "-y")
|
||||
cont = true;
|
||||
auto current_path = fs::current_path();
|
||||
if (fs::exists(current_path / "CMakeLists.txt") && cont == false) {
|
||||
std::cout
|
||||
<< "A CMakeLists.txt file already exists in the current directory.\nWould you "
|
||||
"like to overwrite it?[y/n]"
|
||||
<< std::endl;
|
||||
std::string resp;
|
||||
std::cin >> resp;
|
||||
if (resp != "y")
|
||||
return "CMake generation aborted!";
|
||||
}
|
||||
auto ret = cmkr::gen::generate_cmake(current_path.string().c_str());
|
||||
if (ret)
|
||||
return "CMake generation error!";
|
||||
return "CMake generation successful!";
|
||||
@@ -54,7 +70,8 @@ const char *handle_args(int argc, char **argv) {
|
||||
return "Unknown argument!";
|
||||
}
|
||||
}
|
||||
} // namespace cmkr::args
|
||||
} // namespace args
|
||||
} // namespace cmkr
|
||||
|
||||
const char *cmkr_args_handle_args(int argc, char **argv) {
|
||||
try {
|
||||
|
||||
+6
-7
@@ -3,16 +3,15 @@
|
||||
#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 {
|
||||
namespace cmkr {
|
||||
namespace build {
|
||||
|
||||
int run(int argc, char **argv) {
|
||||
cmake::CMake cmake(".", true);
|
||||
@@ -25,7 +24,7 @@ int run(int argc, char **argv) {
|
||||
|
||||
if (!fs::exists("CMakeLists.txt"))
|
||||
if (gen::generate_cmake("."))
|
||||
throw std::runtime_error("CMake generation failure!");
|
||||
throw std::runtime_error("[cmkr] error: CMake generation failure!");
|
||||
|
||||
ss << "cmake -S. -B" << cmake.bin_dir << " ";
|
||||
|
||||
@@ -65,8 +64,8 @@ int install() {
|
||||
auto cmd = "cmake --install " + cmake.bin_dir;
|
||||
return ::system(cmd.c_str());
|
||||
}
|
||||
|
||||
} // namespace cmkr::build
|
||||
} // namespace build
|
||||
} // namespace cmkr
|
||||
|
||||
int cmkr_build_run(int argc, char **argv) {
|
||||
try {
|
||||
|
||||
+6
-6
@@ -1,12 +1,11 @@
|
||||
#include "cmake.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include "fs.hpp"
|
||||
#include <stdexcept>
|
||||
#include <toml.hpp>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace cmkr::cmake {
|
||||
namespace cmkr {
|
||||
namespace cmake {
|
||||
|
||||
namespace detail {
|
||||
std::vector<std::string> to_string_vec(
|
||||
@@ -21,7 +20,7 @@ std::vector<std::string> to_string_vec(
|
||||
|
||||
CMake::CMake(const std::string &path, bool build) {
|
||||
if (!fs::exists(fs::path(path) / "cmake.toml")) {
|
||||
throw std::runtime_error("No cmake.toml was found!");
|
||||
throw std::runtime_error("[cmkr] error: No cmake.toml was found!");
|
||||
}
|
||||
const auto toml = toml::parse((fs::path(path) / "cmake.toml").string());
|
||||
if (build) {
|
||||
@@ -235,4 +234,5 @@ CMake::CMake(const std::string &path, bool build) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace cmkr::cmake
|
||||
} // namespace cmake
|
||||
} // namespace cmkr
|
||||
|
||||
+34
-4
@@ -1,17 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
namespace cmkr::cmake {
|
||||
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;
|
||||
std::variant<bool, std::string> val;
|
||||
detail::Variant<bool, std::string> val;
|
||||
bool cache = false;
|
||||
bool force = false;
|
||||
};
|
||||
@@ -78,4 +107,5 @@ struct CMake {
|
||||
CMake(const std::string &path, bool build);
|
||||
};
|
||||
|
||||
} // namespace cmkr::cmake
|
||||
} // namespace cmake
|
||||
} // namespace cmkr
|
||||
+4
-2
@@ -2,7 +2,8 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
namespace cmkr::error {
|
||||
namespace cmkr {
|
||||
namespace error {
|
||||
|
||||
Status::Status(Code ec) noexcept : ec_(ec) {}
|
||||
|
||||
@@ -10,7 +11,8 @@ Status::operator int() const noexcept { return static_cast<int>(ec_); }
|
||||
|
||||
Status::Code Status::code() const noexcept { return ec_; }
|
||||
|
||||
} // namespace cmkr::error
|
||||
} // namespace error
|
||||
} // namespace cmkr
|
||||
|
||||
const char *err_string[] = {
|
||||
"Success", "Runtime error", "Initialization error", "CMake generation error", "Build error",
|
||||
|
||||
+15
@@ -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
|
||||
+37
-18
@@ -3,7 +3,7 @@
|
||||
#include "error.h"
|
||||
#include "literals.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include "fs.hpp"
|
||||
#include <fstream>
|
||||
#include <new>
|
||||
#include <sstream>
|
||||
@@ -12,9 +12,8 @@
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace cmkr::gen {
|
||||
namespace cmkr {
|
||||
namespace gen {
|
||||
|
||||
namespace detail {
|
||||
|
||||
@@ -33,7 +32,7 @@ std::string format(const char *fmt, Args... args) {
|
||||
char *buf = new char[sz];
|
||||
int ret = snprintf(buf, sz, fmt, args...);
|
||||
if (ret != sz - 1)
|
||||
throw std::runtime_error("Error formatting string!");
|
||||
throw std::runtime_error("[cmkr] error: Error formatting string!");
|
||||
std::string temp(buf, buf + sz - 1);
|
||||
delete[] buf;
|
||||
return temp;
|
||||
@@ -80,7 +79,7 @@ int generate_project(const char *str) {
|
||||
dest = "include/" + dir_name;
|
||||
} else {
|
||||
throw std::runtime_error(
|
||||
"Unknown project type. Types are exe, lib, shared, static, interface!");
|
||||
"[cmkr] error: Unknown project type. Types are exe, lib, shared, static, interface!");
|
||||
}
|
||||
|
||||
const auto tomlbuf = detail::format(cmake_toml, dir_name.c_str(), dir_name.c_str(), str,
|
||||
@@ -109,7 +108,15 @@ int generate_cmake(const char *path) {
|
||||
if (fs::exists(fs::path(path) / "cmake.toml")) {
|
||||
cmake::CMake cmake(path, false);
|
||||
std::stringstream ss;
|
||||
ss << "# This file was generated automatically by cmkr.\n\n";
|
||||
ss << "# This file was generated automatically by cmkr.\n";
|
||||
ss << "\n";
|
||||
|
||||
ss << "# Regenerate CMakeLists.txt file when necessary\n";
|
||||
ss << "include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)\n\n";
|
||||
ss << "if(CMKR_INCLUDE_RESULT)\n";
|
||||
ss << "\tcmkr()\n";
|
||||
ss << "endif()\n";
|
||||
ss << "\n";
|
||||
|
||||
if (!cmake.cmake_version.empty()) {
|
||||
ss << "cmake_minimum_required(VERSION " << cmake.cmake_version << ")\n\n";
|
||||
@@ -213,18 +220,23 @@ 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;;
|
||||
ss << "set(" << set.name << " " << set_val;
|
||||
;
|
||||
if (set.cache) {
|
||||
std::string typ;
|
||||
if (set.val.index() == 1) typ = "STRING"; else typ = "BOOL";
|
||||
ss << " CACHE " << typ << " \"" << set.comment << "\"";
|
||||
if (set.force) ss << " FORCE";
|
||||
if (set.val.index() == 1)
|
||||
typ = "STRING";
|
||||
else
|
||||
typ = "BOOL";
|
||||
ss << " CACHE " << typ << " \"" << set.comment << "\"";
|
||||
if (set.force)
|
||||
ss << " FORCE";
|
||||
}
|
||||
ss << ")\n\n";
|
||||
ss << ")\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,8 +255,8 @@ int generate_cmake(const char *path) {
|
||||
bin_type = "";
|
||||
add_command = "add_library";
|
||||
} else {
|
||||
throw std::runtime_error(
|
||||
"Unknown binary type! Supported types are exe, shared and static");
|
||||
throw std::runtime_error("[cmkr] error: Unknown binary type! Supported types "
|
||||
"are exe, lib, shared, static, interface");
|
||||
}
|
||||
|
||||
if (!bin.sources.empty()) {
|
||||
@@ -356,7 +368,11 @@ int generate_cmake(const char *path) {
|
||||
ss << conf << " ";
|
||||
}
|
||||
}
|
||||
ss << "\n\tDESTINATION " << inst.destination << "\n\t)\n\n";
|
||||
ss << "\n\tDESTINATION " << inst.destination << "\n\t";
|
||||
if (!inst.targets.empty())
|
||||
ss << "COMPONENT " << inst.targets[0] << "\n\t)\n\n";
|
||||
else
|
||||
ss << "\n\t)\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,10 +390,13 @@ int generate_cmake(const char *path) {
|
||||
if (fs::exists(fs::path(sub) / "cmake.toml"))
|
||||
generate_cmake(sub.c_str());
|
||||
}
|
||||
} else {
|
||||
throw std::runtime_error("[cmkr] error: No cmake.toml found!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
} // namespace cmkr::gen
|
||||
} // namespace gen
|
||||
} // namespace cmkr
|
||||
|
||||
int cmkr_gen_generate_project(const char *typ) {
|
||||
try {
|
||||
|
||||
+5
-3
@@ -1,8 +1,9 @@
|
||||
#include "help.h"
|
||||
|
||||
namespace cmkr::help {
|
||||
namespace cmkr {
|
||||
namespace help {
|
||||
|
||||
const char *version() noexcept { return "cmkr version 0.1.2"; }
|
||||
const char *version() noexcept { return "cmkr version 0.1.3"; }
|
||||
|
||||
const char *message() noexcept {
|
||||
return R"lit(
|
||||
@@ -17,7 +18,8 @@ arguments:
|
||||
version Current cmkr version.
|
||||
)lit";
|
||||
}
|
||||
} // namespace cmkr::help
|
||||
} // namespace help
|
||||
} // namespace cmkr
|
||||
|
||||
const char *cmkr_help_version(void) { return cmkr::help::version(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user