aboutsummaryrefslogtreecommitdiff
path: root/src/autogen
diff options
context:
space:
mode:
Diffstat (limited to 'src/autogen')
-rw-r--r--src/autogen/CMakeLists.txt31
-rw-r--r--src/autogen/settings.h.in70
-rw-r--r--src/autogen/version.h.in21
3 files changed, 122 insertions, 0 deletions
diff --git a/src/autogen/CMakeLists.txt b/src/autogen/CMakeLists.txt
new file mode 100644
index 0000000..66065ee
--- /dev/null
+++ b/src/autogen/CMakeLists.txt
@@ -0,0 +1,31 @@
+find_program(PYTHON python3)
+
+# version.h
+configure_file(version.h.in version.h @ONLY)
+
+# settings.h
+add_custom_command(OUTPUT settings.h DEPENDS settings.h.in
+ COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/scripts/gen-default-cfg.py
+ --kconfig=${CMAKE_SOURCE_DIR}/Kconfig --dotconfig=${CMAKE_SOURCE_DIR}/linux/.config
+ --input=${CMAKE_CURRENT_SOURCE_DIR}/settings.h.in --output=settings.h)
+
+# poi_logos.h
+set(poi_logos ${CMAKE_SOURCE_DIR}/data/poi.svg ${CMAKE_SOURCE_DIR}/data/poi_window.svg)
+add_custom_command(OUTPUT poi_logos.h DEPENDS ${poi_logos}
+ COMMAND ${PYTHON} ${RCC} -o=poi_logos.h dump -ns=logos ${poi_logos})
+
+# poi_icons.h
+set(poi_icons icons/arrow-left.svg icons/arrow-right.svg icons/circle-x.svg icons/refresh.svg icons/home.svg)
+foreach(f ${poi_icons})
+ list(REMOVE_ITEM poi_icons ${f})
+ list(APPEND poi_icons ${ICONS_PATH}/${f})
+endforeach()
+add_custom_command(OUTPUT poi_icons.h DEPENDS ${poi_icons}
+ COMMAND ${PYTHON} ${RCC} -o=poi_icons.h dump -ns=icons ${poi_icons})
+
+# autogen target
+add_custom_target(py_autogen DEPENDS settings.h poi_logos.h poi_icons.h)
+
+add_library(autogen INTERFACE)
+target_include_directories(autogen INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
+add_dependencies(autogen py_autogen)
diff --git a/src/autogen/settings.h.in b/src/autogen/settings.h.in
new file mode 100644
index 0000000..51b2bd0
--- /dev/null
+++ b/src/autogen/settings.h.in
@@ -0,0 +1,70 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/cgit/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#pragma once
+
+#include <configuration.h>
+#include <fstream>
+#include <cstdlib>
+#include <filesystem>
+#include <array>
+#include <spdlog/spdlog.h>
+
+inline auto init_conf(const std::string &path)
+{
+ namespace fs = std::filesystem;
+ struct {
+ std::optional<fs::path> path;
+ std::unique_ptr<Configuration> ptr;
+ } conf;
+
+ conf.ptr = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({
+ @__DEFAULT_CFG__
+ });
+
+ conf.path = [&]() -> std::optional<fs::path> {
+ if(!path.empty()) {
+ return fs::path(path);
+ }
+
+ // 1000: invalid; 0: $HOME; 1: $XDG_CONFIG_HOME
+ std::array<std::optional<fs::path>, 2> home = { std::nullopt, std::nullopt };
+ if(const char* usr = std::getenv("HOME"))
+ home[0] = fs::path(usr);
+ if(const char* xdg = std::getenv("XDG_CONFIG_HOME"))
+ home[1] = fs::path(xdg);
+
+ for(const auto &pair : {
+ @__CONFIG_PATHS__
+ }) {
+ if(pair.first < 0) {
+ auto p = fs::path(pair.second);
+ spdlog::debug("Trying {}", p.c_str());
+ if(fs::exists(p))
+ return p;
+ } else if(home[static_cast<std::size_t>(pair.first)]) {
+ auto p = home[static_cast<std::size_t>(pair.first)].value() / pair.second;
+ spdlog::debug("Trying {}", p.c_str());
+ if(fs::exists(p))
+ return p;
+ }
+ }
+
+ return std::nullopt;
+
+ }();
+
+ if(conf.path) {
+ std::fstream file(conf.path.value(), std::fstream::in);
+ if(file.is_open()) {
+ conf.ptr->read(file);
+ file.close();
+ }
+ }
+ return conf;
+}
diff --git a/src/autogen/version.h.in b/src/autogen/version.h.in
new file mode 100644
index 0000000..4d50885
--- /dev/null
+++ b/src/autogen/version.h.in
@@ -0,0 +1,21 @@
+/*
+ * This file is part of smolbote. It's copyrighted by the contributors recorded
+ * in the version control history of the file, available from its original
+ * location: https://neueland.iserlohn-fortress.net/cgit/smolbote
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_VERSION_H
+#define SMOLBOTE_VERSION_H
+
+/*
+ * This is an automatically generated file, any changes to it may be overwritten.
+ * Edit src/version.h.in instead.
+ */
+
+#define POI_NAME "@CMAKE_PROJECT_NAME@"
+#define POI_VERSION "@CMAKE_PROJECT_VERSION@"
+#define POI_SHORT_VERSION "@CMAKE_PROJECT_SHORT_VERSION@"
+
+#endif // SMOLBOTE_VERSION_H