diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..814155f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.15.0) + +set(CMAKE_TOOLCHAIN_FILE cmake/toolchain.cmake) + +project(miner_scheduler VERSION 0.1.0) + +add_definitions(-DAPP_NAME="miner_scheduler") +add_definitions(-DAPP_VERSION="0.1.0") +add_definitions(-DAPP_GCC="${CMAKE_C_COMPILER_VERSION}") + +include(ExternalProject) +include(cmake/fmt.cmake) +include(cmake/wiringOP.cmake) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +add_executable(miner_scheduler main.cpp + cmd_line_args.cpp) + +add_dependencies(miner_scheduler fmt wiringOP) + diff --git a/cmake/fmt.cmake b/cmake/fmt.cmake new file mode 100644 index 0000000..c44cf42 --- /dev/null +++ b/cmake/fmt.cmake @@ -0,0 +1,18 @@ +ExternalProject_Add(fmt + URL https://github.com/fmtlib/fmt/archive/refs/tags/8.1.1.tar.gz + #CMAKE_ARGS -DEVENT__LIBRARY_TYPE:STRING=STATIC + INSTALL_COMMAND "" + CONFIGURE_COMMAND cmake -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake + BUILD_COMMAND make fmt + ) + +ExternalProject_Get_property(fmt BINARY_DIR) +set(FMT_BINARY_DIR ${BINARY_DIR}) + +ExternalProject_Get_property(fmt SOURCE_DIR) +set(FMT_SRC_DIR ${SOURCE_DIR}) + +include_directories(${FMT_SRC_DIR}/include) + +link_directories(${FMT_BINARY_DIR}) +link_libraries(fmt.a) diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake new file mode 100644 index 0000000..931f783 --- /dev/null +++ b/cmake/toolchain.cmake @@ -0,0 +1,9 @@ +set(CMAKE_AR /usr/bin/arm-linux-gnueabihf-ar) +set(CMAKE_ASM_COMPILER /usr/bin/arm-linux-gnueabihf-as) +set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc) +set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++) +set(CMAKE_LINKER /usr/bin/arm-linux-gnueabihf-ld) +set(CMAKE_OBJCOPY /usr/bin/arm-linux-gnueabihf-objcopy) +set(CMAKE_RANLIB /usr/bin/arm-linux-gnueabihf-ranlib) +set(CMAKE_SIZE /usr/bin/arm-linux-gnueabihf-size) +set(CMAKE_STRIP /usr/bin/arm-linux-gnueabihf-strip) \ No newline at end of file diff --git a/cmake/wiringOP.cmake b/cmake/wiringOP.cmake new file mode 100644 index 0000000..d2add80 --- /dev/null +++ b/cmake/wiringOP.cmake @@ -0,0 +1,7 @@ +ExternalProject_Add(wiringOP + GIT_REPOSITORY https://github.com/orangepi-xunlong/wiringOP + BUILD_IN_SOURCE true + CONFIGURE_COMMAND ./build clean + BUILD_COMMAND BOARD=orangepipc-h3 ./build + INSTALL_COMMAND "" +) \ No newline at end of file diff --git a/cmd_line_args.cpp b/cmd_line_args.cpp new file mode 100644 index 0000000..70fe071 --- /dev/null +++ b/cmd_line_args.cpp @@ -0,0 +1,68 @@ + +#include +#include +#include +#include "cmd_line_args.h" + +static struct option options[] = + { + {"help", no_argument, NULL, '?'}, + {"version", no_argument, NULL, 'v'}, + {"config-file", optional_argument, NULL, 'c'}, + {NULL, 0, NULL, 0 } + }; + +static constexpr auto optc = "?v:c:"; + +static constexpr auto help_format = + "{0} v{1}\n\n" + "Usage:\n" + "Availabe options are:\n" + "\t--help Show help\n" + "\t--config-file Config file path\n" + "\t--version Version of the {0}\n" + "\n" + "Usage example:\n" + "{0} --config-file=scheduler.conf\n" + "\n\n"; +static constexpr auto version_format = + "{0} v{1}\n\n" + "Build with gcc-{2}"; + +void usage() { + std::cout << fmt::format(help_format, APP_NAME, APP_VERSION) << std::endl; +} + +void version() { + std::cout << fmt::format(version_format, APP_NAME, APP_VERSION, APP_GCC) << std::endl; +} + +parsed_opts parse_opts(int argc, char** argv) { + if(argc < 1){ + exit(1); + } + + std::string config_file {""}; + + for(;;) { + int opt_idx, c; + + if((c = getopt_long(argc, argv, optc, options, &opt_idx)) == -1) break; + + switch(c) { + case '?': + usage(); + break; + case 'v': + version(); + break; + case 'c': + config_file = optarg; + break; + default: + exit(1); + } + } + + return {config_file}; +} \ No newline at end of file diff --git a/cmd_line_args.h b/cmd_line_args.h new file mode 100644 index 0000000..9bd4b7d --- /dev/null +++ b/cmd_line_args.h @@ -0,0 +1,10 @@ +#ifndef CMD_LINE_ARGS_H +#define CMD_LINE_ARGS_H +#include + +struct parsed_opts { + std::string config_file; +}; + +parsed_opts parse_opts(int argc, char** argv); +#endif // CMD_LINE_ARGS_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..763850f --- /dev/null +++ b/main.cpp @@ -0,0 +1,6 @@ +#include "cmd_line_args.h" + +int main(int argc, char** argv) { + parse_opts(argc, argv); + return 0; +}