Compare commits
49 Commits
c1c0325bce
...
myx-cmake
Author | SHA1 | Date | |
---|---|---|---|
3bdf4ceda3 | |||
1e635fc7bb | |||
6f2d2361fd | |||
6c1728bce0 | |||
6dbde42d6f | |||
023b493eff | |||
31a3fc3dc7 | |||
52c618c590 | |||
ece9b7cf70 | |||
bb580c0938 | |||
547a127956 | |||
554ab7efdf | |||
7319a202c3 | |||
c1235edaa9 | |||
a4ea9864be | |||
347ef3d46d | |||
b21def5945 | |||
cfe4fe8a2e | |||
11c572a96c | |||
e3d5243f80 | |||
3f633ee15c | |||
458dcd82c6 | |||
a4b181a838 | |||
2261982479 | |||
d159417bbb | |||
66ddb8a1fb | |||
dd1010a826 | |||
35ad2e1db8 | |||
7d0c2f68d6 | |||
7396f77054 | |||
3d3690ca64 | |||
105ed96f5f | |||
5645c5ea31 | |||
e63e6a4c8a | |||
a017ca6814 | |||
8114675c1c | |||
d839fa6ed4 | |||
a368091252 | |||
9468f95dd3 | |||
56a0b595d2 | |||
716545e49c | |||
b575634554 | |||
299dabf295 | |||
a29cea6f61 | |||
360b2b41d1 | |||
297b04bd56 | |||
3b2332a82f | |||
2d1537a9b8 | |||
77683831b9 |
248
.cmake-format.py
Normal file
248
.cmake-format.py
Normal file
@ -0,0 +1,248 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# ----------------------------------
|
||||
# Options affecting listfile parsing
|
||||
# ----------------------------------
|
||||
with section("parse"):
|
||||
|
||||
# Specify structure for custom cmake functions
|
||||
additional_commands = {
|
||||
'add_doxygen': { 'flags' : [],
|
||||
'kwargs': { 'LATEX': 1,
|
||||
'HTML': 1,
|
||||
'COMMENT': 1}},
|
||||
'add_breathe': { 'flags' : [],
|
||||
'kwargs': { 'COMMENT': 1}},
|
||||
'add_common_library': { 'flags' : [],
|
||||
'kwargs': { 'OUTPUT_NAME': 1,
|
||||
'SOURCES': '*',
|
||||
'TARGET': 1}},
|
||||
'qt5_translation': { 'flags' : [],
|
||||
'kwargs': { 'OUTPUT_DIR': 1,
|
||||
'LANGUAGES': '*',
|
||||
'SOURCES': '*',
|
||||
'BASE_NAME': 1}},
|
||||
'pvs_studio_add_target': { 'flags' : [ 'COMPILE_COMMANDS',
|
||||
'OUTPUT',
|
||||
'HIDE_HELP'],
|
||||
'kwargs': { 'ARGS': '*',
|
||||
'CONFIG': '*',
|
||||
'DEPENDS': '*',
|
||||
'FORMAT': '*',
|
||||
'MODE': '*',
|
||||
'TARGET': 1}},
|
||||
'write_compiler_detection_header': { 'flags' : [],
|
||||
'kwargs': { 'COMPILERS': '*',
|
||||
'FEATURES': '*',
|
||||
'FILE': '*',
|
||||
'PREFIX': '*'}}}
|
||||
|
||||
# Specify variable tags.
|
||||
vartags = []
|
||||
|
||||
# Specify property tags.
|
||||
proptags = []
|
||||
|
||||
# -----------------------------
|
||||
# Options affecting formatting.
|
||||
# -----------------------------
|
||||
with section("format"):
|
||||
|
||||
# How wide to allow formatted cmake files
|
||||
line_width = 110
|
||||
|
||||
# How many spaces to tab for indent
|
||||
tab_size = 2
|
||||
|
||||
# If an argument group contains more than this many sub-groups (parg or kwarg
|
||||
# groups) then force it to a vertical layout.
|
||||
max_subgroups_hwrap = 3
|
||||
|
||||
# If a positional argument group contains more than this many arguments, then
|
||||
# force it to a vertical layout.
|
||||
max_pargs_hwrap = 5
|
||||
|
||||
# If a cmdline positional group consumes more than this many lines without
|
||||
# nesting, then invalidate the layout (and nest)
|
||||
max_rows_cmdline = 2
|
||||
|
||||
# If true, separate flow control names from their parentheses with a space
|
||||
separate_ctrl_name_with_space = False
|
||||
|
||||
# If true, separate function names from parentheses with a space
|
||||
separate_fn_name_with_space = False
|
||||
|
||||
# If a statement is wrapped to more than one line, than dangle the closing
|
||||
# parenthesis on its own line.
|
||||
dangle_parens = False
|
||||
|
||||
# If the trailing parenthesis must be 'dangled' on its on line, then align it
|
||||
# to this reference: `prefix`: the start of the statement, `prefix-indent`:
|
||||
# the start of the statement, plus one indentation level, `child`: align to
|
||||
# the column of the arguments
|
||||
dangle_align = 'prefix'
|
||||
|
||||
# If the statement spelling length (including space and parenthesis) is
|
||||
# smaller than this amount, then force reject nested layouts.
|
||||
min_prefix_chars = 4
|
||||
|
||||
# If the statement spelling length (including space and parenthesis) is larger
|
||||
# than the tab width by more than this amount, then force reject un-nested
|
||||
# layouts.
|
||||
max_prefix_chars = 2
|
||||
|
||||
# If a candidate layout is wrapped horizontally but it exceeds this many
|
||||
# lines, then reject the layout.
|
||||
max_lines_hwrap = 2
|
||||
|
||||
# What style line endings to use in the output.
|
||||
line_ending = 'unix'
|
||||
|
||||
# Format command names consistently as 'lower' or 'upper' case
|
||||
command_case = 'canonical'
|
||||
|
||||
# Format keywords consistently as 'lower' or 'upper' case
|
||||
keyword_case = 'upper'
|
||||
|
||||
# A list of command names which should always be wrapped
|
||||
always_wrap = []
|
||||
|
||||
# If true, the argument lists which are known to be sortable will be sorted
|
||||
# lexicographicall
|
||||
enable_sort = True
|
||||
|
||||
# If true, the parsers may infer whether or not an argument list is sortable
|
||||
# (without annotation).
|
||||
autosort = False
|
||||
|
||||
# By default, if cmake-format cannot successfully fit everything into the
|
||||
# desired linewidth it will apply the last, most agressive attempt that it
|
||||
# made. If this flag is True, however, cmake-format will print error, exit
|
||||
# with non-zero status code, and write-out nothing
|
||||
require_valid_layout = False
|
||||
|
||||
# A dictionary mapping layout nodes to a list of wrap decisions. See the
|
||||
# documentation for more information.
|
||||
layout_passes = {}
|
||||
|
||||
# ------------------------------------------------
|
||||
# Options affecting comment reflow and formatting.
|
||||
# ------------------------------------------------
|
||||
with section("markup"):
|
||||
|
||||
# What character to use for bulleted lists
|
||||
bullet_char = '*'
|
||||
|
||||
# What character to use as punctuation after numerals in an enumerated list
|
||||
enum_char = '.'
|
||||
|
||||
# If comment markup is enabled, don't reflow the first comment block in each
|
||||
# listfile. Use this to preserve formatting of your copyright/license
|
||||
# statements.
|
||||
first_comment_is_literal = False
|
||||
|
||||
# If comment markup is enabled, don't reflow any comment block which matches
|
||||
# this (regex) pattern. Default is `None` (disabled).
|
||||
literal_comment_pattern = None
|
||||
|
||||
# Regular expression to match preformat fences in comments default=
|
||||
# ``r'^\s*([`~]{3}[`~]*)(.*)$'``
|
||||
fence_pattern = '^\\s*([`~]{3}[`~]*)(.*)$'
|
||||
|
||||
# Regular expression to match rulers in comments default=
|
||||
# ``r'^\s*[^\w\s]{3}.*[^\w\s]{3}$'``
|
||||
ruler_pattern = '^\\s*[^\\w\\s]{3}.*[^\\w\\s]{3}$'
|
||||
|
||||
# If a comment line matches starts with this pattern then it is explicitly a
|
||||
# trailing comment for the preceeding argument. Default is '#<'
|
||||
explicit_trailing_pattern = '#<'
|
||||
|
||||
# If a comment line starts with at least this many consecutive hash
|
||||
# characters, then don't lstrip() them off. This allows for lazy hash rulers
|
||||
# where the first hash char is not separated by space
|
||||
hashruler_min_length = 10
|
||||
|
||||
# If true, then insert a space between the first hash char and remaining hash
|
||||
# chars in a hash ruler, and normalize its length to fill the column
|
||||
canonicalize_hashrulers = True
|
||||
|
||||
# enable comment markup parsing and reflow
|
||||
enable_markup = False
|
||||
|
||||
# ----------------------------
|
||||
# Options affecting the linter
|
||||
# ----------------------------
|
||||
with section("lint"):
|
||||
|
||||
# a list of lint codes to disable
|
||||
disabled_codes = ['C0113']
|
||||
|
||||
# regular expression pattern describing valid function names
|
||||
function_pattern = '[0-9a-z_]+'
|
||||
|
||||
# regular expression pattern describing valid macro names
|
||||
macro_pattern = '[0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for variables with global
|
||||
# scope
|
||||
global_var_pattern = '[0-9A-Z][0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for variables with global
|
||||
# scope (but internal semantic)
|
||||
internal_var_pattern = '_[0-9A-Z][0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for variables with local
|
||||
# scope
|
||||
local_var_pattern = '[0-9a-z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for privatedirectory
|
||||
# variables
|
||||
private_var_pattern = '_[0-9a-z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for publicdirectory
|
||||
# variables
|
||||
public_var_pattern = '[0-9A-Z][0-9A-Z_]+'
|
||||
|
||||
# regular expression pattern describing valid names for keywords used in
|
||||
# functions or macros
|
||||
keyword_pattern = '[0-9A-Z_]+'
|
||||
|
||||
# In the heuristic for C0201, how many conditionals to match within a loop in
|
||||
# before considering the loop a parser.
|
||||
max_conditionals_custom_parser = 2
|
||||
|
||||
# Require at least this many newlines between statements
|
||||
min_statement_spacing = 1
|
||||
|
||||
# Require no more than this many newlines between statements
|
||||
max_statement_spacing = 2
|
||||
max_returns = 6
|
||||
max_branches = 12
|
||||
max_arguments = 5
|
||||
max_localvars = 15
|
||||
max_statements = 50
|
||||
|
||||
# -------------------------------
|
||||
# Options affecting file encoding
|
||||
# -------------------------------
|
||||
with section("encode"):
|
||||
|
||||
# If true, emit the unicode byte-order mark (BOM) at the start of the file
|
||||
emit_byteorder_mark = False
|
||||
|
||||
# Specify the encoding of the input file. Defaults to utf-8
|
||||
input_encoding = 'utf-8'
|
||||
|
||||
# Specify the encoding of the output file. Defaults to utf-8. Note that cmake
|
||||
# only claims to support utf-8 so be careful when using anything else
|
||||
output_encoding = 'utf-8'
|
||||
|
||||
# -------------------------------------
|
||||
# Miscellaneous configurations options.
|
||||
# -------------------------------------
|
||||
with section("misc"):
|
||||
|
||||
# A dictionary containing any per-command configuration overrides. Currently
|
||||
# only `command_case` is supported.
|
||||
per_command = {}
|
||||
|
43
.gitignore
vendored
43
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
# Каталог для результатов сборки проекта
|
||||
_build
|
||||
build
|
||||
|
||||
# Каталог для тестирования установки
|
||||
_output
|
||||
@ -13,6 +14,8 @@ files/etc/*.conf
|
||||
files/lib/*
|
||||
files/log/*
|
||||
|
||||
!.gitkeep
|
||||
!.gitignore
|
||||
|
||||
###
|
||||
### Общие настройки для C, C++, Fortran, Qt, CMake, Ninja, LaTeX и редакторов
|
||||
@ -43,6 +46,8 @@ files/log/*
|
||||
[._]ss[a-gi-z]
|
||||
[._]sw[a-p]
|
||||
|
||||
# Project
|
||||
.vimprj
|
||||
# Temporary
|
||||
.netrwhist
|
||||
*~
|
||||
@ -106,6 +111,10 @@ compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
### CMake Patch ###
|
||||
# External projects
|
||||
*-prefix/
|
||||
|
||||
|
||||
###
|
||||
### Ninja
|
||||
@ -162,6 +171,38 @@ target_wrapper.*
|
||||
*_qmlcache.qrc
|
||||
|
||||
|
||||
### KDevelop4 ###
|
||||
*.kdev4
|
||||
.kdev4/
|
||||
|
||||
|
||||
### vscode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
|
||||
### Eclipse ###
|
||||
.metadata
|
||||
.settings/
|
||||
.recommenders/
|
||||
|
||||
# TeXlipse
|
||||
.texlipse
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# CDT- autotools
|
||||
.autotools
|
||||
|
||||
|
||||
###
|
||||
### Latex
|
||||
###
|
||||
@ -173,6 +214,7 @@ target_wrapper.*
|
||||
*.blg
|
||||
*.dvi
|
||||
*.fdb_latexmk
|
||||
*.fls
|
||||
*.glg
|
||||
*.glo
|
||||
*.gls
|
||||
@ -195,6 +237,7 @@ target_wrapper.*
|
||||
*.synctex.gz
|
||||
*.toc
|
||||
*.vrb
|
||||
*.xdv
|
||||
*.xdy
|
||||
*.tdo
|
||||
|
||||
|
15
.gitmodules
vendored
15
.gitmodules
vendored
@ -1,15 +0,0 @@
|
||||
[submodule "cmake/etc/uncrustify"]
|
||||
path = cmake/etc/uncrustify
|
||||
url = ../../f1x1t/uncrustify-config.git
|
||||
[submodule "cmake/cmlib"]
|
||||
path = cmake/cmlib
|
||||
url = ../../f1x1t/cmlib
|
||||
[submodule "cmake/find"]
|
||||
path = cmake/find
|
||||
url = ../../f1x1t/cmake-find
|
||||
[submodule "cmake/generators"]
|
||||
path = cmake/generators
|
||||
url = ../../f1x1t/cmake-generators
|
||||
[submodule "cmake/doc"]
|
||||
path = cmake/doc
|
||||
url = ../../f1x1t/cmake-doc
|
3371
.uncrustify.cfg
Normal file
3371
.uncrustify.cfg
Normal file
File diff suppressed because it is too large
Load Diff
@ -3,15 +3,13 @@ cmake_minimum_required(VERSION 3.3)
|
||||
cmake_policy(VERSION 3.0.2..3.7)
|
||||
|
||||
# Название проекта
|
||||
project(myx VERSION 0.4.0 LANGUAGES C CXX)
|
||||
project(myx VERSION 0.9.0 LANGUAGES C CXX)
|
||||
|
||||
# В каталоге cmake/lib находятся файлы с библиотечными функциями
|
||||
if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/cmake/cmlib)
|
||||
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/cmlib)
|
||||
else()
|
||||
message(FATAL_ERROR "CMake library directory not exists")
|
||||
endif()
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/find)
|
||||
# Обязательные переменные
|
||||
set(MYX_CMAKE_ORGANIZATION_NAME "ECS5" CACHE STRING "")
|
||||
set(MYX_CMAKE_AUTHOR_NAME "Андрей Астафьев" CACHE STRING "")
|
||||
set(MYX_CMAKE_AUTHOR_EMAIL "dev@246060.ru" CACHE STRING "")
|
||||
set(MYX_CMAKE_DESCRIPTION "Разные функции" CACHE STRING "")
|
||||
|
||||
if(NOT DEFINED MYXLIB_MASTER_PROJECT)
|
||||
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
@ -21,7 +19,7 @@ if(NOT DEFINED MYXLIB_MASTER_PROJECT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(CMLibCommon)
|
||||
find_package(MyxCMake 0.4.5 REQUIRED)
|
||||
|
||||
#cmlib_set_cxx_standard(11)
|
||||
option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF)
|
||||
@ -36,7 +34,7 @@ find_package(Threads REQUIRED)
|
||||
# Qt5
|
||||
find_package(Qt5 COMPONENTS Core Network REQUIRED)
|
||||
|
||||
cmlib_generate_private_config_hpp()
|
||||
myx_cmake_generate_private_config_header()
|
||||
|
||||
# Библиотеки
|
||||
add_subdirectory(src/myx/backports/compiler)
|
||||
@ -46,6 +44,9 @@ add_subdirectory(src/myx/core)
|
||||
add_subdirectory(src/myx/filesystem)
|
||||
add_subdirectory(src/myx/qt)
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(myxlib-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=dev -P
|
||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
# Примеры
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
add_subdirectory(examples/core)
|
||||
@ -56,4 +57,5 @@ if(MYXLIB_BUILD_EXAMPLES)
|
||||
endif()
|
||||
|
||||
# Документация
|
||||
add_subdirectory(cmake/doc)
|
||||
myx_cmake_doc_doxygen(LATEX YES HTML YES)
|
||||
myx_cmake_doc_breathe()
|
||||
|
Submodule cmake/cmlib deleted from dbc0b76a76
Submodule cmake/doc deleted from dc9622f57e
@ -1,10 +0,0 @@
|
||||
set(ORGANIZATION_NAME "ECS5")
|
||||
set(AUTHOR_NAME "Андрей Астафьев")
|
||||
|
||||
set(DOXYGEN_PROJECT_TITLE "MyXLib")
|
||||
set(DOXYGEN_GENERATE_LATEX YES)
|
||||
set(DOXYGEN_GENERATE_HTML YES)
|
||||
|
||||
set(CPACK_COMPONENTS_ALL examples)
|
||||
set(CPACK_PACKAGE_CONTACT "Andrei Astafev <dev@246060.ru>")
|
||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Mixed functions")
|
Submodule cmake/etc/uncrustify deleted from e11d85f133
Submodule cmake/find deleted from bb640e3cf2
Submodule cmake/generators deleted from 74d499b9cb
@ -5,47 +5,17 @@ set(TRGT example-core-endian)
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian.cpp)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
add_dependencies(${TRGT} core)
|
||||
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME endian-minimal)
|
||||
|
||||
add_sanitizers(${TRGT})
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
add_dependencies(${TRGT} core)
|
||||
|
||||
cotire(${TRGT})
|
||||
|
||||
add_dependencies(${TRGT} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
# install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
endif()
|
||||
|
21
examples/core/02_current-system/CMakeLists.txt
Normal file
21
examples/core/02_current-system/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
# Название основной цели в текущем каталоге
|
||||
set(TRGT example-core-current-system)
|
||||
|
||||
# Список файлов исходных текстов
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/current_system.cpp)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME current-system-minimal)
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
add_dependencies(${TRGT} core)
|
||||
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
endif()
|
23
examples/core/02_current-system/current_system.cpp
Normal file
23
examples/core/02_current-system/current_system.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/core/current_system.hpp>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
//NOLINTNEXTLINE
|
||||
#define CMLIB_PROJECT_NAME "myxlib"
|
||||
|
||||
namespace MC = myx::core;
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
MC::CurrentSystem& currentSystem = MC::CurrentSystem::instance();
|
||||
qDebug() << "Current OS: " << QString::fromStdString( currentSystem.os() );
|
||||
qDebug() << "OS distrib: " << QString::fromStdString( currentSystem.distribution() );
|
||||
qDebug() << "OS variant: " << QString::fromStdString( currentSystem.variant() );
|
||||
qDebug() << "OS version: " << QString::fromStdString( currentSystem.version() );
|
||||
|
||||
return( 0 );
|
||||
} // main
|
@ -1 +1,2 @@
|
||||
add_subdirectory(01_endian)
|
||||
add_subdirectory(02_current-system)
|
||||
|
@ -5,48 +5,18 @@ set(TRGT example-filesystem-paths)
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
add_dependencies(${TRGT} core filesystem)
|
||||
|
||||
target_link_libraries(${TRGT} filesystem_static)
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME filesystem-minimal)
|
||||
|
||||
add_sanitizers(${TRGT})
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
add_dependencies(${TRGT} core filesystem)
|
||||
|
||||
cotire(${TRGT})
|
||||
|
||||
add_dependencies(${TRGT} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
# install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
target_link_libraries(${TRGT} filesystem-static)
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
endif()
|
||||
|
@ -18,22 +18,19 @@ int main( int argc, char** argv )
|
||||
QCoreApplication::setApplicationName( QStringLiteral( CMLIB_PROJECT_NAME ) );
|
||||
MF::Paths& paths = MF::Paths::instance();
|
||||
|
||||
paths.init();
|
||||
|
||||
qDebug() << "prefixDirectory : " << paths.projectDirectory();
|
||||
|
||||
qDebug() << "executableName : " << paths.executableName();
|
||||
qDebug() << "executableFilePath : " << paths.executableFilePath();
|
||||
qDebug() << "executableDirectory : " << paths.executableDirectory();
|
||||
|
||||
qDebug() << "configFileName : " << paths.configFileName();
|
||||
qDebug() << "configFilePath : " << paths.configFilePath();
|
||||
qDebug() << "executableDirectory : " << paths.executableDirectory() << endl;
|
||||
|
||||
qDebug() << "systemThemeDirectory : " << paths.systemThemeDirectory();
|
||||
qDebug() << "systemConfigDirectory : " << paths.systemConfigDirectory();
|
||||
qDebug() << "systemConstDataDirectory : " << paths.systemConstDataDirectory();
|
||||
qDebug() << "systemVarDataDirectory : " << paths.systemVarDataDirectory();
|
||||
qDebug() << "systemLogDirectory : " << paths.systemLogDirectory();
|
||||
qDebug() << "systemLogDirectory : " << paths.systemLogDirectory() << endl;
|
||||
|
||||
qDebug() << "userThemeDirectory : " << paths.userThemeDirectory();
|
||||
qDebug() << "userConfigDirectory : " << paths.userConfigDirectory();
|
||||
qDebug() << "userConstDataDirectory : " << paths.userConstDataDirectory();
|
||||
qDebug() << "userVarDataDirectory : " << paths.userVarDataDirectory();
|
||||
|
@ -4,56 +4,26 @@ set(TRGT example-qt-translators)
|
||||
# Список файлов исходных текстов
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp)
|
||||
|
||||
qt5_translation(
|
||||
myx_cmake_qt5_translation(
|
||||
TRGT_qrc
|
||||
OUTPUT_DIR ${CMAKE_SOURCE_DIR}/l10n
|
||||
BASE_NAME ${TRGT}
|
||||
LANGUAGES ru_RU)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp} ${TRGT_qrc})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
add_dependencies(${TRGT} core qt)
|
||||
|
||||
target_link_libraries(${TRGT} qt_static)
|
||||
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-translators)
|
||||
|
||||
add_sanitizers(${TRGT})
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
add_dependencies(${TRGT} core qt)
|
||||
|
||||
cotire(${TRGT})
|
||||
target_link_libraries(${TRGT} qt-static)
|
||||
|
||||
add_dependencies(${TRGT} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
# install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
endif()
|
||||
|
@ -5,49 +5,19 @@ set(TRGT example-qt-posix-signal-watcher)
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Путь поиска библиотек внутри проекта
|
||||
link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp})
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
add_dependencies(${TRGT} core qt)
|
||||
|
||||
target_link_libraries(${TRGT} qt_static)
|
||||
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-posix-signal-watcher)
|
||||
|
||||
add_sanitizers(${TRGT})
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
add_dependencies(${TRGT} core qt)
|
||||
|
||||
cotire(${TRGT})
|
||||
target_link_libraries(${TRGT} qt-static)
|
||||
|
||||
add_dependencies(${TRGT} create_auxilary_symlinks)
|
||||
|
||||
# Правила для установки
|
||||
# install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
endif()
|
||||
|
23
examples/qt/03_message-logger/CMakeLists.txt
Normal file
23
examples/qt/03_message-logger/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
# Название основной цели в текущем каталоге
|
||||
set(TRGT example-qt-message-logger)
|
||||
|
||||
# Список файлов исходных текстов
|
||||
set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/message_logger.cpp)
|
||||
|
||||
if(MYXLIB_BUILD_EXAMPLES)
|
||||
# Цель для создания исполняемого файла
|
||||
add_executable(${TRGT} ${TRGT_cpp})
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
|
||||
# Имя выходного файла для цели
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME qt-message-logger)
|
||||
|
||||
# Qt5
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
add_dependencies(${TRGT} core qt)
|
||||
|
||||
target_link_libraries(${TRGT} qt-static)
|
||||
|
||||
target_link_libraries(${TRGT} Qt5::Core)
|
||||
target_link_libraries(${TRGT} Threads::Threads)
|
||||
endif()
|
29
examples/qt/03_message-logger/message_logger.cpp
Normal file
29
examples/qt/03_message-logger/message_logger.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <myx/qt/message_logger_default.hpp>
|
||||
#include <myx/qt/message_logger_handler.hpp>
|
||||
#include <myx/qt/message_logger_syslog.hpp>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
|
||||
namespace MQ = myx::qt;
|
||||
int main( int argc, char* argv[] )
|
||||
{
|
||||
QCoreApplication app( argc, argv );
|
||||
|
||||
auto mld = QSharedPointer< MQ::MessageLoggerDefault >( new MQ::MessageLoggerDefault );
|
||||
MQ::messageLoggersList.append( mld );
|
||||
MQ::messageLoggersList.append( mld );
|
||||
auto mls = QSharedPointer< MQ::MessageLoggerSyslog >( new MQ::MessageLoggerSyslog );
|
||||
MQ::messageLoggersList.append( mls );
|
||||
qInstallMessageHandler( MQ::message_logger_handler );
|
||||
|
||||
qDebug() << "Hello from process:" << QCoreApplication::applicationPid();
|
||||
qWarning() << "Warning";
|
||||
|
||||
qInstallMessageHandler( nullptr );
|
||||
|
||||
qDebug() << "Reset user handlers";
|
||||
qWarning() << "Goodbye";
|
||||
|
||||
return( 0 );
|
||||
}
|
@ -1,2 +1,3 @@
|
||||
add_subdirectory(01_translators)
|
||||
add_subdirectory(02_posix-signal-watcher)
|
||||
add_subdirectory(03_message-logger)
|
||||
|
0
files/log/.gitkeep
Normal file
0
files/log/.gitkeep
Normal file
0
files/share/.gitkeep
Normal file
0
files/share/.gitkeep
Normal file
Binary file not shown.
Before Width: | Height: | Size: 86 KiB |
@ -16,27 +16,6 @@ set(TRGT_headers ${TRGT_hpp})
|
||||
add_library(${TRGT} INTERFACE)
|
||||
target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT base-dev
|
||||
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT dev
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/compiler)
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
|
@ -17,27 +17,6 @@ set(TRGT_headers ${TRGT_hpp})
|
||||
add_library(${TRGT} INTERFACE)
|
||||
target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT base-dev
|
||||
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT dev
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/cpp)
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace std {
|
||||
namespace std { //-V1061
|
||||
|
||||
template< class T, class E, class = void >
|
||||
struct is_contiguous_container : std::false_type {}; // NOLINT
|
||||
|
@ -16,27 +16,6 @@ set(TRGT_headers ${TRGT_hpp})
|
||||
add_library(${TRGT} INTERFACE)
|
||||
target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
install(FILES ${TRGT_headers} COMPONENT base-dev
|
||||
install(FILES ${TRGT_headers} COMPONENT dev
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/backports/qt)
|
||||
generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
|
@ -9,6 +9,7 @@ set(TRGT_cpp)
|
||||
set(TRGT_hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/config.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/limits.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/current_system.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/endian_types.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/enum_bitmask_operations.hpp)
|
||||
|
||||
@ -18,25 +19,8 @@ set(TRGT_headers ${TRGT_hpp})
|
||||
add_library(${TRGT} INTERFACE)
|
||||
target_sources(${TRGT} INTERFACE ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
target_include_directories(${TRGT} INTERFACE ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT dev
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
|
||||
|
109
src/myx/core/current_system.hpp
Normal file
109
src/myx/core/current_system.hpp
Normal file
@ -0,0 +1,109 @@
|
||||
#ifndef MYX_CORE_CURRENT_SYSTEM_HPP_
|
||||
#define MYX_CORE_CURRENT_SYSTEM_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace core {
|
||||
|
||||
class CurrentSystem
|
||||
{
|
||||
public:
|
||||
CurrentSystem( const CurrentSystem& ) = delete;
|
||||
CurrentSystem& operator=( const CurrentSystem& ) = delete;
|
||||
CurrentSystem( CurrentSystem&& ) = delete;
|
||||
CurrentSystem& operator=( CurrentSystem&& ) = delete;
|
||||
|
||||
/**
|
||||
* @brief instance
|
||||
* @return Уникальный экземпляр класса CurrentSystem
|
||||
*/
|
||||
static CurrentSystem& instance()
|
||||
{
|
||||
static CurrentSystem sCurrentSystem;
|
||||
return( sCurrentSystem );
|
||||
}
|
||||
|
||||
std::string os() const { return( m_os ); }
|
||||
std::string distribution() const { return( m_distribution ); }
|
||||
std::string variant() const { return( m_variant ); }
|
||||
std::string version() const { return( m_version ); }
|
||||
|
||||
protected:
|
||||
CurrentSystem() :
|
||||
m_os
|
||||
(
|
||||
#if defined( WIN32 ) || defined( _WIN32 ) || defined( __WIN32__ ) || defined( __NT__ )
|
||||
"windows"
|
||||
#elif __linux__
|
||||
"linux"
|
||||
#else
|
||||
#error "Unknown OS"
|
||||
#endif
|
||||
)
|
||||
{
|
||||
#if defined( __e2k__ )
|
||||
m_distribution = "debian";
|
||||
m_variant = "elbrus";
|
||||
std::ifstream file( "/etc/mcst_version" );
|
||||
if ( file.is_open() )
|
||||
{
|
||||
std::getline( file, m_version );
|
||||
file.close();
|
||||
}
|
||||
#else
|
||||
std::ifstream file( "/etc/os-release" );
|
||||
if ( file.is_open() )
|
||||
{
|
||||
std::string line;
|
||||
while ( std::getline( file, line ) )
|
||||
{
|
||||
std::size_t pos = line.find( "ID=" );
|
||||
if ( pos == 0 )
|
||||
{
|
||||
m_distribution = line.replace( pos, sizeof( "ID=" ) - 1, "" );
|
||||
}
|
||||
|
||||
pos = line.find( "VARIANT_ID=" );
|
||||
if ( pos != std::string::npos )
|
||||
{
|
||||
m_variant = line.replace( pos, sizeof( "VARIANT_ID=" ) - 1, "" );
|
||||
}
|
||||
|
||||
pos = line.find( "VERSION_ID=" );
|
||||
if ( pos != std::string::npos )
|
||||
{
|
||||
m_version = line.replace( pos, sizeof( "VERSION_ID=" ) - 1, "" );
|
||||
while ( ( pos = m_version.find( '"' ) ) != std::string::npos )
|
||||
{
|
||||
m_version.erase( pos, sizeof( '"' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
#endif // if defined( __e2k__ )
|
||||
}
|
||||
|
||||
~CurrentSystem() = default;
|
||||
|
||||
private:
|
||||
std::string m_os;
|
||||
std::string m_distribution;
|
||||
std::string m_variant;
|
||||
std::string m_version;
|
||||
}; // class CurrentSystem
|
||||
|
||||
// class CurrentSystem
|
||||
|
||||
} // namespace core
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // MYX_CORE_CURRENT_SYSTEM_HPP_
|
@ -91,11 +91,11 @@ public:
|
||||
LittleEndianType& operator^=( const T& b ) { *this = T( *this ) ^ b; return( *this ); }
|
||||
LittleEndianType& operator<<=( const T& b ) { *this = T( T( *this ) << b ); return( *this ); }
|
||||
LittleEndianType& operator>>=( const T& b ) { *this = T( T( *this ) >> b ); return( *this ); }
|
||||
friend std::ostream& operator<<( std::ostream& out, const LittleEndianType b ) { out << T( b ); return( out ); }
|
||||
friend std::ostream& operator<<( std::ostream& out, const LittleEndianType &b ) { out << T( b ); return( out ); }
|
||||
friend std::istream& operator>>( std::istream& in, LittleEndianType& b ) { T val; in >> val; b = val; return( in ); }
|
||||
std::string toStdString() { return( std::to_string( transform( m_data ) ) ); }
|
||||
#ifdef QT_CORE_LIB
|
||||
friend QDebug& operator<<( QDebug& out, const LittleEndianType< T > b ) { out << T( b ); return( out ); }
|
||||
friend QDebug& operator<<( QDebug& out, const LittleEndianType< T > &b ) { out << T( b ); return( out ); }
|
||||
QString toQString() { return( QString::number( transform( m_data ) ) ); }
|
||||
#endif
|
||||
}; // class LittleEndianType
|
||||
@ -151,11 +151,11 @@ public:
|
||||
BigEndianType& operator^=( const T& b ) { *this = T( *this ) ^ b; return( *this ); }
|
||||
BigEndianType& operator<<=( const T& b ) { *this = T( T( *this ) << b ); return( *this ); }
|
||||
BigEndianType& operator>>=( const T& b ) { *this = T( T( *this ) >> b ); return( *this ); }
|
||||
friend std::ostream& operator<<( std::ostream& out, const BigEndianType b ) { out << T( b ); return( out ); }
|
||||
friend std::ostream& operator<<( std::ostream& out, const BigEndianType &b ) { out << T( b ); return( out ); }
|
||||
friend std::istream& operator>>( std::istream& in, BigEndianType& b ) { T val; in >> val; b = val; return( in ); }
|
||||
std::string toStdString() { return( std::to_string( transform( m_data ) ) ); }
|
||||
#ifdef QT_CORE_LIB
|
||||
friend QDebug& operator<<( QDebug& out, const BigEndianType< T > b ) { out << T( b ); return( out ); }
|
||||
friend QDebug& operator<<( QDebug& out, const BigEndianType< T > &b ) { out << T( b ); return( out ); }
|
||||
QString toQString() { return( QString::number( transform( m_data ) ) ); }
|
||||
#endif
|
||||
}; // class BigEndianType
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef MYX_CORE_LIMITS_HPP_
|
||||
#define MYX_CORE_LIMITS_HPP_
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
|
@ -11,37 +11,15 @@ set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp)
|
||||
set(TRGT_headers ${TRGT_hpp})
|
||||
# cmake-format: on
|
||||
|
||||
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
#add_library(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
add_library(${TRGT} OBJECT ${TRGT_cpp} ${TRGT_headers})
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME myx-${TRGT})
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
myx_cmake_add_static_library(${TRGT})
|
||||
myx_cmake_add_shared_library(${TRGT})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
cotire(${TRGT})
|
||||
|
||||
install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT base-dev
|
||||
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT dev
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
|
@ -9,54 +9,28 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QString>
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
#include <QDebug>
|
||||
#endif
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
MYXLIB_INLINE Paths::Paths() :
|
||||
m_configFileExtension( ".conf" ),
|
||||
m_binDirRegex ( "/s*bin$" ),
|
||||
m_unityBinDirRegex ( "/bin/unity$" )
|
||||
m_binDirRegex ( QStringLiteral( "/s*bin$" ) ),
|
||||
m_unityBinDirRegex( QStringLiteral( "/bin/unity$" ) )
|
||||
{
|
||||
QFileInfo procSelfExe( QStringLiteral( "/proc/self/exe" ) );
|
||||
QFileInfo currentExecutable = procSelfExe.canonicalFilePath();
|
||||
m_executableName = currentExecutable.fileName();
|
||||
m_executableFilePath = currentExecutable.absoluteFilePath();
|
||||
m_executableDirectory = currentExecutable.absolutePath();
|
||||
|
||||
// Инициализация значениями по умолчанию
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
MYXLIB_INLINE bool Paths::init()
|
||||
{
|
||||
m_configFileName = m_executableName + m_configFileExtension;
|
||||
return( initCommon() );
|
||||
}
|
||||
|
||||
|
||||
//MYXLIB_INLINE bool Paths::init( const QString& configFileName )
|
||||
//{
|
||||
// m_configFileName = configFileName;
|
||||
// return( initCommon() );
|
||||
//}
|
||||
|
||||
|
||||
//MYXLIB_INLINE bool Paths::init( const QString& projectName, const QString& configFileExtension )
|
||||
//{
|
||||
// m_projectName = projectName.isEmpty() ? m_executableName
|
||||
// : projectName;
|
||||
// auto ext = configFileExtension.isEmpty() ? QStringLiteral( "conf" )
|
||||
// : configFileExtension;
|
||||
// m_configFileName = m_projectName + "." + ext;
|
||||
// return( initCommon() );
|
||||
//}
|
||||
|
||||
|
||||
MYXLIB_INLINE bool Paths::initCommon()
|
||||
MYXLIB_INLINE bool Paths::init( bool autodetect )
|
||||
{
|
||||
m_autodetect = autodetect;
|
||||
m_homeDirectory = QDir::homePath();
|
||||
m_tempDirectory = QDir::tempPath();
|
||||
|
||||
@ -72,79 +46,97 @@ MYXLIB_INLINE bool Paths::initCommon()
|
||||
m_dataDirectory = m_homeDirectory + "/.local/share";
|
||||
}
|
||||
|
||||
if ( m_projectName.isEmpty() )
|
||||
{
|
||||
m_projectName = m_executableName;
|
||||
}
|
||||
m_hierarchyType = getHierarchyType();
|
||||
calculatePaths( m_hierarchyType );
|
||||
|
||||
m_configFilePath = m_systemConfigDirectory + "/" + m_configFileName;
|
||||
|
||||
return( true );
|
||||
} // Paths::initCommon
|
||||
} // Paths::init
|
||||
|
||||
|
||||
MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& defaultProjectDirectory,
|
||||
const QString& defaultEtcDirectory,
|
||||
const QString& defaultConstDataDirectory,
|
||||
const QString& defaultVarDataDirectory,
|
||||
const QString& defaultLogDirectory )
|
||||
MYXLIB_INLINE void Paths::setupSystemDirectories( const QString& projectDir,
|
||||
const QString& etcDir,
|
||||
const QString& constDataDir,
|
||||
const QString& varDataDir,
|
||||
const QString& logDir )
|
||||
{
|
||||
QFileInfo prefixDirInfo { defaultProjectDirectory };
|
||||
QFileInfo prefixDirInfo { projectDir };
|
||||
if ( prefixDirInfo.isDir() && prefixDirInfo.isReadable() )
|
||||
{
|
||||
m_projectDirectory = defaultProjectDirectory;
|
||||
m_projectDirectory = projectDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_projectDirectory = QStringLiteral( "." );
|
||||
}
|
||||
|
||||
QFileInfo etcDirInfo { defaultEtcDirectory };
|
||||
QFileInfo etcDirInfo { etcDir };
|
||||
if ( etcDirInfo.isDir() && etcDirInfo.isReadable() )
|
||||
{
|
||||
m_systemConfigDirectory = defaultEtcDirectory;
|
||||
m_systemConfigDirectory = etcDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemConfigDirectory = m_userConfigDirectory;
|
||||
}
|
||||
|
||||
QFileInfo constDataDirInfo { defaultConstDataDirectory };
|
||||
QFileInfo constDataDirInfo { constDataDir };
|
||||
if ( constDataDirInfo.isDir() && constDataDirInfo.isReadable() )
|
||||
{
|
||||
m_systemConstDataDirectory = defaultConstDataDirectory;
|
||||
m_systemConstDataDirectory = constDataDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemConstDataDirectory = m_userConstDataDirectory;
|
||||
}
|
||||
|
||||
QFileInfo varDataDirInfo { defaultVarDataDirectory };
|
||||
QFileInfo varDataDirInfo { varDataDir };
|
||||
if ( varDataDirInfo.isDir() && varDataDirInfo.isWritable() )
|
||||
{
|
||||
m_systemVarDataDirectory = defaultVarDataDirectory;
|
||||
m_systemVarDataDirectory = varDataDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemVarDataDirectory = m_userVarDataDirectory;
|
||||
}
|
||||
|
||||
QFileInfo logDirInfo { defaultLogDirectory };
|
||||
QFileInfo logDirInfo { logDir };
|
||||
if ( logDirInfo.isDir() && logDirInfo.isWritable() )
|
||||
{
|
||||
m_systemLogDirectory = defaultLogDirectory;
|
||||
m_systemLogDirectory = logDir;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_systemLogDirectory = m_userLogDirectory;
|
||||
}
|
||||
|
||||
if ( !m_organizationName.isEmpty() && !m_themeName.isEmpty() )
|
||||
{
|
||||
m_systemThemeDirectory = "/opt/" + m_organizationName + "-" + m_themeName;
|
||||
}
|
||||
} // Paths::setupSystemDirectories
|
||||
|
||||
|
||||
MYXLIB_INLINE void Paths::setupUserDirectories( const QString& prefix )
|
||||
MYXLIB_INLINE void Paths::setupUserDirectories()
|
||||
{
|
||||
m_userConfigDirectory = m_configDirectory + "/" + prefix;
|
||||
m_userConstDataDirectory = m_dataDirectory + "/" + prefix + "/share";
|
||||
m_userVarDataDirectory = m_dataDirectory + "/" + prefix + "/var";
|
||||
m_userLogDirectory = m_dataDirectory + "/" + prefix + "/log";
|
||||
QString prefix;
|
||||
if ( !m_organizationName.isEmpty() )
|
||||
{
|
||||
prefix = "/" + m_organizationName;
|
||||
if ( !m_themeName.isEmpty() )
|
||||
{
|
||||
prefix.append( "-" + m_themeName );
|
||||
m_userThemeDirectory = m_dataDirectory + prefix;
|
||||
}
|
||||
}
|
||||
prefix.append( "/" + m_projectName );
|
||||
m_userConfigDirectory = m_configDirectory + prefix;
|
||||
m_userConstDataDirectory = m_dataDirectory + prefix + "/share";
|
||||
m_userVarDataDirectory = m_dataDirectory + prefix + "/var";
|
||||
m_userLogDirectory = m_dataDirectory + prefix + "/log";
|
||||
}
|
||||
|
||||
|
||||
@ -193,51 +185,17 @@ MYXLIB_INLINE Paths::HierarchyType Paths::getHierarchyType()
|
||||
MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
|
||||
{
|
||||
auto directory = m_executableDirectory;
|
||||
setupUserDirectories();
|
||||
|
||||
switch ( hType )
|
||||
{
|
||||
case HierarchyType::kFlat:
|
||||
setupSystemDirectories( directory, directory, directory, directory, directory );
|
||||
return;
|
||||
break;
|
||||
|
||||
case HierarchyType::kOpt:
|
||||
if ( m_organizationName.isEmpty() || m_themeName.isEmpty() )
|
||||
{
|
||||
QRegularExpression regex( "^/opt/(.+?)-(.+?)/" );
|
||||
QRegularExpressionMatch match = regex.match( m_executableDirectory );
|
||||
if ( match.hasMatch() )
|
||||
{
|
||||
m_organizationName = match.captured( 1 );
|
||||
m_themeName = match.captured( 2 );
|
||||
|
||||
QRegularExpression vr( "(.+?)\\.(.+)" );
|
||||
QRegularExpressionMatch vm = vr.match( m_themeName );
|
||||
if ( vm.hasMatch() )
|
||||
{
|
||||
m_themeName = vm.captured( 1 );
|
||||
m_version = vm.captured( 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_projectName.isEmpty() )
|
||||
{
|
||||
QRegularExpression regex( "^/opt/.+/(.+?)/" );
|
||||
QRegularExpressionMatch match = regex.match( m_executableDirectory );
|
||||
if ( match.hasMatch() )
|
||||
{
|
||||
m_projectName = match.captured( 1 );
|
||||
}
|
||||
}
|
||||
directory.remove( m_binDirRegex );
|
||||
|
||||
setupSystemDirectories( directory,
|
||||
directory + "/etc",
|
||||
directory + "/share",
|
||||
directory + "/var",
|
||||
directory + "/log" );
|
||||
setupUserDirectories( m_organizationName + "-" + m_themeName + "/" + m_projectName );
|
||||
return;
|
||||
processOptHierarhy();
|
||||
break;
|
||||
|
||||
case HierarchyType::kUsr:
|
||||
setupSystemDirectories( QStringLiteral( "/usr" ),
|
||||
@ -245,7 +203,7 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
|
||||
"/usr/share/" + m_projectName,
|
||||
"/var/lib/" + m_projectName,
|
||||
"/var/log/" + m_projectName );
|
||||
return;
|
||||
break;
|
||||
|
||||
case HierarchyType::kUsrLocal:
|
||||
setupSystemDirectories( QStringLiteral( "/usr/local" ),
|
||||
@ -253,7 +211,7 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
|
||||
"/usr/local/share/" + m_projectName,
|
||||
"/var/lib/" + m_projectName,
|
||||
"/var/log/" + m_projectName );
|
||||
return;
|
||||
break;
|
||||
|
||||
case HierarchyType::kUsrLocalOrg:
|
||||
directory.remove( m_binDirRegex );
|
||||
@ -262,15 +220,15 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
|
||||
directory + "/share",
|
||||
directory + "/var",
|
||||
directory + "/log" );
|
||||
return;
|
||||
break;
|
||||
|
||||
case HierarchyType::kHome:
|
||||
m_projectDirectory = m_homeDirectory;
|
||||
m_systemConfigDirectory = m_userConfigDirectory;
|
||||
m_systemConstDataDirectory = m_userConstDataDirectory;
|
||||
m_systemVarDataDirectory = m_userVarDataDirectory;
|
||||
m_systemLogDirectory = m_userLogDirectory;
|
||||
return;
|
||||
setupSystemDirectories( m_homeDirectory,
|
||||
m_userConfigDirectory,
|
||||
m_userConstDataDirectory,
|
||||
m_userVarDataDirectory,
|
||||
m_userLogDirectory );
|
||||
break;
|
||||
|
||||
case HierarchyType::kDevelopment:
|
||||
directory.remove( m_unityBinDirRegex );
|
||||
@ -280,23 +238,66 @@ MYXLIB_INLINE void Paths::calculatePaths( HierarchyType hType )
|
||||
directory + "/share",
|
||||
directory + "/var",
|
||||
directory + "/log" );
|
||||
return;
|
||||
break;
|
||||
|
||||
case HierarchyType::kUndefined:
|
||||
;
|
||||
} // switch
|
||||
setupUserDirectories();
|
||||
} // Paths::calculatePaths
|
||||
|
||||
|
||||
MYXLIB_INLINE void Paths::processOptHierarhy()
|
||||
{
|
||||
auto directory = m_executableDirectory;
|
||||
|
||||
if ( m_autodetect )
|
||||
{
|
||||
QRegularExpression regex( QStringLiteral( "^/opt/(.+?)/(.+?)/" ) );
|
||||
QRegularExpressionMatch match = regex.match( m_executableDirectory );
|
||||
|
||||
if ( match.hasMatch() )
|
||||
{
|
||||
m_organizationName = match.captured( 1 );
|
||||
m_projectName = match.captured( 2 );
|
||||
|
||||
QRegularExpression themeRegex( QStringLiteral( "(.+?)-(.+)" ) );
|
||||
QRegularExpressionMatch themeMatch = themeRegex.match( m_organizationName );
|
||||
if ( themeMatch.hasMatch() )
|
||||
{
|
||||
m_themeName = themeMatch.captured( 2 );
|
||||
m_organizationName = themeMatch.captured( 1 );
|
||||
}
|
||||
|
||||
QRegularExpression versionRegex( QStringLiteral( "(.+?)\\.(.+)" ) );
|
||||
QRegularExpressionMatch versionMatch = versionRegex.match( m_projectName );
|
||||
if ( versionMatch.hasMatch() )
|
||||
{
|
||||
m_projectName = versionMatch.captured( 1 );
|
||||
m_version = versionMatch.captured( 2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
directory.remove( m_binDirRegex );
|
||||
setupSystemDirectories( directory,
|
||||
directory + "/etc",
|
||||
directory + "/share",
|
||||
directory + "/var",
|
||||
directory + "/log" );
|
||||
setupUserDirectories();
|
||||
} // Paths::processOptHierarhy
|
||||
|
||||
|
||||
MYXLIB_INLINE bool Paths::makeDefaultSystemDirectories()
|
||||
{
|
||||
bool status = true;
|
||||
QDir dir;
|
||||
|
||||
if ( !dir.mkpath( m_systemConfigDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_systemVarDataDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_systemConstDataDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_systemLogDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_systemConfigDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_systemVarDataDirectory ) ) { status = false; }
|
||||
|
||||
return( status );
|
||||
}
|
||||
@ -307,10 +308,10 @@ MYXLIB_INLINE bool Paths::makeDefaultUserDirectories()
|
||||
bool status = true;
|
||||
QDir dir;
|
||||
|
||||
if ( !dir.mkpath( m_userConfigDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_userVarDataDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_userConstDataDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_userLogDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_userConfigDirectory ) ) { status = false; }
|
||||
if ( !dir.mkpath( m_userVarDataDirectory ) ) { status = false; }
|
||||
|
||||
return( status );
|
||||
}
|
||||
@ -322,25 +323,24 @@ MYXLIB_INLINE bool Paths::makeDefaultDirectories()
|
||||
}
|
||||
|
||||
|
||||
MYXLIB_INLINE QString Paths::findConfigFile( const QString& defaultConfigFile )
|
||||
MYXLIB_INLINE QString Paths::findConfigFile( const QString& configFileName )
|
||||
{
|
||||
if ( !defaultConfigFile.isEmpty() && QFileInfo( defaultConfigFile ).isReadable() )
|
||||
if ( !configFileName.isEmpty() && QFileInfo( configFileName ).isReadable() )
|
||||
{
|
||||
m_configFilePath = defaultConfigFile;
|
||||
return( defaultConfigFile );
|
||||
return( configFileName );
|
||||
}
|
||||
|
||||
auto fileName = QString::fromLocal8Bit( qgetenv( QCoreApplication::applicationName()
|
||||
.toUpper().toUtf8() + "_CONFIG" ) );
|
||||
if ( QFileInfo( fileName ).isReadable() )
|
||||
{
|
||||
m_configFilePath = fileName;
|
||||
return( fileName );
|
||||
}
|
||||
|
||||
if ( QFileInfo( m_configFilePath ).isReadable() )
|
||||
QString autoConfigFile = m_systemConfigDirectory + "/" + m_executableName;
|
||||
if ( QFileInfo( autoConfigFile ).isReadable() )
|
||||
{
|
||||
return( m_configFilePath );
|
||||
return( configFileName );
|
||||
}
|
||||
|
||||
return( QString() );
|
||||
@ -359,27 +359,15 @@ MYXLIB_INLINE const QString& Paths::systemConfigDirectory() const
|
||||
}
|
||||
|
||||
|
||||
MYXLIB_INLINE const QString& Paths::configFilePath() const
|
||||
MYXLIB_INLINE const QString& Paths::userThemeDirectory() const
|
||||
{
|
||||
return( m_configFilePath );
|
||||
return( m_userThemeDirectory );
|
||||
}
|
||||
|
||||
|
||||
MYXLIB_INLINE const QString& Paths::configFileName() const
|
||||
MYXLIB_INLINE const QString& Paths::systemThemeDirectory() const
|
||||
{
|
||||
return( m_configFileName );
|
||||
}
|
||||
|
||||
|
||||
const QString& Paths::configFileExtension() const
|
||||
{
|
||||
return( m_configFileExtension );
|
||||
}
|
||||
|
||||
|
||||
void Paths::setConfigFileExtension( const QString& name )
|
||||
{
|
||||
m_configFileExtension = name;
|
||||
return( m_systemThemeDirectory );
|
||||
}
|
||||
|
||||
|
||||
@ -437,6 +425,12 @@ MYXLIB_INLINE const QString& Paths::projectName() const
|
||||
}
|
||||
|
||||
|
||||
MYXLIB_INLINE void Paths::setProjectName( const QString& name )
|
||||
{
|
||||
m_projectName = name;
|
||||
}
|
||||
|
||||
|
||||
MYXLIB_INLINE const QString& Paths::organizationName() const
|
||||
{
|
||||
return( m_organizationName );
|
||||
|
@ -18,12 +18,12 @@ namespace myx {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
/** @brief Класс, предоставляющий методы для получения стандартных путей к каталогам и файлам */
|
||||
//* @brief Класс, предоставляющий методы для получения стандартных путей к каталогам и файлам
|
||||
class Paths
|
||||
{
|
||||
enum class HierarchyType : intptr_t
|
||||
{
|
||||
/** @brief Тип расположения файлов не определён */
|
||||
//* @brief Тип расположения файлов не определён
|
||||
kUndefined = 0x00,
|
||||
/** @brief Не определено ни одно из типовых размещений файлов
|
||||
* @details Если исполняемый файл не находится в каталоге bin или не найдены
|
||||
@ -31,17 +31,17 @@ class Paths
|
||||
* что все файлы находятся в одном каталоге с исполняемым файлом
|
||||
*/
|
||||
kFlat = 0x01,
|
||||
/** @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /opt */
|
||||
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /opt
|
||||
kOpt = 0x02,
|
||||
/** @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии / usr */
|
||||
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии / usr
|
||||
kUsr = 0x03,
|
||||
/** @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local */
|
||||
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local
|
||||
kUsrLocal = 0x04,
|
||||
/** @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local/ORG (используется для работ в проекте Сирена) */
|
||||
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /usr/local/ORG (используется для работ в проекте Сирена)
|
||||
kUsrLocalOrg = 0x05,
|
||||
/** @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /home */
|
||||
//* @brief Исполняемый файл и сопутствующие каталоги находятся в иерахии /home
|
||||
kHome = 0x06,
|
||||
/** @brief Исполняемый файл и сопутствующие каталоги находятся в каталоге программного проекта */
|
||||
//* @brief Исполняемый файл и сопутствующие каталоги находятся в каталоге программного проекта
|
||||
kDevelopment = 0x07
|
||||
};
|
||||
|
||||
@ -61,174 +61,168 @@ public:
|
||||
return( sPaths );
|
||||
}
|
||||
|
||||
/** @brief Обновление путей с учётом расположения исполняемого файла */
|
||||
bool init();
|
||||
//* @brief Обновление путей с учётом расположения исполняемого файла
|
||||
bool init( bool autodetect = true );
|
||||
|
||||
/** @brief Создание стандартных системных каталогов */
|
||||
//* @brief Создание стандартных системных каталогов
|
||||
bool makeDefaultSystemDirectories();
|
||||
|
||||
/** @brief Создание стандартных пользовательских каталогов */
|
||||
//* @brief Создание стандартных пользовательских каталогов
|
||||
bool makeDefaultUserDirectories();
|
||||
|
||||
/** @brief Создание стандартных каталогов */
|
||||
//* @brief Создание стандартных каталогов
|
||||
bool makeDefaultDirectories();
|
||||
|
||||
/** @brief Поиск существующего файла настойки.
|
||||
* Поиск выполняется до тех пор пока не будет найден файл в следующем порядке:
|
||||
* 1. Имя файла, указанное в качестве параметра функции
|
||||
* 2. Имя файла, заданное переменной окружения вида PROJECT_NAME_CONFIG
|
||||
* 3. Имя файла, полученное из внутренней переменной класса
|
||||
* 2. Имя файла, заданное переменной окружения вида EXECUTABLE_NAME_CONFIG
|
||||
* 3. Имя файла, полученное из имени каталога системных настроек и имени исполняемого файла
|
||||
* Если файл настройки не будет найден, то будет возвращена пустая строка
|
||||
*/
|
||||
QString findConfigFile( const QString& defaultConfigFile = QLatin1String( "" ) );
|
||||
QString findConfigFile( const QString& configFileName = QLatin1String( "" ) );
|
||||
|
||||
/** @brief Полный путь к базовому каталогу */
|
||||
const QString& projectName() const;
|
||||
|
||||
/** @brief Имя исполняемого файла */
|
||||
//* @brief Имя исполняемого файла
|
||||
const QString& executableName() const;
|
||||
|
||||
/** @brief Полный путь к исполняемому файлу */
|
||||
//* @brief Полный путь к исполняемому файлу
|
||||
const QString& executableFilePath() const;
|
||||
|
||||
/** @brief Полный путь к каталогу с исполняемым файлом */
|
||||
//* @brief Полный путь к каталогу с исполняемым файлом
|
||||
const QString& executableDirectory() const;
|
||||
|
||||
/** @brief Имя файла настройки */
|
||||
const QString& configFileName() const;
|
||||
//* @brief Путь к общему пользовательскому каталогу для файлов работы (темы)
|
||||
const QString& userThemeDirectory() const;
|
||||
|
||||
/** @brief Расширение файла настройки */
|
||||
const QString& configFileExtension() const;
|
||||
//* @brief Путь к общему системному каталогу для файлов работы (темы)
|
||||
const QString& systemThemeDirectory() const;
|
||||
|
||||
/** @brief Установка расширения файла настройки */
|
||||
void setConfigFileExtension( const QString& name );
|
||||
|
||||
/** @brief Полный путь к файлу настройки */
|
||||
const QString& configFilePath() const;
|
||||
|
||||
/** @brief Полный путь к пользовательскому каталогу с файлами настройки */
|
||||
//* @brief Полный путь к пользовательскому каталогу с файлами настройки
|
||||
const QString& userConfigDirectory() const;
|
||||
|
||||
/** @brief Полный путь к системному каталогу с файлами настройки */
|
||||
//* @brief Полный путь к системному каталогу с файлами настройки
|
||||
const QString& systemConfigDirectory() const;
|
||||
|
||||
/** @brief Полный путь к пользовательскому каталогу с изменяемыми файлами */
|
||||
//* @brief Полный путь к пользовательскому каталогу с изменяемыми файлами
|
||||
const QString& userVarDataDirectory() const;
|
||||
|
||||
/** @brief Полный путь к системному каталогу с изменяемыми файлами */
|
||||
//* @brief Полный путь к системному каталогу с изменяемыми файлами
|
||||
const QString& systemVarDataDirectory() const;
|
||||
|
||||
/** @brief Полный путь к пользовательскому каталогу с неизменяемыми файлами */
|
||||
//* @brief Полный путь к пользовательскому каталогу с неизменяемыми файлами
|
||||
const QString& userConstDataDirectory() const;
|
||||
|
||||
/** @brief Полный путь к системному каталогу с неизменяемыми файлами */
|
||||
//* @brief Полный путь к системному каталогу с неизменяемыми файлами
|
||||
const QString& systemConstDataDirectory() const;
|
||||
|
||||
/** @brief Полный путь к пользовательскому каталогу с журналами работы */
|
||||
//* @brief Полный путь к пользовательскому каталогу с журналами работы
|
||||
const QString& userLogDirectory() const;
|
||||
|
||||
/** @brief Полный путь к системному каталогу с журналами работы */
|
||||
//* @brief Полный путь к системному каталогу с журналами работы
|
||||
const QString& systemLogDirectory() const;
|
||||
|
||||
/** @brief Полный путь к каталогу с временными файлами */
|
||||
//* @brief Полный путь к каталогу с временными файлами
|
||||
const QString& tempDirectory() const;
|
||||
|
||||
/** @brief Полный путь к домашнему каталогу текущего пользователя */
|
||||
//* @brief Полный путь к домашнему каталогу текущего пользователя
|
||||
const QString& homeDirectory() const;
|
||||
|
||||
/** @brief Имя каталога для работы (темы) */
|
||||
const QString& themeDirectory() const;
|
||||
|
||||
/** @brief Имя каталога для проекта */
|
||||
//* @brief Имя каталога для проекта
|
||||
const QString& projectDirectory() const;
|
||||
|
||||
/** @brief Название организации */
|
||||
//* @brief Название организации
|
||||
const QString& organizationName() const;
|
||||
void setOrganizationName( const QString& name );
|
||||
|
||||
/** @brief Название работы (темы) */
|
||||
//* @brief Название работы (темы)
|
||||
const QString& themeName() const;
|
||||
void setThemeName( const QString& name );
|
||||
|
||||
//* @brief Название программного проекта
|
||||
const QString& projectName() const;
|
||||
void setProjectName( const QString& name );
|
||||
|
||||
protected:
|
||||
Paths();
|
||||
~Paths() = default;
|
||||
|
||||
private:
|
||||
/** @brief Тип расположения файлов по каталогам */
|
||||
//* @brief Тип расположения файлов по каталогам
|
||||
HierarchyType m_hierarchyType { HierarchyType::kFlat };
|
||||
|
||||
/** @brief Название организации */
|
||||
/** @brief Автоматически определять значения organizationName, themeName и projectName
|
||||
* @details Если true, то пытаться автоматически определять значения переменных
|
||||
* на основании полного пути к исполняемому файлу.
|
||||
* Иначе использовать значения переменных, указанные пользователем.
|
||||
*/
|
||||
bool m_autodetect { true };
|
||||
|
||||
//* @brief Название организации
|
||||
QString m_organizationName;
|
||||
|
||||
/** @brief Название работы (темы) */
|
||||
//* @brief Название работы (темы)
|
||||
QString m_themeName;
|
||||
|
||||
/** @brief Номер версии установленного пакета */
|
||||
//* @brief Номер версии установленного пакета
|
||||
QString m_version;
|
||||
|
||||
/** @brief Имя проекта, которое используется при формировании имён файлов и каталогов */
|
||||
//* @brief Имя проекта, которое используется при формировании имён файлов и каталогов
|
||||
QString m_projectName;
|
||||
|
||||
QString m_executableName;
|
||||
QString m_executableFilePath;
|
||||
QString m_executableDirectory;
|
||||
|
||||
/** @brief Общий каталог для файлов работы (темы) */
|
||||
QString m_themeDirectory;
|
||||
|
||||
/** @brief Общий каталог для файлов проекта */
|
||||
//* @brief Общий каталог для файлов проекта
|
||||
QString m_projectDirectory;
|
||||
|
||||
/** @brief Путь к каталогу с временными файлами */
|
||||
//* @brief Путь к каталогу с временными файлами
|
||||
QString m_tempDirectory;
|
||||
/** @brief Путь к домашнему каталогу текущего пользователя */
|
||||
//* @brief Путь к домашнему каталогу текущего пользователя
|
||||
QString m_homeDirectory;
|
||||
/** @brief Путь к общему пользовательскому каталогу настроек */
|
||||
//* @brief Путь к общему пользовательскому каталогу настроек
|
||||
QString m_configDirectory;
|
||||
/** @brief Путь к общему пользовательскому каталогу данных */
|
||||
//* @brief Путь к общему пользовательскому каталогу данных
|
||||
QString m_dataDirectory;
|
||||
|
||||
/** @brief Путь к пользовательскому каталогу с изменяемыми файлами */
|
||||
//* @brief Путь к общему пользовательскому каталогу для файлов работы (темы)
|
||||
QString m_userThemeDirectory;
|
||||
//* @brief Путь к общему системному каталогу для файлов работы (темы)
|
||||
QString m_systemThemeDirectory;
|
||||
|
||||
//* @brief Путь к пользовательскому каталогу с изменяемыми файлами
|
||||
QString m_userVarDataDirectory;
|
||||
/** @brief Путь к системному каталогу с изменяемыми файлами */
|
||||
//* @brief Путь к системному каталогу с изменяемыми файлами
|
||||
QString m_systemVarDataDirectory;
|
||||
|
||||
/** @brief Путь к пользовательскому каталогу с неизменяемыми файлами */
|
||||
//* @brief Путь к пользовательскому каталогу с неизменяемыми файлами
|
||||
QString m_userConstDataDirectory;
|
||||
/** @brief Путь к системному каталогу с неизменяемыми файлами */
|
||||
//* @brief Путь к системному каталогу с неизменяемыми файлами
|
||||
QString m_systemConstDataDirectory;
|
||||
|
||||
/** @brief Путь к пользовательскому каталогу с журналами работы */
|
||||
//* @brief Путь к пользовательскому каталогу с журналами работы
|
||||
QString m_userLogDirectory;
|
||||
/** @brief Путь к системному каталогу с журналами работы */
|
||||
//* @brief Путь к системному каталогу с журналами работы
|
||||
QString m_systemLogDirectory;
|
||||
|
||||
/** @brief Путь к пользовательскому каталогу с файлами настройки */
|
||||
//* @brief Путь к пользовательскому каталогу с файлами настройки
|
||||
QString m_userConfigDirectory;
|
||||
/** @brief Путь к системному каталогу с файлами настройки */
|
||||
//* @brief Путь к системному каталогу с файлами настройки
|
||||
QString m_systemConfigDirectory;
|
||||
|
||||
/** @brief Полный путь к файлу настройки */
|
||||
QString m_configFilePath;
|
||||
/** @brief Имя файла настройки */
|
||||
QString m_configFileName;
|
||||
/** @brief Расширение файла настройки */
|
||||
QString m_configFileExtension;
|
||||
|
||||
QRegularExpression m_binDirRegex;
|
||||
QRegularExpression m_unityBinDirRegex;
|
||||
|
||||
void setupSystemDirectories( const QString& defaultProjectDirectory,
|
||||
const QString& defaultEtcDirectory,
|
||||
const QString& defaultConstDataDirectory,
|
||||
const QString& defaultVarDataDirectory,
|
||||
const QString& defaultLogDirectory );
|
||||
void setupUserDirectories( const QString& prefix );
|
||||
void setupSystemDirectories( const QString& projectDir,
|
||||
const QString& etcDir,
|
||||
const QString& constDataDir,
|
||||
const QString& varDataDir,
|
||||
const QString& logDir );
|
||||
void setupUserDirectories();
|
||||
|
||||
bool initCommon();
|
||||
HierarchyType getHierarchyType();
|
||||
void calculatePaths( HierarchyType hType );
|
||||
void processOptHierarhy();
|
||||
}; // class Paths
|
||||
|
||||
} // namespace filesystem
|
||||
|
@ -6,6 +6,9 @@ set(TRGT qt)
|
||||
set(TRGT_cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/posix_signal_watcher.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/translators.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_default.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_handler.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_syslog.cpp
|
||||
)
|
||||
|
||||
set(TRGT_moc_hpp
|
||||
@ -18,6 +21,10 @@ set(TRGT_moc_private_hpp
|
||||
|
||||
set(TRGT_hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/translators.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_default.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_handler.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/message_logger_syslog.hpp
|
||||
)
|
||||
|
||||
set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp})
|
||||
@ -25,39 +32,14 @@ set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp})
|
||||
|
||||
qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_private_hpp} ${TRGT_moc_hpp})
|
||||
|
||||
add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_moc_cpp}
|
||||
${TRGT_moc_private_hpp} ${TRGT_headers})
|
||||
common_target_properties(${TRGT})
|
||||
|
||||
# Создание цели для проверки утилитой clang-tidy
|
||||
add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clang-analyze
|
||||
add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой clazy
|
||||
add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers})
|
||||
|
||||
# Создание цели для проверки утилитой pvs-studio
|
||||
add_pvs_check(${TRGT})
|
||||
|
||||
# Создание цели для автоматического форматирования кода
|
||||
add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers} ${TRGT_moc_private_hpp})
|
||||
add_library(${TRGT} OBJECT ${TRGT_cpp} ${TRGT_moc_cpp} ${TRGT_moc_private_hpp} ${TRGT_headers})
|
||||
set_target_properties(${TRGT} PROPERTIES OUTPUT_NAME myx-${TRGT})
|
||||
myx_cmake_common_target_properties(${TRGT})
|
||||
myx_cmake_add_static_library(${TRGT})
|
||||
myx_cmake_add_shared_library(${TRGT})
|
||||
|
||||
target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS})
|
||||
target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
target_include_directories(${TRGT} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
||||
cotire(${TRGT})
|
||||
|
||||
install(TARGETS ${TRGT}_static COMPONENT libs-dev ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
if(BUILD_SHARED_LIBS)
|
||||
install(TARGETS ${TRGT}_shared COMPONENT main LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
generate_pkgconfig(myx-${TRGT} COMPONENT base-dev INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT base-dev
|
||||
myx_cmake_generate_pkgconfig(${TRGT} BASENAME myx-${TRGT} INSTALL_LIBRARY ${MYXLIB_BUILD_LIBRARIES})
|
||||
install(FILES ${TRGT_headers} COMPONENT dev
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT})
|
||||
|
||||
# Цель, используемая только для установки заголовочных файлов без компиляции проекта
|
||||
add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P
|
||||
"${CMAKE_BINARY_DIR}/cmake_install.cmake")
|
||||
|
44
src/myx/qt/message_logger.hpp
Normal file
44
src/myx/qt/message_logger.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <QList>
|
||||
#include <QMessageLogContext>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
class MessageLogger
|
||||
{
|
||||
public:
|
||||
virtual ~MessageLogger() noexcept ( true ) = default;
|
||||
|
||||
virtual void debug( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void info( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void warning( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void critical( const QMessageLogContext& context, const QString& ) = 0;
|
||||
virtual void fatal( const QMessageLogContext& context, const QString& ) = 0;
|
||||
|
||||
void setEnabled( bool v = true ) { m_enabled = v; }
|
||||
bool isEnabled() { return( m_enabled ); }
|
||||
|
||||
protected:
|
||||
bool m_enabled { true };
|
||||
};
|
||||
|
||||
using MessageLoggersList = QList< QSharedPointer< MessageLogger > >;
|
||||
extern MessageLoggersList messageLoggersList;
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_HPP_
|
46
src/myx/qt/message_logger_default.cpp
Normal file
46
src/myx/qt/message_logger_default.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <myx/qt/message_logger_default.hpp>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
void MessageLoggerDefault::debug( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
fprintf( stderr, "D: %s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::info( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
fprintf( stderr, "I: %s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::warning( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
fprintf( stderr, "W: %s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::critical( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerDefault::fatal( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
}
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
31
src/myx/qt/message_logger_default.hpp
Normal file
31
src/myx/qt/message_logger_default.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
class MessageLoggerDefault : public MessageLogger
|
||||
{
|
||||
public:
|
||||
virtual ~MessageLoggerDefault() noexcept ( true ) = default;
|
||||
|
||||
void debug( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void info( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void warning( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void critical( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void fatal( const QMessageLogContext& context, const QString& msg ) override;
|
||||
};
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_DEFAULT_HPP_
|
81
src/myx/qt/message_logger_handler.cpp
Normal file
81
src/myx/qt/message_logger_handler.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
MessageLoggersList messageLoggersList;
|
||||
|
||||
void message_logger_handler( QtMsgType type, const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
if ( messageLoggersList.isEmpty() )
|
||||
{
|
||||
QByteArray localMsg = msg.toLocal8Bit();
|
||||
const char* file = context.file != nullptr ? context.file : "";
|
||||
const char* function = context.function != nullptr ? context.function : "";
|
||||
switch ( type )
|
||||
{
|
||||
case QtDebugMsg:
|
||||
#ifndef QT_NO_DEBUG_OUTPUT
|
||||
// fprintf( stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
#endif
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
#ifndef QT_NO_INFO_OUTPUT
|
||||
// fprintf( stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
#endif
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
#ifndef QT_NO_WARNING_OUTPUT
|
||||
// fprintf( stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
#endif
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
// fprintf( stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
// fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
// break;
|
||||
case QtFatalMsg:
|
||||
// fprintf( stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function );
|
||||
fprintf( stderr, "%s\n", localMsg.constData() );
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( type )
|
||||
{
|
||||
case QtDebugMsg:
|
||||
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->debug( context, msg ); } }
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->info( context, msg ); } }
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->warning( context, msg ); } }
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->critical( context, msg ); } }
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
for ( const auto& m: qAsConst( messageLoggersList ) )
|
||||
{ if ( m->isEnabled() ) { m->fatal( context, msg ); } }
|
||||
break;
|
||||
} // switch
|
||||
}
|
||||
} // message_logger_handler
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
20
src/myx/qt/message_logger_handler.hpp
Normal file
20
src/myx/qt/message_logger_handler.hpp
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
void message_logger_handler( QtMsgType type, const QMessageLogContext& context, const QString& msg );
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_HANDLER_HPP_
|
61
src/myx/qt/message_logger_syslog.cpp
Normal file
61
src/myx/qt/message_logger_syslog.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
|
||||
#include <myx/qt/message_logger_syslog.hpp>
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
MessageLoggerSyslog::MessageLoggerSyslog() :
|
||||
MessageLogger()
|
||||
{
|
||||
// openlog( nullptr, LOG_ODELAY, LOG_USER );
|
||||
}
|
||||
|
||||
|
||||
MessageLoggerSyslog::~MessageLoggerSyslog() noexcept ( true )
|
||||
{
|
||||
closelog();
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::debug( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_DEBUG, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::info( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_INFO, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::warning( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_WARNING, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::critical( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_CRIT, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
|
||||
void MessageLoggerSyslog::fatal( const QMessageLogContext& context, const QString& msg )
|
||||
{
|
||||
Q_UNUSED( context )
|
||||
syslog( LOG_EMERG, "%s\n", msg.toUtf8().data() );
|
||||
}
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
32
src/myx/qt/message_logger_syslog.hpp
Normal file
32
src/myx/qt/message_logger_syslog.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
||||
#define MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <myx/backports/qt/common.hpp>
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/qt/message_logger.hpp>
|
||||
|
||||
|
||||
namespace myx {
|
||||
|
||||
namespace qt {
|
||||
|
||||
class MessageLoggerSyslog : public MessageLogger
|
||||
{
|
||||
public:
|
||||
MessageLoggerSyslog();
|
||||
virtual ~MessageLoggerSyslog() noexcept ( true );
|
||||
|
||||
void debug( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void info( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void warning( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void critical( const QMessageLogContext& context, const QString& msg ) override;
|
||||
void fatal( const QMessageLogContext& context, const QString& msg ) override;
|
||||
};
|
||||
|
||||
} // namespace qt
|
||||
|
||||
} // namespace myx
|
||||
|
||||
#endif // ifndef MYX_QT_MESSAGE_LOGGER_SYSLOG_HPP_
|
@ -18,8 +18,8 @@ PosixSignalWatcherPrivate::~PosixSignalWatcherPrivate() = default;
|
||||
PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) :
|
||||
q_ptr( q )
|
||||
{
|
||||
#if MYX_QT_HAS_POSIX_SIGNALS
|
||||
// Create socket pair
|
||||
#ifdef Q_OS_UNIX
|
||||
// Create socket pair
|
||||
if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, mSockpair.data() ) != 0 )
|
||||
{
|
||||
qDebug() << "PosixSignalWatcher: socketpair: " << ::strerror( errno );
|
||||
@ -61,8 +61,8 @@ MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal )
|
||||
return;
|
||||
}
|
||||
|
||||
#if MYX_QT_HAS_POSIX_SIGNALS
|
||||
// Register a sigaction which will write to the socket pair
|
||||
#ifdef Q_OS_UNIX
|
||||
// Register a sigaction which will write to the socket pair
|
||||
struct sigaction sigact; //NOLINT
|
||||
sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; //NOLINT
|
||||
sigact.sa_flags = 0;
|
||||
|
@ -6,25 +6,19 @@
|
||||
#include <myx/core/config.hpp>
|
||||
#include <myx/qt/posix_signal_watcher.hpp>
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QSocketNotifier>
|
||||
#include <QtDebug>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#define MYX_QT_HAS_POSIX_SIGNALS 0
|
||||
#else
|
||||
#define MYX_QT_HAS_POSIX_SIGNALS 1
|
||||
#endif
|
||||
|
||||
#if MYX_QT_HAS_POSIX_SIGNALS
|
||||
#ifdef Q_OS_UNIX
|
||||
#include <cerrno>
|
||||
#include <csignal>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#include <cerrno>
|
||||
#endif
|
||||
|
||||
namespace myx {
|
||||
@ -42,7 +36,7 @@ class PosixSignalWatcherPrivate : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PosixSignalWatcherPrivate( PosixSignalWatcher* q );
|
||||
explicit PosixSignalWatcherPrivate( PosixSignalWatcher* q );
|
||||
~PosixSignalWatcherPrivate();
|
||||
|
||||
void watchForSignal( int signal );
|
||||
|
Reference in New Issue
Block a user