1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-16 11:35:49 +00:00

Add a DINDEXER_INST_MODE cmake switch.

Attempt to clean up the path mess in cmake and improve scalability.
Previously, paths such as action search path and config file path had to
be given manually and were likely to be wrong if running make install or
if running the program from the build directory directly.

This commit introduces set_switchable(), along with the
DINDEXER_INST_MODE. Whenever relevant, paths come with a regular and an
INST variant (eg: DINDEXER_QML_PATH and DINDEXER_INST_QML_PATH), which
are CACHE variables so users can customize them and expect their setting
to be persistent.
set_switchable() then sets a CURR variant of the same variable (eg:
DINDEXER_CURR_QML_PATH), which is set to either of the above two values
depending on if DINDEXER_INST_MODE is on or off. This way the rest of
the cmake code can just use the CURR variable and expect it to be set to
the right value.
This commit is contained in:
King_DuckZ 2016-10-12 23:08:29 +02:00
parent eea8d3323c
commit a48742c0b0
10 changed files with 199 additions and 26 deletions

View file

@ -33,6 +33,7 @@ include(timestamp)
include(shared_git_project)
include(TargetArch)
include(CMakeDependentOption)
include(set_switchable)
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options filesystem system)
find_package(PostgreSQL 8.3 REQUIRED)
@ -49,10 +50,10 @@ if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION_MAJOR EQUAL "5")
endif()
cmake_dependent_option(DINDEXER_NATIVE_RELEASE "Pass the -march=native flag to the compiler for release builds" OFF "NOT is_arm" OFF)
option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF)
option(DINDEXER_WITH_MEDIA_AUTODETECT "Enable code that tries to autodetect the media type and sets --type automatically" ON)
cmake_dependent_option(DINDEXER_WITH_DESKTOP_QT5_GUI "Enable the Qt5 GUI for desktop" ON "Qt5Qml_FOUND" OFF)
cmake_dependent_option(DINDEXER_CXX11_ABI "Controls if _GLIBCXX_USE_CXX11_ABI gets set to 0 or not" ON "compiler_is_gnuxx_5plus" OFF)
option(DINDEXER_INST_MODE "Set some paths to the value that is expected for the layout of the installed version of ${bare_name} (make install)" OFF)
if(DINDEXER_NATIVE_RELEASE)
set(march_flag "-march=native")
@ -61,8 +62,21 @@ else()
endif()
set(DINDEXER_COPYRIGHT_YEARS "2015,2016")
set(DINDEXER_ACTIONS_PATH "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE STRING "Actions search path")
set_switchable(PREFIX DINDEXER INFIX INST NAME CONFIG_FILE
ONVALUE "$HOME/.config/${bare_name}.yml" CACHE STRING "Path to the config file"
OFFVALUE "${PROJECT_BINARY_DIR}/${bare_name}.yml" CACHE STRING "Path to the config file for debug runs (non-install mode)"
)
set_switchable(PREFIX DINDEXER INFIX INST NAME ACTIONS_PATH
ONVALUE "share/${bare_name}/actions" CACHE STRING "Actions search path"
OFFVALUE "${CMAKE_CURRENT_BINARY_DIR}/src" CACHE STRING "Actions search path for debug runs (non-install mode)"
)
string(REGEX MATCH "[^/].*" ACTIONS_INST_PATH_INSTALL "${DINDEXER_INST_ACTIONS_PATH}")
string(REGEX MATCH "[^/].*" ACTIONS_PATH_INSTALL "${DINDEXER_ACTIONS_PATH}")
if (DINDEXER_INST_MODE)
message(STATUS "Install mode enabled")
else()
message(STATUS "Install mode disabled")
endif()
set(DINDEXER_DB_OWNER_NAME "$ENV{USER}" CACHE STRING "Name that will be used as the DB owner name")
set(PROJECT_VERSION_BETA "1")
@ -75,20 +89,12 @@ set(DINDEXER_PUB_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(PBL_WITH_TESTS OFF)
get_git_head_revision(GIT_REFSPEC PROJECT_VERSION_GIT)
if ("${DINDEXER_CONFIG_FILE}" STREQUAL "")
if (DINDEXER_DEBUG_CFG_FILE)
set(DINDEXER_CONFIG_FILE ${CMAKE_CURRENT_BINARY_DIR}/${bare_name}.yml CACHE STRING "Path to the config file" FORCE)
else()
set(DINDEXER_CONFIG_FILE "$HOME/.config/${bare_name}.yml" CACHE STRING "Path to the config file" FORCE)
endif()
endif()
message(STATUS "Config file set to \"${DINDEXER_CONFIG_FILE}\"")
message(STATUS "Config file set to \"${DINDEXER_CURR_CONFIG_FILE}\"")
message(STATUS "Actions search path set to: \"${DINDEXER_CURR_ACTIONS_PATH}\"")
add_library(${PROJECT_NAME} INTERFACE)
add_library(${bare_name}-inc INTERFACE)
message(STATUS "Actions search path set to: \"${DINDEXER_ACTIONS_PATH}\"")
configure_file(
"${PROJECT_SOURCE_DIR}/src/${bare_name}Config.h.in"
"${PROJECT_BINARY_DIR}/${bare_name}Config.h"

View file

@ -117,7 +117,7 @@ These are the options understood by cmake. At runtime you might be able to see w
* **DINDEXER_ACTIONS_PATH** Search path for dindexer actions
* **DINDEXER_CONFIG_FILE** Full path to the yaml configuration file
* **DINDEXER_CXX11_ABI** Set this to off to force newer gcc (5+) to keep using the old ABI - useful on Gentoo if you built your system libraries with gcc 4 and you are trying to build dindexer with gcc 5
* **DINDEXER_DEBUG_CFG_FILE** If set to on, DINDEXER_CONFIG_FILE will be set to a path that is more appropriate for development environments
* **DINDEXER_INST_MODE** If set to on, paths will be set to the value that is assumed to be valid for a system-wide installed version of dindexer
* **DINDEXER_NATIVE_RELEASE** Set to on to pass `--march=native` to the compiler
* **DINDEXER_WITH_BUILD_DATE** If set to on, the current date will be hardcoded into the final binary - warning: if set to on, some files will need to be rebuilt every day just because the date has changed
* **DINDEXER_WITH_MEDIA_AUTODETECT** Enable code that detects the inserted media type, eg: CD-Rom or DVD - requires libblkid

View file

@ -0,0 +1,52 @@
function(set_switchable)
set(options "")
set(one_value_args PREFIX INFIX OUT_INFIX NAME)
set(multi_value_args ONVALUE OFFVALUE)
cmake_parse_arguments(SS "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
if (NOT SS_PREFIX)
message(FATAL_ERROR "No PREFIX given")
endif()
if (NOT SS_INFIX)
set(SS_INFIX "ENABLED")
endif()
if (NOT SS_OUT_INFIX)
set(SS_OUT_INFIX "CURR")
endif()
if (NOT SS_NAME)
message(FATAL_ERROR "No NAME given")
endif()
list(FIND SS_ONVALUE CACHE on_is_cachevar)
list(FIND SS_ONVALUE PARENT_SCOPE on_is_parentscope)
list(FIND SS_OFFVALUE CACHE off_is_cachevar)
list(FIND SS_OFFVALUE PARENT_SCOPE off_is_parentscope)
set(on_parentscope)
if (${on_is_cachevar} LESS 0 AND ${on_is_parentscope} LESS 1)
list(APPEND on_parentscope "PARENT_SCOPE")
endif()
set(off_parentscope)
if (${off_is_cachevar} LESS 0 AND ${off_is_parentscope} LESS 1)
list(APPEND off_parentscope "PARENT_SCOPE")
endif()
#Set some alisases to make the following code less yelling-at-me
set(prefix "${SS_PREFIX}")
set(infix "${SS_INFIX}")
set(out_infix "${SS_OUT_INFIX}")
set(suffix "${SS_NAME}")
set(${prefix}_${infix}_${suffix} ${SS_ONVALUE} ${on_parentscope})
set(${prefix}_${suffix} ${SS_OFFVALUE} ${off_parentscope})
#message(STATUS "${prefix}_${suffix} set to \"${${prefix}_${suffix}}\"")
#message(STATUS "${prefix}_${infix}_${suffix} set to \"${${prefix}_${infix}_${suffix}}\"")
if (${prefix}_${infix}_MODE)
set(${prefix}_${out_infix}_${suffix} "${${prefix}_${infix}_${suffix}}" PARENT_SCOPE)
else()
set(${prefix}_${out_infix}_${suffix} "${${prefix}_${suffix}}" PARENT_SCOPE)
endif()
endfunction()

View file

@ -1,6 +1,9 @@
project(${bare_name}-backend-redis CXX)
set(DINDEXER_REDIS_SCRIPTS_PATH "usr/share/${bare_name}/redis" CACHE STRING "Path where Lua scripts for Redis are stored")
set_switchable(PREFIX DINDEXER INFIX INST NAME REDIS_SCRIPTS_PATH
ONVALUE "share/${bare_name}/redis" CACHE STRING "Path where Lua scripts for Redis are stored"
OFFVALUE "resources/redis" CACHE STRING "Path where Lua scripts for Redis are stored"
)
find_package(Boost 1.53.0 REQUIRED COMPONENTS regex)
@ -41,15 +44,17 @@ install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib/static
)
set(lua_script_list "")
foreach (lua_script ${LUA_SCRIPTS})
get_filename_component(lua_script_basename "${lua_script}" NAME)
configure_file("${lua_script}" "${CMAKE_CURRENT_BINARY_DIR}/lua/${lua_script_basename}" COPYONLY)
list(APPEND lua_script_list "${CMAKE_CURRENT_BINARY_DIR}/lua/${lua_script_basename}")
get_directory_property(lua_script_list ADDITIONAL_MAKE_CLEAN_FILES)
foreach (current_lua ${LUA_SCRIPTS})
get_filename_component(lua_script_basename "${current_lua}" NAME)
configure_file("${current_lua}" "${CMAKE_BINARY_DIR}/${DINDEXER_CURR_REDIS_SCRIPTS_PATH}/${lua_script_basename}" COPYONLY)
list(APPEND lua_script_list "${CMAKE_BINARY_DIR}/${DINDEXER_CURR_REDIS_SCRIPTS_PATH}/${lua_script_basename}")
endforeach()
unset(lua_script)
unset(lua_script_basename)
install(FILES ${lua_script_list} DESTINATION "${DINDEXER_REDIS_SCRIPTS_PATH}")
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${lua_script_list}")
unset(lua_script_list)
unset(current_lua)
unset(lua_script_basename)
install(FILES ${LUA_SCRIPTS} DESTINATION "${DINDEXER_CURR_REDIS_SCRIPTS_PATH}")
ln_backend(${PROJECT_NAME})

View file

@ -18,6 +18,12 @@
#ifndef idB3E2F339E3B64378B66342550C4D2089
#define idB3E2F339E3B64378B66342550C4D2089
#define REDIS_SCRIPTS_PATH "@DINDEXER_REDIS_SCRIPTS_PATH@"
#cmakedefine DINDEXER_INST_MODE
#if defined(DINDEXER_INST_MODE)
# define REDIS_SCRIPTS_PATH "@CMAKE_INSTALL_PREFIX@/@DINDEXER_CURR_REDIS_SCRIPTS_PATH@"
#else
# define REDIS_SCRIPTS_PATH "@DINDEXER_CURR_REDIS_SCRIPTS_PATH@"
#endif
#endif

View file

@ -20,13 +20,19 @@
#include "duckhandy/cmake_on_off.h"
#cmakedefine DINDEXER_INST_MODE
#define PROGRAM_NAME "@bare_name@"
#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#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@"
#define ACTIONS_SEARCH_PATH "@DINDEXER_ACTIONS_PATH@"
#define CONFIG_FILE_PATH "@DINDEXER_CURR_CONFIG_FILE@"
#if defined(DINDEXER_INST_MODE)
# define ACTIONS_SEARCH_PATH "@CMAKE_INSTALL_PREFIX@/@DINDEXER_CURR_ACTIONS_PATH@"
#else
# define ACTIONS_SEARCH_PATH "@DINDEXER_CURR_ACTIONS_PATH@"
#endif
#define ACTION_PREFIX "@bare_name@-"
#define DB_OWNER_NAME "@DINDEXER_DB_OWNER_NAME@"

View file

@ -1,5 +1,10 @@
project(${bare_name}-gui CXX)
set_switchable(PREFIX DINDEXER INFIX INST NAME QML_PATH
ONVALUE "share/${bare_name}/qml" CACHE STRING "Path to the directory containing the qml files needed by ${bare_name} gui"
OFFVALUE "resources/qml" CACHE STRING "Path to the directory containing the qml files needed by ${bare_name} gui"
)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Qml 5.1 REQUIRED)
find_package(Qt5Widgets 5.1 REQUIRED)
@ -9,9 +14,14 @@ add_executable(${PROJECT_NAME}
searcher.cpp
)
set(qml_files
qml/mainwin.qml
)
target_include_directories(${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..
PRIVATE ${CMAKE_SOURCE_DIR}/lib/glob2regex/include
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(${PROJECT_NAME}
@ -28,8 +38,25 @@ target_compile_definitions(${PROJECT_NAME}
PRIVATE ACTION_NAME="${ACTION_NAME}"
)
get_directory_property(clean_qml_list ADDITIONAL_MAKE_CLEAN_FILES)
foreach(current_qml ${qml_files})
get_filename_component(qml_basename "${current_qml}" NAME)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/${current_qml}" "${CMAKE_BINARY_DIR}/${DINDEXER_CURR_QML_PATH}/${qml_basename}" COPYONLY)
list(APPEND clean_qml_list "${CMAKE_BINARY_DIR}/${DINDEXER_CURR_QML_PATH}/${qml_basename}")
endforeach()
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${clean_qml_list}")
unset(clean_qml_list)
unset(current_qml)
unset(qml_basename)
configure_file(
"${PROJECT_NAME}Config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.h"
)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
RUNTIME DESTINATION ${ACTIONS_PATH_INSTALL}
ARCHIVE DESTINATION lib/static
)
install(FILES ${qml_files} DESTINATION "${DINDEXER_CURR_QML_PATH}")

View file

@ -0,0 +1,29 @@
/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id9CF52D31E3D04CC99591E8BE3F83A4EF
#define id9CF52D31E3D04CC99591E8BE3F83A4EF
#cmakedefine DINDEXER_INST_MODE
#if defined(DINDEXER_INST_MODE)
# define QML_PATH "@CMAKE_INSTALL_PREFIX@/@DINDEXER_CURR_QML_PATH@"
#else
# define QML_PATH "@DINDEXER_CURR_QML_PATH@"
#endif
#endif

View file

@ -17,6 +17,7 @@
#include "searcher.hpp"
#include "dindexerConfig.h"
#include "dindexer-guiConfig.h"
#include "dindexer-common/settings.hpp"
#include <QApplication>
#include <QtCore/QUrl>
@ -24,10 +25,46 @@
#include <cassert>
#include <iostream>
//namespace {
// std::string replace_dindexer_path (const char* parPath, const std::map<std::string, std::string>& parDict) a_pure;
//
// std::string replace_dindexer_path (const char* parPath, const std::map<std::string, std::string>& parDict) {
// assert(parPath);
// std::string retval(parPath);
//
// std::size_t from = 0;
// while ((from = retval.find('%', from)) != std::string::npos) {
// if (retval.size() - 1 == from)
// break;
// if ('%' == retval[from + 1]) {
// from += 2;
// continue;
// }
//
// const auto to = retval.find('%', from + 1);
// if (std::string::npos == to)
// break;
//
// assert(to - from + 1 > 2);
// const auto& val = parDict.at(retval.substr(from + 1, to - from - 1));
// retval.replace(from, to - from + 1, val);
// }
// if (not retval.empty() and retval.back() != '/')
// retval += '/';
// return retval;
// }
//} //unnamed namespace
int main (int parArgc, char* parArgv[]) {
QApplication app(parArgc, parArgv);
QQmlApplicationEngine engine;
engine.load(QUrl::fromLocalFile("/home/michele/dev/code/cpp/dindexer/src/gui/qml/mainwin.qml"));
//const auto qml_path = replace_dindexer_path(
// QML_PATH,
// { {"APP_PATH", QCoreApplication::applicationDirPath().toStdString()} }
//) + "mainwin.qml";
//engine.load(QUrl::fromLocalFile(QString::fromUtf8(qml_path.c_str(), qml_path.size())));
engine.load(QUrl::fromLocalFile(QML_PATH "/mainwin.qml"));
dinlib::Settings settings;
try {

View file

@ -36,6 +36,11 @@ void print_builtin_feats() {
printf("NDEBUG = yes (Release build)\n");
#else
printf("NDEBUG = no (Debug build)\n");
#endif
#if defined(DINDEXER_INST_MODE)
printf("INSTALL_MODE = yes\n");
#else
printf("INSTALL_MODE = no\n");
#endif
printf("Built on %s (CMake %s)\n", CMAKE_SYSTEM, CMAKE_VERSION);
printf("C compiler = %s %s\n", CMAKE_C_COMPILER_ID, CMAKE_C_COMPILER_VERSION);