Rearranged the file structure and rewrote the CMake recipes.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
* Compile a library again. * Made CMake recipes modular. * Added xdgcfgConfig.cmake. * Added pkg-config file. * Updated readme.
This commit is contained in:
parent
91bbae667c
commit
2fb329a302
|
@ -1,42 +1,54 @@
|
||||||
cmake_minimum_required (VERSION 3.1)
|
# Support version 3.1 and above, but use policy settings up to 3.14.
|
||||||
|
cmake_minimum_required(VERSION 3.1...3.14)
|
||||||
|
# Ranges are supported from 3.12, set policy to current for 3.1 - 3.11.
|
||||||
|
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.4.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)
|
# Build shared libs by default but allow overriding.
|
||||||
find_package(PkgConfig REQUIRED)
|
set(BUILD_SHARED_LIBS YES CACHE BOOL "Build shared libs.")
|
||||||
pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir)
|
|
||||||
pkg_check_modules(LIBCONFIG REQUIRED libconfig++)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set_property(GLOBAL PROPERTY CXX_STANDARD 14)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set_property(GLOBAL PROPERTY CXX_STANDARD_REQUIRED YES)
|
||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set_property(GLOBAL PROPERTY 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("$<$<CONFIG:Debug>:${DEBUG_LDFLAGS}>")
|
||||||
|
|
||||||
include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS})
|
add_subdirectory(src)
|
||||||
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
add_subdirectory(include)
|
||||||
|
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})
|
|
||||||
|
|
43
README.md
43
README.md
|
@ -2,13 +2,24 @@
|
||||||
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](src/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
|
||||||
|
|
||||||
|
@ -26,13 +37,21 @@ emerge -a dev-cpp/xdgcfg
|
||||||
|
|
||||||
### From source
|
### From source
|
||||||
|
|
||||||
Copy `xdgcfg.hpp` into a folder where your project can find it.
|
### 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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -40,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).
|
|
||||||
|
|
|
@ -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}")
|
|
@ -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")
|
|
@ -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)
|
||||||
|
|
|
@ -4,19 +4,29 @@
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
xdgcfg config("test.cfg", "xdgcfg");
|
xdgcfg config("test.cfg", // File name.
|
||||||
config.set_verbose(true);
|
"xdgcfg"); // Sub directory (optional).
|
||||||
|
config.set_verbose(true); // Print error messages.
|
||||||
|
|
||||||
if (config.read() != 0)
|
if (config.read() != 0)
|
||||||
{
|
{
|
||||||
config.write();
|
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::Config &cfg = config.get_cfg();
|
||||||
libconfig::Setting &root = cfg.getRoot();
|
libconfig::Setting &root = cfg.getRoot();
|
||||||
|
|
||||||
if (!root.exists("Hello"))
|
if (!root.exists("Hello"))
|
||||||
{
|
{
|
||||||
root.add("Hello", libconfig::Setting::TypeString) = "World";
|
root.add("Hello", libconfig::Setting::TypeString) = "World";
|
||||||
}
|
}
|
||||||
config.write();
|
|
||||||
|
if (!config.write())
|
||||||
|
{
|
||||||
|
std::cerr << "Writing failed.\n";
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Hello: " << root["Hello"].c_str() << std::endl;
|
std::cout << "Hello: " << root["Hello"].c_str() << std::endl;
|
||||||
}
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
install(FILES "xdgcfg.hpp" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
|
@ -14,7 +14,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <libconfig.h++>
|
#include <libconfig.h++>
|
||||||
#include <basedir.h>
|
|
||||||
|
|
||||||
#if __cplusplus >= 201703L
|
#if __cplusplus >= 201703L
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
@ -40,82 +39,21 @@ public:
|
||||||
* @param filename The name of the file, including extension
|
* @param filename The name of the file, including extension
|
||||||
* @param subdir The subdir (optional)
|
* @param subdir The subdir (optional)
|
||||||
*/
|
*/
|
||||||
explicit xdgcfg(const string &filename, const string &subdir = "")
|
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
|
* @brief Read the file
|
||||||
*
|
*
|
||||||
* @return 0 on success, 1 on I/O error, 2 on parse error.
|
* @return 0 on success, 1 on I/O error, 2 on parse error.
|
||||||
*/
|
*/
|
||||||
uint_fast8_t read()
|
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
|
* @brief Write the file
|
||||||
*
|
*
|
||||||
* @return `true` on success
|
* @return `true` on success
|
||||||
*/
|
*/
|
||||||
bool write()
|
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
|
* @brief Returns a reference to the config as libconfig::Config
|
||||||
|
@ -125,34 +63,22 @@ public:
|
||||||
* libconfig::Config &cfg = config.get_cfg();
|
* libconfig::Config &cfg = config.get_cfg();
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
libconfig::Config &get_cfg()
|
libconfig::Config &get_cfg();
|
||||||
{
|
|
||||||
return _cfg;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns the complete filepath
|
* @brief Returns the complete filepath
|
||||||
*/
|
*/
|
||||||
const fs::path get_filepath() const
|
const fs::path get_filepath() const;
|
||||||
{
|
|
||||||
return _filepath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Sets verbosity
|
* @brief Sets verbosity
|
||||||
*/
|
*/
|
||||||
void set_verbose(bool verbose)
|
void set_verbose(bool verbose);
|
||||||
{
|
|
||||||
_verbose = verbose;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Returns verbosity
|
* @brief Returns verbosity
|
||||||
*/
|
*/
|
||||||
bool get_verbose() const
|
bool get_verbose() const;
|
||||||
{
|
|
||||||
return _verbose;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/*!
|
/*!
|
|
@ -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")
|
|
@ -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
|
|
@ -0,0 +1,25 @@
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(libxdg-basedir REQUIRED IMPORTED_TARGET libxdg-basedir)
|
||||||
|
pkg_check_modules(libconfig++ REQUIRED IMPORTED_TARGET libconfig++)
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} "xdgcfg.cpp" "../include/xdgcfg.hpp")
|
||||||
|
|
||||||
|
set_target_properties(xdgcfg PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR})
|
||||||
|
|
||||||
|
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}")
|
|
@ -0,0 +1,93 @@
|
||||||
|
/* Public Domain / CC-0
|
||||||
|
* Author: tastytea <tastytea@tastytea.de>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint_fast8_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;
|
||||||
|
}
|
|
@ -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