Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
9337964266 | |||
49b2117f13 | |||
3da87609f4 | |||
32e0a46a7f | |||
88751694a5 | |||
9a5bad2335 | |||
26ae664334 | |||
83a01f2941 | |||
146dca1359 | |||
2947c31263 | |||
20d9c64161 | |||
8adbb9478e | |||
2fb329a302 | |||
91bbae667c | |||
bb08020611 | |||
1cca2b7406 |
35
.drone.yml
35
.drone.yml
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- fill-column: 1000 -*-
|
||||||
|
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
name: build x86_64
|
name: build x86_64
|
||||||
|
|
||||||
|
@ -11,6 +13,7 @@ trigger:
|
||||||
exclude:
|
exclude:
|
||||||
- tag
|
- tag
|
||||||
|
|
||||||
|
steps:
|
||||||
- name: gcc5
|
- name: gcc5
|
||||||
image: debian:stretch-slim
|
image: debian:stretch-slim
|
||||||
pull: always
|
pull: always
|
||||||
|
@ -22,23 +25,47 @@ trigger:
|
||||||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
- apt-get update -q
|
- apt-get update -q
|
||||||
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
||||||
- echo "deb http://deb.debian.org/debian sid main" >> /etc/apt/sources.list.d/sid.list
|
|
||||||
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
||||||
- apt-get install -qy gnupg
|
- apt-get install -qy gnupg
|
||||||
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
||||||
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||||
- apt-get update -q
|
- apt-get update -q
|
||||||
- apt-get install -qy -t xenial g++-5
|
- apt-get install -qy -t xenial g++-5
|
||||||
- apt-get install -qy cmake pkg-config
|
- apt-get install -qy cmake pkg-config libconfig++-dev libxdg-basedir-dev catch
|
||||||
- apt-get install -qy libconfig++-dev libxdg-basedir-dev
|
|
||||||
- rm -rf build && mkdir -p build && cd build
|
- rm -rf build && mkdir -p build && cd build
|
||||||
- cmake ..
|
- cmake -DWITH_TESTS=YES -DWITH_EXAMPLES=YES ..
|
||||||
- make VERBOSE=1
|
- make VERBOSE=1
|
||||||
- make install DESTDIR=install
|
- make install DESTDIR=install
|
||||||
|
- cd tests && ctest -Q
|
||||||
volumes:
|
volumes:
|
||||||
- name: debian-package-cache
|
- name: debian-package-cache
|
||||||
path: /var/cache/apt/archives
|
path: /var/cache/apt/archives
|
||||||
|
|
||||||
|
- name: gcc9
|
||||||
|
image: debian:stretch-slim
|
||||||
|
pull: always
|
||||||
|
environment:
|
||||||
|
CXX: g++-9
|
||||||
|
CXXFLAGS: -pipe -O2
|
||||||
|
LANG: en_US.utf-8
|
||||||
|
commands:
|
||||||
|
- rm /etc/apt/apt.conf.d/docker-clean
|
||||||
|
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||||
|
- apt-get update -q
|
||||||
|
- echo "APT::Default-Release \"stretch\";" >> /etc/apt/apt.conf.d/00default_release
|
||||||
|
- echo "deb http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu xenial main" >> /etc/apt/sources.list.d/ubuntu-toolchain-r.list
|
||||||
|
- apt-get install -qy gnupg
|
||||||
|
- gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0x60c317803a41ba51845e371a1e9377a2ba9ef27f
|
||||||
|
- gpg --armor --export 0x60c317803a41ba51845e371a1e9377a2ba9ef27f | apt-key add -
|
||||||
|
- apt-get update -q
|
||||||
|
- apt-get install -qy -t xenial g++-9
|
||||||
|
- apt-get install -qy cmake pkg-config libconfig++-dev libxdg-basedir-dev catch
|
||||||
|
- rm -rf build && mkdir -p build && cd build
|
||||||
|
- cmake -DWITH_TESTS=YES -DWITH_EXAMPLES=YES ..
|
||||||
|
- make VERBOSE=1
|
||||||
|
- make install DESTDIR=install
|
||||||
|
- cd tests && ctest -Q
|
||||||
|
|
||||||
- name: notify
|
- name: notify
|
||||||
image: drillster/drone-email
|
image: drillster/drone-email
|
||||||
pull: always
|
pull: always
|
||||||
|
|
|
@ -1,42 +1,57 @@
|
||||||
cmake_minimum_required (VERSION 3.1)
|
# Support version 3.6 and above, but use policy settings up to 3.14.
|
||||||
|
# 3.6 is needed because of IMPORTED_TARGET in pkg_check_modules().
|
||||||
|
cmake_minimum_required(VERSION 3.6...3.14)
|
||||||
|
# Ranges are supported from 3.12, set policy to current for < 3.12.
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS 3.12)
|
||||||
|
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
||||||
|
endif()
|
||||||
|
|
||||||
project(xdgcfg
|
project(xdgcfg
|
||||||
VERSION 0.3.1
|
VERSION 0.5.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
# DESCRIPTION was introduced in version 3.9.
|
||||||
|
if(NOT (${CMAKE_VERSION} VERSION_LESS 3.9))
|
||||||
|
set(PROJECT_DESCRIPTION
|
||||||
|
"Wrapper around libconfig that writes and reads files in XDG_CONFIG_HOME.")
|
||||||
|
endif()
|
||||||
|
|
||||||
set(WITH_EXAMPLES "NO" CACHE STRING "WITH_EXAMPLES defaults to \"NO\"")
|
# All custom build switches.
|
||||||
set(WITH_TESTS "NO" CACHE STRING "WITH_TESTS defaults to \"NO\"")
|
option(WITH_EXAMPLES "Compile examples." NO)
|
||||||
|
option(WITH_TESTS "Compile tests." NO)
|
||||||
include(GNUInstallDirs)
|
option(BUILD_SHARED_LIBS "Build shared libraries." YES)
|
||||||
find_package(PkgConfig REQUIRED)
|
|
||||||
pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir)
|
|
||||||
pkg_check_modules(LIBCONFIG REQUIRED libconfig++)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS NO)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG
|
set(DEBUG_CXXFLAGS
|
||||||
"${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Wpedantic -ftrapv \
|
"-Wall"
|
||||||
-fsanitize=undefined -g -Og -fno-omit-frame-pointer")
|
"-Wextra"
|
||||||
|
"-Wpedantic"
|
||||||
|
"-ftrapv"
|
||||||
|
"-fsanitize=undefined"
|
||||||
|
"-g"
|
||||||
|
"-Og"
|
||||||
|
"-fno-omit-frame-pointer")
|
||||||
|
set(DEBUG_LDFLAGS
|
||||||
|
"-fsanitize=undefined")
|
||||||
|
add_compile_options("$<$<CONFIG:Debug>:${DEBUG_CXXFLAGS}>")
|
||||||
|
# add_link_options was introduced in version 3.13.
|
||||||
|
if(${CMAKE_VERSION} VERSION_LESS 3.13)
|
||||||
|
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${DEBUG_LDFLAGS}")
|
||||||
|
else()
|
||||||
|
add_link_options("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
|
||||||
|
endif()
|
||||||
|
|
||||||
include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS})
|
add_subdirectory(src)
|
||||||
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
add_subdirectory(pkg-config)
|
||||||
|
add_subdirectory(cmake)
|
||||||
|
|
||||||
link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS})
|
if(WITH_EXAMPLES)
|
||||||
link_directories(${LIBCONFIG_LIBRARY_DIRS})
|
add_subdirectory(examples)
|
||||||
|
|
||||||
set(COMMON_LIBRARIES
|
|
||||||
${LIBXDG_BASEDIR_LIBRARIES} ${LIBCONFIG_LIBRARIES} stdc++fs)
|
|
||||||
|
|
||||||
if (WITH_EXAMPLES)
|
|
||||||
add_executable(example src/example.cpp)
|
|
||||||
target_link_libraries(example
|
|
||||||
${COMMON_LIBRARIES})
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(WITH_TESTS)
|
if(WITH_TESTS)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
install(FILES src/xdgcfg.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
||||||
|
|
194
Doxyfile
194
Doxyfile
|
@ -1,198 +1,28 @@
|
||||||
DOXYFILE_ENCODING = UTF-8
|
# -*- mode: conf-unix -*-
|
||||||
PROJECT_NAME = "xdgcfg"
|
PROJECT_NAME = "xdgcfg"
|
||||||
PROJECT_NUMBER = 0.0.0
|
PROJECT_NUMBER = 0.0.0
|
||||||
INPUT = README.md src/
|
INPUT = README.md include/ src/
|
||||||
USE_MDFILE_AS_MAINPAGE = README.md
|
USE_MDFILE_AS_MAINPAGE = README.md
|
||||||
CREATE_SUBDIRS = NO
|
EXAMPLE_PATH = examples/
|
||||||
|
EXAMPLE_RECURSIVE = YES
|
||||||
|
GENERATE_HTML = YES
|
||||||
|
HTML_OUTPUT = doc/html
|
||||||
|
GENERATE_LATEX = NO
|
||||||
ALLOW_UNICODE_NAMES = YES
|
ALLOW_UNICODE_NAMES = YES
|
||||||
OUTPUT_LANGUAGE = English
|
|
||||||
BRIEF_MEMBER_DESC = YES
|
BRIEF_MEMBER_DESC = YES
|
||||||
REPEAT_BRIEF = YES
|
REPEAT_BRIEF = YES
|
||||||
ALWAYS_DETAILED_SEC = NO
|
ALWAYS_DETAILED_SEC = YES
|
||||||
INLINE_INHERITED_MEMB = NO
|
INLINE_INHERITED_MEMB = NO
|
||||||
FULL_PATH_NAMES = YES
|
|
||||||
SHORT_NAMES = NO
|
|
||||||
JAVADOC_AUTOBRIEF = NO
|
|
||||||
QT_AUTOBRIEF = NO
|
|
||||||
MULTILINE_CPP_IS_BRIEF = NO
|
|
||||||
INHERIT_DOCS = YES
|
INHERIT_DOCS = YES
|
||||||
SEPARATE_MEMBER_PAGES = NO
|
SEPARATE_MEMBER_PAGES = NO
|
||||||
TAB_SIZE = 4
|
TAB_SIZE = 4
|
||||||
OPTIMIZE_OUTPUT_FOR_C = NO
|
|
||||||
OPTIMIZE_OUTPUT_JAVA = NO
|
|
||||||
OPTIMIZE_FOR_FORTRAN = NO
|
|
||||||
OPTIMIZE_OUTPUT_VHDL = NO
|
|
||||||
MARKDOWN_SUPPORT = YES
|
MARKDOWN_SUPPORT = YES
|
||||||
AUTOLINK_SUPPORT = YES
|
AUTOLINK_SUPPORT = YES
|
||||||
BUILTIN_STL_SUPPORT = NO
|
|
||||||
CPP_CLI_SUPPORT = NO
|
|
||||||
SIP_SUPPORT = NO
|
|
||||||
IDL_PROPERTY_SUPPORT = YES
|
|
||||||
DISTRIBUTE_GROUP_DOC = NO
|
|
||||||
GROUP_NESTED_COMPOUNDS = NO
|
|
||||||
SUBGROUPING = YES
|
|
||||||
INLINE_GROUPED_CLASSES = NO
|
|
||||||
INLINE_SIMPLE_STRUCTS = NO
|
INLINE_SIMPLE_STRUCTS = NO
|
||||||
TYPEDEF_HIDES_STRUCT = NO
|
|
||||||
LOOKUP_CACHE_SIZE = 0
|
|
||||||
EXTRACT_ALL = NO
|
|
||||||
EXTRACT_PRIVATE = NO
|
|
||||||
EXTRACT_PACKAGE = NO
|
|
||||||
EXTRACT_STATIC = NO
|
|
||||||
EXTRACT_LOCAL_CLASSES = YES
|
|
||||||
EXTRACT_LOCAL_METHODS = NO
|
|
||||||
EXTRACT_ANON_NSPACES = NO
|
|
||||||
HIDE_UNDOC_MEMBERS = NO
|
|
||||||
HIDE_UNDOC_CLASSES = NO
|
|
||||||
HIDE_FRIEND_COMPOUNDS = NO
|
|
||||||
HIDE_IN_BODY_DOCS = NO
|
|
||||||
INTERNAL_DOCS = NO
|
|
||||||
CASE_SENSE_NAMES = YES
|
|
||||||
HIDE_SCOPE_NAMES = NO
|
|
||||||
HIDE_COMPOUND_REFERENCE= NO
|
|
||||||
SHOW_INCLUDE_FILES = YES
|
|
||||||
SHOW_GROUPED_MEMB_INC = NO
|
|
||||||
FORCE_LOCAL_INCLUDES = NO
|
|
||||||
INLINE_INFO = YES
|
|
||||||
SORT_MEMBER_DOCS = YES
|
|
||||||
SORT_BRIEF_DOCS = NO
|
|
||||||
SORT_MEMBERS_CTORS_1ST = NO
|
|
||||||
SORT_GROUP_NAMES = NO
|
|
||||||
SORT_BY_SCOPE_NAME = NO
|
|
||||||
STRICT_PROTO_MATCHING = NO
|
|
||||||
GENERATE_TODOLIST = YES
|
|
||||||
GENERATE_TESTLIST = YES
|
|
||||||
GENERATE_BUGLIST = YES
|
|
||||||
GENERATE_DEPRECATEDLIST= YES
|
|
||||||
MAX_INITIALIZER_LINES = 30
|
|
||||||
SHOW_USED_FILES = YES
|
|
||||||
SHOW_FILES = YES
|
|
||||||
SHOW_NAMESPACES = YES
|
|
||||||
QUIET = NO
|
QUIET = NO
|
||||||
WARNINGS = YES
|
WARNINGS = YES
|
||||||
WARN_IF_UNDOCUMENTED = YES
|
BUILTIN_STL_SUPPORT = YES
|
||||||
WARN_IF_DOC_ERROR = YES
|
|
||||||
WARN_NO_PARAMDOC = NO
|
|
||||||
WARN_FORMAT = "$file:$line: $text"
|
|
||||||
INPUT_ENCODING = UTF-8
|
|
||||||
RECURSIVE = NO
|
|
||||||
EXCLUDE_SYMLINKS = NO
|
|
||||||
EXAMPLE_PATH = src
|
|
||||||
EXAMPLE_RECURSIVE = YES
|
|
||||||
FILTER_SOURCE_FILES = NO
|
|
||||||
SOURCE_BROWSER = NO
|
|
||||||
INLINE_SOURCES = YES
|
|
||||||
STRIP_CODE_COMMENTS = YES
|
|
||||||
REFERENCED_BY_RELATION = NO
|
|
||||||
REFERENCES_RELATION = NO
|
|
||||||
REFERENCES_LINK_SOURCE = YES
|
|
||||||
SOURCE_TOOLTIPS = YES
|
|
||||||
USE_HTAGS = NO
|
|
||||||
VERBATIM_HEADERS = YES
|
VERBATIM_HEADERS = YES
|
||||||
CLANG_ASSISTED_PARSING = NO
|
INLINE_SOURCES = YES
|
||||||
ALPHABETICAL_INDEX = YES
|
SEARCHENGINE = YES
|
||||||
COLS_IN_ALPHA_INDEX = 5
|
SHOW_FILES = YES
|
||||||
GENERATE_HTML = YES
|
|
||||||
HTML_OUTPUT = doc/html
|
|
||||||
HTML_FILE_EXTENSION = .html
|
|
||||||
HTML_COLORSTYLE_HUE = 220
|
|
||||||
HTML_COLORSTYLE_SAT = 100
|
|
||||||
HTML_COLORSTYLE_GAMMA = 80
|
|
||||||
HTML_TIMESTAMP = NO
|
|
||||||
HTML_DYNAMIC_SECTIONS = NO
|
|
||||||
HTML_INDEX_NUM_ENTRIES = 100
|
|
||||||
GENERATE_DOCSET = NO
|
|
||||||
DOCSET_FEEDNAME = "Doxygen generated docs"
|
|
||||||
DOCSET_BUNDLE_ID = org.doxygen.Project
|
|
||||||
DOCSET_PUBLISHER_ID = org.doxygen.Publisher
|
|
||||||
DOCSET_PUBLISHER_NAME = Publisher
|
|
||||||
GENERATE_HTMLHELP = NO
|
|
||||||
GENERATE_CHI = NO
|
|
||||||
BINARY_TOC = NO
|
|
||||||
TOC_EXPAND = NO
|
|
||||||
GENERATE_QHP = NO
|
|
||||||
QHP_NAMESPACE = org.doxygen.Project
|
|
||||||
QHP_VIRTUAL_FOLDER = doc
|
|
||||||
GENERATE_ECLIPSEHELP = NO
|
|
||||||
ECLIPSE_DOC_ID = org.doxygen.Project
|
|
||||||
DISABLE_INDEX = NO
|
|
||||||
GENERATE_TREEVIEW = NO
|
|
||||||
ENUM_VALUES_PER_LINE = 4
|
|
||||||
TREEVIEW_WIDTH = 250
|
|
||||||
EXT_LINKS_IN_WINDOW = NO
|
|
||||||
FORMULA_FONTSIZE = 10
|
|
||||||
FORMULA_TRANSPARENT = YES
|
|
||||||
USE_MATHJAX = NO
|
|
||||||
MATHJAX_FORMAT = HTML-CSS
|
|
||||||
MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest
|
|
||||||
SEARCHENGINE = NO
|
|
||||||
SERVER_BASED_SEARCH = NO
|
|
||||||
EXTERNAL_SEARCH = NO
|
|
||||||
SEARCHDATA_FILE = searchdata.xml
|
|
||||||
GENERATE_LATEX = NO
|
|
||||||
LATEX_OUTPUT = latex
|
|
||||||
LATEX_CMD_NAME = latex
|
|
||||||
MAKEINDEX_CMD_NAME = makeindex
|
|
||||||
COMPACT_LATEX = NO
|
|
||||||
PAPER_TYPE = a4
|
|
||||||
PDF_HYPERLINKS = YES
|
|
||||||
USE_PDFLATEX = YES
|
|
||||||
LATEX_BATCHMODE = NO
|
|
||||||
LATEX_HIDE_INDICES = NO
|
|
||||||
LATEX_SOURCE_CODE = NO
|
|
||||||
LATEX_BIB_STYLE = plain
|
|
||||||
GENERATE_RTF = NO
|
|
||||||
RTF_OUTPUT = rtf
|
|
||||||
COMPACT_RTF = NO
|
|
||||||
RTF_HYPERLINKS = NO
|
|
||||||
RTF_SOURCE_CODE = NO
|
|
||||||
GENERATE_MAN = NO
|
|
||||||
MAN_OUTPUT = man
|
|
||||||
MAN_EXTENSION = .3
|
|
||||||
MAN_SUBDIR =
|
|
||||||
MAN_LINKS = NO
|
|
||||||
GENERATE_XML = NO
|
|
||||||
XML_OUTPUT = xml
|
|
||||||
XML_PROGRAMLISTING = YES
|
|
||||||
GENERATE_DOCBOOK = NO
|
|
||||||
DOCBOOK_OUTPUT = docbook
|
|
||||||
DOCBOOK_PROGRAMLISTING = NO
|
|
||||||
GENERATE_AUTOGEN_DEF = NO
|
|
||||||
GENERATE_PERLMOD = NO
|
|
||||||
PERLMOD_LATEX = NO
|
|
||||||
PERLMOD_PRETTY = YES
|
|
||||||
ENABLE_PREPROCESSING = YES
|
|
||||||
MACRO_EXPANSION = NO
|
|
||||||
EXPAND_ONLY_PREDEF = NO
|
|
||||||
SEARCH_INCLUDES = YES
|
|
||||||
SKIP_FUNCTION_MACROS = YES
|
|
||||||
ALLEXTERNALS = NO
|
|
||||||
EXTERNAL_GROUPS = YES
|
|
||||||
EXTERNAL_PAGES = YES
|
|
||||||
PERL_PATH = /usr/bin/perl
|
|
||||||
CLASS_DIAGRAMS = YES
|
|
||||||
HIDE_UNDOC_RELATIONS = YES
|
|
||||||
HAVE_DOT = NO
|
|
||||||
DOT_NUM_THREADS = 0
|
|
||||||
DOT_FONTNAME = Helvetica
|
|
||||||
DOT_FONTSIZE = 10
|
|
||||||
CLASS_GRAPH = YES
|
|
||||||
COLLABORATION_GRAPH = YES
|
|
||||||
GROUP_GRAPHS = YES
|
|
||||||
UML_LOOK = NO
|
|
||||||
UML_LIMIT_NUM_FIELDS = 10
|
|
||||||
TEMPLATE_RELATIONS = NO
|
|
||||||
INCLUDE_GRAPH = YES
|
|
||||||
INCLUDED_BY_GRAPH = YES
|
|
||||||
CALL_GRAPH = NO
|
|
||||||
CALLER_GRAPH = NO
|
|
||||||
GRAPHICAL_HIERARCHY = YES
|
|
||||||
DIRECTORY_GRAPH = YES
|
|
||||||
DOT_IMAGE_FORMAT = png
|
|
||||||
INTERACTIVE_SVG = NO
|
|
||||||
DOT_GRAPH_MAX_NODES = 50
|
|
||||||
MAX_DOT_GRAPH_DEPTH = 0
|
|
||||||
DOT_TRANSPARENT = NO
|
|
||||||
DOT_MULTI_TARGETS = NO
|
|
||||||
GENERATE_LEGEND = YES
|
|
||||||
DOT_CLEANUP = YES
|
|
||||||
|
|
26
LICENSE
Normal file
26
LICENSE
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
Copyright (c) 2019 tastytea <tastytea@tastytea.de>. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software without
|
||||||
|
specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||||
|
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
57
README.md
57
README.md
|
@ -2,23 +2,56 @@
|
||||||
and writes files in `${XDG_CONFIG_HOME}`. It creates subdirectories if
|
and writes files in `${XDG_CONFIG_HOME}`. It creates subdirectories if
|
||||||
necessary.
|
necessary.
|
||||||
|
|
||||||
## Dependencies
|
## Usage
|
||||||
|
|
||||||
* C++ compiler (Tested: g++ 5/8)
|
`xdgcfg.hpp` has explanatory comments in it and there is an
|
||||||
* [cmake](https://cmake.org/) (at least: 3.1)
|
[example](examples/example.cpp). The reference is also available at
|
||||||
* [pkgconfig](https://pkgconfig.freedesktop.org/wiki/)
|
[doc.schlomp.space/xdgcfg/](https://doc.schlomp.space/xdgcfg/classxdgcfg.html).
|
||||||
* [libconfig++](https://github.com/hyperrealm/libconfig)
|
|
||||||
* [libxdg-basedir](http://repo.or.cz/w/libxdg-basedir.git)
|
Use it in your CMake project like this:
|
||||||
|
|
||||||
|
``` cmake
|
||||||
|
find_package(xdgcfg CONFIG REQUIRED)
|
||||||
|
target_link_libraries(MyProject xdgcfg::xdgcfg)
|
||||||
|
```
|
||||||
|
|
||||||
|
If you don't use CMake, you can get the compile-flags with pkg-config:
|
||||||
|
|
||||||
|
``` shell
|
||||||
|
pkg-config --libs --cflags xdgcfg
|
||||||
|
```
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Copy `xdgcfg.hpp` into a folder where your project can find it.
|
### Gentoo
|
||||||
|
|
||||||
|
Add my [repository](https://schlomp.space/tastytea/overlay) and install it from
|
||||||
|
there.
|
||||||
|
|
||||||
|
``` shell
|
||||||
|
eselect repository enable tastytea
|
||||||
|
echo "dev-cpp/xdgcfg" >> /etc/portage/package.accept_keywords/xdgcfg
|
||||||
|
emaint sync -r tastytea
|
||||||
|
emerge -a dev-cpp/xdgcfg
|
||||||
|
```
|
||||||
|
|
||||||
|
### From source
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
* C++ compiler (Tested: g++ 5/8/9)
|
||||||
|
* [cmake](https://cmake.org/) (at least: 3.1)
|
||||||
|
* [pkgconfig](https://pkgconfig.freedesktop.org/wiki/) (tested: 0.29)
|
||||||
|
* [libconfig++](https://github.com/hyperrealm/libconfig) (tested: 1.5)
|
||||||
|
* [libxdg-basedir](http://repo.or.cz/w/libxdg-basedir.git) (tested: 1.2)
|
||||||
|
|
||||||
|
### Compile
|
||||||
|
|
||||||
``` shell
|
``` shell
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake ..
|
||||||
make
|
cmake --build .
|
||||||
make install
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -26,10 +59,4 @@ make install
|
||||||
|
|
||||||
* `-DWITH_TESTS=YES` to compile the tests.
|
* `-DWITH_TESTS=YES` to compile the tests.
|
||||||
* `-DWITH_EXAMPLES=YES` to compile the example.
|
* `-DWITH_EXAMPLES=YES` to compile the example.
|
||||||
|
* `-DBUILD_SHARED_LIBS=NO` to build a static library.
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
`xdgcfg.hpp` has explanatory comments in it and there is an
|
|
||||||
[example](src/example.cpp). The reference is also available at
|
|
||||||
[doc.schlomp.space/xdgcfg/](https://doc.schlomp.space/xdgcfg/classxdgcfg.html).
|
|
||||||
|
|
7
build_doc.sh
Executable file
7
build_doc.sh
Executable file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ -f Doxyfile ]]; then
|
||||||
|
mkdir -p doc
|
||||||
|
(doxygen -s -g - && cat Doxyfile && echo -n "PROJECT_NUMBER = " &&
|
||||||
|
grep -Eo '[0-9]+.[0-9]+.[0-9]+$' CMakeLists.txt) | doxygen -
|
||||||
|
fi
|
19
cmake/CMakeLists.txt
Normal file
19
cmake/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
VERSION ${PACKAGE_VERSION}
|
||||||
|
COMPATIBILITY ExactVersion) # NOTE: Set to SameMajorVersion when stable.
|
||||||
|
|
||||||
|
install(EXPORT ${PROJECT_NAME}Targets
|
||||||
|
FILE "${PROJECT_NAME}Targets.cmake"
|
||||||
|
NAMESPACE "${PROJECT_NAME}::"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||||
|
|
||||||
|
configure_file("${PROJECT_NAME}Config.cmake.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
|
||||||
|
|
||||||
|
install(FILES
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
6
cmake/xdgcfgConfig.cmake.in
Normal file
6
cmake/xdgcfgConfig.cmake.in
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
include(CMakeFindDependencyMacro)
|
||||||
|
|
||||||
|
find_dependency(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(libconfig++ REQUIRED IMPORTED_TARGET libconfig++)
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
9
examples/CMakeLists.txt
Normal file
9
examples/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
add_executable(example example.cpp)
|
||||||
|
target_link_libraries(example xdgcfg)
|
||||||
|
|
||||||
|
# # In your own project, you would link to xdgcfg like this:
|
||||||
|
# find_package(xdgcfg CONFIG REQUIRED)
|
||||||
|
# target_link_libraries(example xdgcfg::xdgcfg)
|
||||||
|
|
34
examples/example.cpp
Normal file
34
examples/example.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
/* This file is part of xdgcfg. */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <libconfig.h++>
|
||||||
|
#include "xdgcfg.hpp"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
xdgcfg config("test.cfg", // File name.
|
||||||
|
"xdgcfg"); // Sub directory (optional).
|
||||||
|
config.set_verbose(true); // Print error messages.
|
||||||
|
|
||||||
|
if (config.read() != 0)
|
||||||
|
{
|
||||||
|
std::cout << "File not found.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a reference to the libconfig::Config object and use it as you would
|
||||||
|
// normally do.
|
||||||
|
libconfig::Config &cfg = config.get_cfg();
|
||||||
|
libconfig::Setting &root = cfg.getRoot();
|
||||||
|
|
||||||
|
if (!root.exists("Hello"))
|
||||||
|
{
|
||||||
|
root.add("Hello", libconfig::Setting::TypeString) = "World";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.write())
|
||||||
|
{
|
||||||
|
std::cerr << "Writing failed.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Hello: " << root["Hello"].c_str() << std::endl;
|
||||||
|
}
|
|
@ -1,8 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -f Doxyfile ]; then
|
|
||||||
mkdir -p doc
|
|
||||||
(cat Doxyfile && echo -n "PROJECT_NUMBER = " &&
|
|
||||||
grep -Eo '[0-9]+.[0-9]+.[0-9]+$' CMakeLists.txt) \
|
|
||||||
| doxygen -
|
|
||||||
fi
|
|
106
include/xdgcfg.hpp
Normal file
106
include/xdgcfg.hpp
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the BSD-3-Clause license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XDGCFG_HPP
|
||||||
|
#define XDGCFG_HPP
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
#include <filesystem>
|
||||||
|
#else
|
||||||
|
#include <experimental/filesystem>
|
||||||
|
#endif
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <libconfig.h++>
|
||||||
|
|
||||||
|
#if __cplusplus >= 201703L
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
#else
|
||||||
|
namespace fs = std::experimental::filesystem;
|
||||||
|
#endif
|
||||||
|
using std::string;
|
||||||
|
using std::uint8_t;
|
||||||
|
using std::cerr;
|
||||||
|
using std::endl;
|
||||||
|
|
||||||
|
class xdgcfg
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*!
|
||||||
|
* @brief Checks if subdir is present, creates it if necessary
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* @code
|
||||||
|
* xdgcfg config("test.cfg", "subdirectory");
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param filename The name of the file, including extension
|
||||||
|
* @param subdir The subdir (optional)
|
||||||
|
*/
|
||||||
|
explicit xdgcfg(const string &filename, const string &subdir = "");
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Read the file
|
||||||
|
*
|
||||||
|
* @return 0 on success, 1 on I/O error, 2 on parse error.
|
||||||
|
*/
|
||||||
|
uint8_t read();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Write the file
|
||||||
|
*
|
||||||
|
* @return `true` on success
|
||||||
|
*/
|
||||||
|
bool write();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns a reference to the config as libconfig::Config
|
||||||
|
*
|
||||||
|
* Example:
|
||||||
|
* @code
|
||||||
|
* libconfig::Config &cfg = config.get_cfg();
|
||||||
|
* @endcode
|
||||||
|
*/
|
||||||
|
libconfig::Config &get_cfg();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns the complete filepath
|
||||||
|
*/
|
||||||
|
const fs::path get_filepath() const;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets verbosity
|
||||||
|
*/
|
||||||
|
void set_verbose(bool verbose);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns verbosity
|
||||||
|
*/
|
||||||
|
bool get_verbose() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*!
|
||||||
|
* Holds the contents of the CFG file
|
||||||
|
*/
|
||||||
|
libconfig::Config _cfg;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Complete filepath
|
||||||
|
*/
|
||||||
|
fs::path _filepath;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Print out error messages if true
|
||||||
|
*/
|
||||||
|
bool _verbose;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @example example.cpp
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif // XDGCFG_HPP
|
7
pkg-config/CMakeLists.txt
Normal file
7
pkg-config/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
configure_file("${PROJECT_NAME}.pc.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" @ONLY)
|
||||||
|
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
||||||
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
13
pkg-config/xdgcfg.pc.in
Normal file
13
pkg-config/xdgcfg.pc.in
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
name=@PROJECT_NAME@
|
||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||||
|
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
|
||||||
|
|
||||||
|
Name: ${name}
|
||||||
|
Description: @PROJECT_DESCRIPTION@
|
||||||
|
Version: @PROJECT_VERSION@
|
||||||
|
Libs: -L${libdir} -l${name}
|
||||||
|
Cflags: -I${includedir}
|
||||||
|
Requires: libconfig++
|
||||||
|
Requires.private: libxdg-basedir
|
28
src/CMakeLists.txt
Normal file
28
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir)
|
||||||
|
pkg_check_modules(libconfig++ REQUIRED IMPORTED_TARGET libconfig++)
|
||||||
|
|
||||||
|
set(${PROJECT_NAME}_public_headers "../include/xdgcfg.hpp")
|
||||||
|
add_library(${PROJECT_NAME} "xdgcfg.cpp" "${${PROJECT_NAME}_public_headers}")
|
||||||
|
|
||||||
|
set_target_properties(xdgcfg PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}
|
||||||
|
PUBLIC_HEADER "${${PROJECT_NAME}_public_headers}")
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PUBLIC
|
||||||
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>"
|
||||||
|
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
PRIVATE PkgConfig::libxdg-basedir
|
||||||
|
PUBLIC PkgConfig::libconfig++ stdc++fs)
|
||||||
|
|
||||||
|
install(TARGETS ${PROJECT_NAME}
|
||||||
|
EXPORT "${PROJECT_NAME}Targets"
|
||||||
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
@ -1,22 +0,0 @@
|
||||||
#include <iostream>
|
|
||||||
#include <libconfig.h++>
|
|
||||||
#include "xdgcfg.hpp"
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
xdgcfg config("test.cfg", "xdgcfg");
|
|
||||||
config.set_verbose(true);
|
|
||||||
if (config.read() != 0)
|
|
||||||
{
|
|
||||||
config.write();
|
|
||||||
}
|
|
||||||
libconfig::Config &cfg = config.get_cfg();
|
|
||||||
libconfig::Setting &root = cfg.getRoot();
|
|
||||||
if (!root.exists("Hello"))
|
|
||||||
{
|
|
||||||
root.add("Hello", libconfig::Setting::TypeString) = "World";
|
|
||||||
}
|
|
||||||
config.write();
|
|
||||||
|
|
||||||
std::cout << "Hello: " << root["Hello"].c_str() << std::endl;
|
|
||||||
}
|
|
95
src/xdgcfg.cpp
Normal file
95
src/xdgcfg.cpp
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/* Copyright © 2019 tastytea <tastytea@tastytea.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the BSD-3-Clause license.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <basedir.h>
|
||||||
|
#include "xdgcfg.hpp"
|
||||||
|
|
||||||
|
xdgcfg::xdgcfg(const string &filename, const string &subdir)
|
||||||
|
: _cfg()
|
||||||
|
, _verbose(false)
|
||||||
|
{
|
||||||
|
xdgHandle xdg;
|
||||||
|
xdgInitHandle(&xdg);
|
||||||
|
_filepath = xdgConfigHome(&xdg);
|
||||||
|
xdgWipeHandle(&xdg);
|
||||||
|
|
||||||
|
if (!subdir.empty())
|
||||||
|
{
|
||||||
|
_filepath /= subdir;
|
||||||
|
}
|
||||||
|
if (!fs::exists(_filepath))
|
||||||
|
{
|
||||||
|
fs::create_directories(_filepath);
|
||||||
|
}
|
||||||
|
_filepath /= filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t xdgcfg::read()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_cfg.readFile(_filepath.c_str());
|
||||||
|
}
|
||||||
|
catch (const libconfig::FileIOException &e)
|
||||||
|
{
|
||||||
|
if (_verbose)
|
||||||
|
{
|
||||||
|
cerr << "I/O error while reading " << _filepath
|
||||||
|
<< " - " << e.what() << endl;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (const libconfig::ParseException &e)
|
||||||
|
{
|
||||||
|
if (_verbose)
|
||||||
|
{
|
||||||
|
cerr << "Parse error at " << e.getFile() << ":" << e.getLine()
|
||||||
|
<< " - " << e.getError() << endl;
|
||||||
|
}
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool xdgcfg::write()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_cfg.writeFile(_filepath.c_str());
|
||||||
|
}
|
||||||
|
catch (const libconfig::FileIOException &e)
|
||||||
|
{
|
||||||
|
if (_verbose)
|
||||||
|
{
|
||||||
|
cerr << "I/O error while writing " << _filepath
|
||||||
|
<< " - " << e.what() << endl;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
libconfig::Config &xdgcfg::get_cfg()
|
||||||
|
{
|
||||||
|
return _cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fs::path xdgcfg::get_filepath() const
|
||||||
|
{
|
||||||
|
return _filepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
void xdgcfg::set_verbose(bool verbose)
|
||||||
|
{
|
||||||
|
_verbose = verbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool xdgcfg::get_verbose() const
|
||||||
|
{
|
||||||
|
return _verbose;
|
||||||
|
}
|
178
src/xdgcfg.hpp
178
src/xdgcfg.hpp
|
@ -1,178 +0,0 @@
|
||||||
/* Public Domain / CC-0
|
|
||||||
* Author: tastytea <tastytea@tastytea.de>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef XDGCFG_HPP
|
|
||||||
#define XDGCFG_HPP
|
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
|
||||||
#include <filesystem>
|
|
||||||
#else
|
|
||||||
#include <experimental/filesystem>
|
|
||||||
#endif
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <libconfig.h++>
|
|
||||||
#include <basedir.h>
|
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
|
||||||
namespace fs = std::filesystem;
|
|
||||||
#else
|
|
||||||
namespace fs = std::experimental::filesystem;
|
|
||||||
#endif
|
|
||||||
using std::string;
|
|
||||||
using std::uint_fast8_t;
|
|
||||||
using std::cerr;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
class xdgcfg
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/*!
|
|
||||||
* @brief Checks if subdir is present, creates it if necessary
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* @code
|
|
||||||
* xdgcfg config("test.cfg", "subdirectory");
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* @param filename The name of the file, including extension
|
|
||||||
* @param subdir The subdir (optional)
|
|
||||||
*/
|
|
||||||
explicit xdgcfg(const string &filename, const string &subdir = "")
|
|
||||||
: _cfg()
|
|
||||||
, _verbose(false)
|
|
||||||
{
|
|
||||||
xdgHandle xdg;
|
|
||||||
xdgInitHandle(&xdg);
|
|
||||||
_filepath = xdgConfigHome(&xdg);
|
|
||||||
xdgWipeHandle(&xdg);
|
|
||||||
|
|
||||||
if (!subdir.empty())
|
|
||||||
{
|
|
||||||
_filepath /= subdir;
|
|
||||||
}
|
|
||||||
if (!fs::exists(_filepath))
|
|
||||||
{
|
|
||||||
fs::create_directories(_filepath);
|
|
||||||
}
|
|
||||||
_filepath /= filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Read the file
|
|
||||||
*
|
|
||||||
* @return 0 on success, 1 on I/O error, 2 on parse error.
|
|
||||||
*/
|
|
||||||
uint_fast8_t read()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_cfg.readFile(_filepath.c_str());
|
|
||||||
}
|
|
||||||
catch (const libconfig::FileIOException &e)
|
|
||||||
{
|
|
||||||
if (_verbose)
|
|
||||||
{
|
|
||||||
cerr << "I/O error while reading " << _filepath
|
|
||||||
<< " - " << e.what() << endl;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
catch (const libconfig::ParseException &e)
|
|
||||||
{
|
|
||||||
if (_verbose)
|
|
||||||
{
|
|
||||||
cerr << "Parse error at " << e.getFile() << ":" << e.getLine()
|
|
||||||
<< " - " << e.getError() << endl;
|
|
||||||
}
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Write the file
|
|
||||||
*
|
|
||||||
* @return `true` on success
|
|
||||||
*/
|
|
||||||
bool write()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_cfg.writeFile(_filepath.c_str());
|
|
||||||
}
|
|
||||||
catch (const libconfig::FileIOException &e)
|
|
||||||
{
|
|
||||||
if (_verbose)
|
|
||||||
{
|
|
||||||
cerr << "I/O error while writing " << _filepath
|
|
||||||
<< " - " << e.what() << endl;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Returns a reference to the config as libconfig::Config
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
* @code
|
|
||||||
* libconfig::Config &cfg = config.get_cfg();
|
|
||||||
* @endcode
|
|
||||||
*/
|
|
||||||
libconfig::Config &get_cfg()
|
|
||||||
{
|
|
||||||
return _cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Returns the complete filepath
|
|
||||||
*/
|
|
||||||
const fs::path get_filepath() const
|
|
||||||
{
|
|
||||||
return _filepath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Sets verbosity
|
|
||||||
*/
|
|
||||||
void set_verbose(bool verbose)
|
|
||||||
{
|
|
||||||
_verbose = verbose;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @brief Returns verbosity
|
|
||||||
*/
|
|
||||||
bool get_verbose() const
|
|
||||||
{
|
|
||||||
return _verbose;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
/*!
|
|
||||||
* Holds the contents of the CFG file
|
|
||||||
*/
|
|
||||||
libconfig::Config _cfg;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Complete filepath
|
|
||||||
*/
|
|
||||||
fs::path _filepath;
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* Print out error messages if true
|
|
||||||
*/
|
|
||||||
bool _verbose;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* @example example.cpp
|
|
||||||
*/
|
|
||||||
|
|
||||||
#endif // XDGCFG_HPP
|
|
|
@ -1,20 +1,22 @@
|
||||||
include(CTest)
|
include(CTest)
|
||||||
file(GLOB sources_tests test_*.cpp)
|
file(GLOB sources_tests test_*.cpp)
|
||||||
|
|
||||||
find_package(Catch2)
|
find_package(Catch2 CONFIG)
|
||||||
if(Catch2_FOUND) # Catch 2.x
|
if(Catch2_FOUND) # Catch 2.x
|
||||||
include(Catch)
|
include(Catch)
|
||||||
add_executable(all_tests main.cpp ${sources_tests})
|
add_executable(all_tests main.cpp ${sources_tests})
|
||||||
target_link_libraries(all_tests Catch2::Catch2 ${COMMON_LIBRARIES})
|
target_link_libraries(all_tests Catch2::Catch2 xdgcfg)
|
||||||
target_include_directories(all_tests PRIVATE "/usr/include/catch2")
|
target_include_directories(all_tests
|
||||||
|
PRIVATE "../include" "/usr/include/catch2")
|
||||||
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
|
catch_discover_tests(all_tests EXTRA_ARGS "${EXTRA_TEST_ARGS}")
|
||||||
else() # Catch 1.x
|
else() # Catch 1.x
|
||||||
if(EXISTS "/usr/include/catch.hpp")
|
if(EXISTS "/usr/include/catch.hpp")
|
||||||
message(STATUS "Catch 1.x found.")
|
message(STATUS "Catch 1.x found.")
|
||||||
foreach(src ${sources_tests})
|
foreach(src ${sources_tests})
|
||||||
get_filename_component(bin ${src} NAME_WE)
|
get_filename_component(bin ${src} NAME_WE)
|
||||||
add_executable(${bin} main.cpp ${src})
|
add_executable(${bin} main.cpp ${src})
|
||||||
target_link_libraries(${bin} ${COMMON_LIBRARIES})
|
target_include_directories(${bin} PRIVATE "../include")
|
||||||
|
target_link_libraries(${bin} xdgcfg)
|
||||||
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
|
add_test(${bin} ${bin} "${EXTRA_TEST_ARGS}")
|
||||||
endforeach()
|
endforeach()
|
||||||
else()
|
else()
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
#include "../src/xdgcfg.hpp"
|
#include "xdgcfg.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user