diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce795c..0871a77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,20 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(dindexer VERSION 0.1.1 LANGUAGES CXX C) list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) +option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF) set(PROJECT_VERSION_BETA "1") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11") +if (DINDEXER_CONFIG_FILE STREQUAL "") + if (DINDEXER_DEBUG_CFG_FILE) + set(DINDEXER_CONFIG_FILE ${CMAKE_CURRENT_BINARY_DIR}/dindexer.yml CACHE STRING "Path to the config file" FORCE) + else() + set(DINDEXER_CONFIG_FILE "$HOME/.config/dindexer.yml" CACHE STRING "Path to the config file" FORCE) + endif() +endif() +message(STATUS "Config file set to ${DINDEXER_CONFIG_FILE}") + find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options) find_package(PostgreSQL REQUIRED) find_package(YamlCpp 0.5.1 REQUIRED) diff --git a/README.md b/README.md index 3f3b69f..0787354 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,13 @@ The program will go through every file in the path you specify. Hashing everythi You can run dindexer --help to see a list of available switches. # Build instructions # +## Dependencies ## +The following libraries must be available on your system: + +- PostgreSQL (libpq) +- Boost 1.53 or later +- yaml-cpp 0.5.1 or later + ## Linux ## mkdir dindexer_build diff --git a/dindexerrc.yml b/dindexer.yml similarity index 100% rename from dindexerrc.yml rename to dindexer.yml diff --git a/src/dindexerConfig.h.in b/src/dindexerConfig.h.in index 2270bce..72da2f6 100644 --- a/src/dindexerConfig.h.in +++ b/src/dindexerConfig.h.in @@ -23,5 +23,6 @@ #define VERSION_MINOR @PROJECT_VERSION_MINOR@ #define VERSION_BETA @PROJECT_VERSION_BETA@ #define VERSION_PATCH @PROJECT_VERSION_PATCH@ +#define CONFIG_FILE_PATH "@DINDEXER_CONFIG_FILE@" #endif diff --git a/src/main.cpp b/src/main.cpp index 9e6d625..5d7174f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,8 @@ # include # include #endif +#include +#include "dindexerConfig.h" #include "filesearcher.hpp" #include "indexer.hpp" #include "settings.hpp" @@ -33,6 +35,7 @@ namespace { void run_hash_calculation ( din::Indexer& parIndexer, bool parShowProgress ); + std::string expand ( const char* parString ); } //unnamed namespace int main (int parArgc, char* parArgv[]) { @@ -61,7 +64,7 @@ int main (int parArgc, char* parArgv[]) { din::DinDBSettings settings; { - const bool loaded = din::load_settings("dindexerrc.yml", settings); + const bool loaded = din::load_settings(expand(CONFIG_FILE_PATH), settings); if (not loaded) { std::cerr << "Can't load settings from dindexerrc.yml, quitting\n"; return 1; @@ -141,4 +144,16 @@ namespace { } #endif } + + std::string expand (const char* parString) { + wordexp_t p; + wordexp(parString, &p, 0); + char** w = p.we_wordv; + std::ostringstream oss; + for (std::size_t z = 0; z < p.we_wordc; ++z) { + oss << w[z]; + } + wordfree(&p); + return oss.str(); + } } //unnamed namespace