Browse Source

project files

master
Sergey Markov 3 years ago
parent
commit
61f63799ff
  1. 20
      CMakeLists.txt
  2. 18
      cmake/fmt.cmake
  3. 9
      cmake/toolchain.cmake
  4. 7
      cmake/wiringOP.cmake
  5. 68
      cmd_line_args.cpp
  6. 10
      cmd_line_args.h
  7. 6
      main.cpp

20
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)

18
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 <SOURCE_DIR>
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)

9
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)

7
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 ""
)

68
cmd_line_args.cpp

@ -0,0 +1,68 @@
#include <getopt.h>
#include <iostream>
#include <fmt/format.h>
#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};
}

10
cmd_line_args.h

@ -0,0 +1,10 @@
#ifndef CMD_LINE_ARGS_H
#define CMD_LINE_ARGS_H
#include <string>
struct parsed_opts {
std::string config_file;
};
parsed_opts parse_opts(int argc, char** argv);
#endif // CMD_LINE_ARGS_H

6
main.cpp

@ -0,0 +1,6 @@
#include "cmd_line_args.h"
int main(int argc, char** argv) {
parse_opts(argc, argv);
return 0;
}
Loading…
Cancel
Save