HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
cmake_install.hpp
1// Copyright Take Vos 2024.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/utility.hpp"
8#include "../macros.hpp"
9#include <filesystem>
10#include <string>
11#include <fstream>
12
13hi_export_module(hikogui.path.cmake_install);
14
15hi_export namespace hi { inline namespace v1 {
16
18 std::filesystem::path source_dir;
19};
20
28[[nodiscard]] inline std::optional<cmake_install> parse_cmake_install(std::filesystem::path path) noexcept
29{
30 if (not std::filesystem::exists(path)) {
31 return std::nullopt;
32 }
33
34 auto line = std::string{};
35 try {
36 auto fd = std::ifstream{path.string()};
37 line = getline(fd, 512);
38 fd.close();
39
40 } catch (...) {
41 return std::nullopt;
42 }
43
44 auto const cmake_install_start = std::string{"# Install script for directory: "};
45 if (not line.starts_with(cmake_install_start)) {
46 return std::nullopt;
47 }
48
49 auto source_dir = std::filesystem::path{line.substr(cmake_install_start.size())};
50 if (not std::filesystem::exists(source_dir)) {
51 return std::nullopt;
52 }
53
55}
56
57}}
std::optional< std::filesystem::path > source_dir() noexcept
Get the full path to source code of this executable.
Definition path_location_intf.hpp:219
The HikoGUI namespace.
Definition array_generic.hpp:20
std::basic_string< CharT, Traits > getline(std::basic_istream< CharT, Traits > &in, size_t max_size) noexcept
Get a line from an input string, upto a maximum size.
Definition misc.hpp:112
std::optional< cmake_install > parse_cmake_install(std::filesystem::path path) noexcept
Parse a cmake_install.cmake file.
Definition cmake_install.hpp:28
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition cmake_install.hpp:17
T substr(T... args)