From a4d00ed80b939acdc41ba4818edb85cec2bb925f Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Sun, 28 Jun 2020 09:52:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82?= =?UTF-8?q?=D0=B5=D0=BA=D0=B0=20=D1=82=D1=80=D0=B5=D0=B1=D1=83=D0=B5=D1=82?= =?UTF-8?q?=20=D1=81=D0=B1=D0=BE=D1=80=D0=BA=D0=B8=20=D0=B2=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=20(=D0=B8=D0=B7-=D0=B7=D0=B0=20moc)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 10 ++-- examples/base/01_endian/CMakeLists.txt | 27 +--------- examples/base/01_endian/endian.cpp | 2 - .../{01_minimal => 01_paths}/CMakeLists.txt | 29 +--------- .../minimal.cpp => 01_paths/paths.cpp} | 0 examples/filesystem/CMakeLists.txt | 2 +- examples/qt/01_translators/CMakeLists.txt | 26 --------- .../qt/02_posix-signal-watcher/CMakeLists.txt | 30 ----------- src/myx/base/CMakeLists.txt | 42 ++++++--------- src/myx/base/config.cpp | 9 ---- src/myx/base/config.hpp | 12 ----- src/myx/base/endian_types.hpp | 8 +-- src/myx/filesystem/CMakeLists.txt | 50 +++++++---------- src/myx/filesystem/paths.cpp | 7 +-- src/myx/filesystem/paths.hpp | 4 -- src/myx/qt/CMakeLists.txt | 53 ++++++++----------- src/myx/qt/posix_signal_watcher.cpp | 21 +++----- src/myx/qt/posix_signal_watcher.hpp | 7 +-- src/myx/qt/posix_signal_watcher_p.hpp | 7 +-- src/myx/qt/translators.cpp | 5 -- src/myx/qt/translators.hpp | 4 -- 21 files changed, 84 insertions(+), 271 deletions(-) rename examples/filesystem/{01_minimal => 01_paths}/CMakeLists.txt (65%) rename examples/filesystem/{01_minimal/minimal.cpp => 01_paths/paths.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9afefa..ee9cf59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,11 +23,7 @@ endif() include(CMLibCommon) -option(MYXLIB_BUILD_LIBRARIES "Build libraries" OFF) -if(MYXLIB_BUILD_LIBRARIES) - option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF) -endif() -option(MYXLIB_BUILD_EXAMPLES_HO "Build examples using header only version" OFF) +option(MYXLIB_BUILD_EXAMPLES "Build examples" OFF) # Поиск библиотек с помощью pkgconfig find_package(PkgConfig REQUIRED) @@ -45,10 +41,12 @@ add_subdirectory(src/myx/filesystem) add_subdirectory(src/myx/qt) # Примеры -if(MYXLIB_BUILD_EXAMPLES OR MYXLIB_BUILD_EXAMPLES_HO) +if(MYXLIB_BUILD_EXAMPLES) add_subdirectory(examples/base) add_subdirectory(examples/filesystem) add_subdirectory(examples/qt) + add_custom_target(examples example-base-endian example-filesystem-paths example-qt-tranlators + example-qt-posix-signal-watcher) endif() # Документация diff --git a/examples/base/01_endian/CMakeLists.txt b/examples/base/01_endian/CMakeLists.txt index 199646f..cc3a06e 100644 --- a/examples/base/01_endian/CMakeLists.txt +++ b/examples/base/01_endian/CMakeLists.txt @@ -1,5 +1,5 @@ # Название основной цели в текущем каталоге -set(TRGT example-endian-minimal) +set(TRGT example-base-endian) # Список файлов исходных текстов set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/endian.cpp) @@ -50,28 +50,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME endian-minimal-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/examples/base/01_endian/endian.cpp b/examples/base/01_endian/endian.cpp index 5b86e63..a4cc260 100644 --- a/examples/base/01_endian/endian.cpp +++ b/examples/base/01_endian/endian.cpp @@ -5,8 +5,6 @@ #define CMLIB_PROJECT_NAME "myxlib" -namespace MB = myx::base; - int main( int argc, char** argv ) { diff --git a/examples/filesystem/01_minimal/CMakeLists.txt b/examples/filesystem/01_paths/CMakeLists.txt similarity index 65% rename from examples/filesystem/01_minimal/CMakeLists.txt rename to examples/filesystem/01_paths/CMakeLists.txt index f4d533a..2062f33 100644 --- a/examples/filesystem/01_minimal/CMakeLists.txt +++ b/examples/filesystem/01_paths/CMakeLists.txt @@ -1,8 +1,8 @@ # Название основной цели в текущем каталоге -set(TRGT example-filesystem-minimal) +set(TRGT example-filesystem-paths) # Список файлов исходных текстов -set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/minimal.cpp) +set(TRGT_cpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp) if(MYXLIB_BUILD_EXAMPLES) # Путь поиска библиотек внутри проекта @@ -50,28 +50,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only filesystem-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME filesystem-minimal-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/examples/filesystem/01_minimal/minimal.cpp b/examples/filesystem/01_paths/paths.cpp similarity index 100% rename from examples/filesystem/01_minimal/minimal.cpp rename to examples/filesystem/01_paths/paths.cpp diff --git a/examples/filesystem/CMakeLists.txt b/examples/filesystem/CMakeLists.txt index 5e9d165..1254222 100644 --- a/examples/filesystem/CMakeLists.txt +++ b/examples/filesystem/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(01_minimal) +add_subdirectory(01_paths) diff --git a/examples/qt/01_translators/CMakeLists.txt b/examples/qt/01_translators/CMakeLists.txt index 59af417..c02441f 100644 --- a/examples/qt/01_translators/CMakeLists.txt +++ b/examples/qt/01_translators/CMakeLists.txt @@ -11,7 +11,6 @@ qt5_translation( LANGUAGES ru_RU) if(MYXLIB_BUILD_EXAMPLES) - # Путь поиска библиотек внутри проекта link_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) @@ -58,28 +57,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_qrc}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only qt-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME qt-translators-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/examples/qt/02_posix-signal-watcher/CMakeLists.txt b/examples/qt/02_posix-signal-watcher/CMakeLists.txt index 88d72d2..1caeae2 100644 --- a/examples/qt/02_posix-signal-watcher/CMakeLists.txt +++ b/examples/qt/02_posix-signal-watcher/CMakeLists.txt @@ -51,33 +51,3 @@ if(MYXLIB_BUILD_EXAMPLES) # Правила для установки install(TARGETS ${TRGT} COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() - -if(MYXLIB_BUILD_EXAMPLES_HO) - set(TRGT_moc_hpp - ${CMAKE_SOURCE_DIR}/src/myx/qt/posix_signal_watcher.hpp - ${CMAKE_SOURCE_DIR}/src/myx/qt/posix_signal_watcher_p.hpp) - qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_hpp}) - - # Цель для создания исполняемого файла - add_executable(${TRGT}-ho ${TRGT_cpp} ${TRGT_moc_cpp}) - common_target_properties(${TRGT}-ho) - - target_include_directories(${TRGT}-ho PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_include_directories(${TRGT}-ho SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) - - add_dependencies(${TRGT}-ho base-header-only qt-header-only) - - target_link_libraries(${TRGT}-ho Qt5::Core) - target_link_libraries(${TRGT}-ho Threads::Threads) - - # Имя выходного файла для цели - set_target_properties(${TRGT}-ho PROPERTIES OUTPUT_NAME qt-posix-signal-watcher-ho) - - add_sanitizers(${TRGT}-ho) - cotire(${TRGT}-ho) - - add_dependencies(${TRGT}-ho create_auxilary_symlinks) - - # Правила для установки - install(TARGETS ${TRGT}-ho COMPONENT examples RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -endif() diff --git a/src/myx/base/CMakeLists.txt b/src/myx/base/CMakeLists.txt index fa6b9bd..42627d7 100644 --- a/src/myx/base/CMakeLists.txt +++ b/src/myx/base/CMakeLists.txt @@ -17,39 +17,29 @@ set(TRGT_hpp set(TRGT_headers ${TRGT_hpp}) # cmake-format: on -add_library(${TRGT}-header-only INTERFACE) -target_include_directories( - ${TRGT}-header-only SYSTEM INTERFACE "$" - "$") +add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) +common_target_properties(${TRGT}) -if(MYXLIB_BUILD_LIBRARIES) - 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-tidy - add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_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}) - # Создание цели для проверки утилитой clazy - add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) - # Создание цели для проверки утилитой pvs-studio - add_pvs_check(${TRGT}) +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для автоматического форматирования кода - add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - target_compile_definitions(${TRGT} PUBLIC MYXLIB_BUILD_LIBRARIES) - target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) - - 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() -else() - install(FILES ${TRGT_cpp} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${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}) diff --git a/src/myx/base/config.cpp b/src/myx/base/config.cpp index c35efbf..3e8bcfb 100644 --- a/src/myx/base/config.cpp +++ b/src/myx/base/config.cpp @@ -1,10 +1 @@ -#ifndef MYX_BASE_CONFIG_CPP_ -#define MYX_BASE_CONFIG_CPP_ - -#ifndef MYXLIB_HEADER_ONLY #include -#else -#pragma once -#endif - -#endif // MYX_BASE_CONFIG_CPP_ diff --git a/src/myx/base/config.hpp b/src/myx/base/config.hpp index 0473bfe..c179cdf 100644 --- a/src/myx/base/config.hpp +++ b/src/myx/base/config.hpp @@ -3,9 +3,6 @@ #pragma once -#ifdef MYXLIB_BUILD_LIBRARIES -#undef MYXLIB_HEADER_ONLY - #if defined( _WIN32 ) && defined( MYXLIB_SHARED_LIB ) #ifdef myxlib_EXPORTS #define MYXLIB_API __declspec( dllexport ) @@ -16,14 +13,5 @@ #define MYXLIB_API #endif #define MYXLIB_INLINE -#else -#define MYXLIB_HEADER_ONLY -#define MYXLIB_API -#define MYXLIB_INLINE inline -#endif // ifdef MYXLIB_BUILD_LIBRARIES - -#ifdef MYXLIB_HEADER_ONLY -#include "config.cpp" -#endif #endif // MYX_BASE_CONFIG_HPP_ diff --git a/src/myx/base/endian_types.hpp b/src/myx/base/endian_types.hpp index bc61749..063779b 100644 --- a/src/myx/base/endian_types.hpp +++ b/src/myx/base/endian_types.hpp @@ -49,8 +49,8 @@ protected: static T transform( const T& b ) { - const uint16_t i = 1; - return( ( reinterpret_cast< const char& >( i ) == 1 ) ? b : EndianTypesBase< T >::swapBytes( b ) ); + const uint16_t k_i = 1; + return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? b : EndianTypesBase< T >::swapBytes( b ) ); } @@ -110,8 +110,8 @@ protected: static T transform( const T& b ) { - const uint16_t i = 1; - return( ( reinterpret_cast< const char& >( i ) == 1 ) ? EndianTypesBase< T >::swapBytes( b ) : b ); + const uint16_t k_i = 1; + return( ( reinterpret_cast< const char& >( k_i ) == 1 ) ? EndianTypesBase< T >::swapBytes( b ) : b ); } diff --git a/src/myx/filesystem/CMakeLists.txt b/src/myx/filesystem/CMakeLists.txt index be1f89a..0ec1240 100644 --- a/src/myx/filesystem/CMakeLists.txt +++ b/src/myx/filesystem/CMakeLists.txt @@ -11,46 +11,36 @@ set(TRGT_hpp ${CMAKE_CURRENT_SOURCE_DIR}/paths.hpp) set(TRGT_headers ${TRGT_hpp}) # cmake-format: on -add_library(${TRGT}-header-only INTERFACE) -target_include_directories( - ${TRGT}-header-only SYSTEM INTERFACE "$" - "$") +add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) +common_target_properties(${TRGT}) -if(MYXLIB_BUILD_LIBRARIES) +# Создание цели для проверки утилитой clang-tidy +add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_headers}) - common_target_properties(${TRGT}) +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-tidy - add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clazy +add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой clang-analyze - add_clang_analyze_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) - # Создание цели для проверки утилитой clazy - add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - # Создание цели для проверки утилитой pvs-studio - add_pvs_check(${TRGT}) +target_include_directories(${TRGT} SYSTEM PUBLIC ${Qt5Core_INCLUDE_DIRS}) +target_include_directories(${TRGT} SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/src) +cotire(${TRGT}) - # Создание цели для автоматического форматирования кода - add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers}) - - target_compile_definitions(${TRGT} PUBLIC MYXLIB_BUILD_LIBRARIES) - 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() -else() - install(FILES ${TRGT_cpp} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${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 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) +install(FILES ${TRGT_headers} COMPONENT base-dev + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) # Цель, используемая только для установки заголовочных файлов без компиляции проекта add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P diff --git a/src/myx/filesystem/paths.cpp b/src/myx/filesystem/paths.cpp index d007d7f..ee76954 100644 --- a/src/myx/filesystem/paths.cpp +++ b/src/myx/filesystem/paths.cpp @@ -1,13 +1,8 @@ #ifndef MYX_BASE_PATHS_CPP_ #define MYX_BASE_PATHS_CPP_ -#ifndef MYXLIB_HEADER_ONLY -#include -#else -#pragma once -#endif - #include +#include #include diff --git a/src/myx/filesystem/paths.hpp b/src/myx/filesystem/paths.hpp index 17effe8..c565e5a 100644 --- a/src/myx/filesystem/paths.hpp +++ b/src/myx/filesystem/paths.hpp @@ -232,8 +232,4 @@ public: } // namespace myx -#ifdef MYXLIB_HEADER_ONLY -#include "paths.cpp" -#endif - #endif // MYX_FILESYSTEM_PATHS_HPP_ diff --git a/src/myx/qt/CMakeLists.txt b/src/myx/qt/CMakeLists.txt index 2582397..f2d1861 100644 --- a/src/myx/qt/CMakeLists.txt +++ b/src/myx/qt/CMakeLists.txt @@ -26,47 +26,38 @@ set(TRGT_headers ${TRGT_moc_hpp} ${TRGT_hpp}) qt5_wrap_cpp(TRGT_moc_cpp ${TRGT_moc_private_hpp} ${TRGT_moc_hpp}) -add_library(${TRGT}-header-only INTERFACE) -target_include_directories( - ${TRGT}-header-only SYSTEM INTERFACE "$" - "$" - "$") +add_common_library(${TRGT} OUTPUT_NAME myx-${TRGT} SOURCES ${TRGT_cpp} ${TRGT_moc_cpp} + ${TRGT_moc_private_hpp} ${TRGT_headers}) +common_target_properties(${TRGT}) -if(MYXLIB_BUILD_LIBRARIES) - 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-tidy - add_clang_tidy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой clang-analyze +add_clang_analyze_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}) - # Создание цели для проверки утилитой clazy - add_clazy_check(${TRGT} ${TRGT_cpp} ${TRGT_headers}) +# Создание цели для проверки утилитой pvs-studio +add_pvs_check(${TRGT}) - # Создание цели для проверки утилитой pvs-studio - add_pvs_check(${TRGT}) +# Создание цели для автоматического форматирования кода +add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers} ${TRGT_moc_private_hpp}) - # Создание цели для автоматического форматирования кода - add_format_sources(${TRGT} ${TRGT_cpp} ${TRGT_headers} ${TRGT_moc_private_hpp}) +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}) - target_compile_definitions(${TRGT} PUBLIC MYXLIB_BUILD_LIBRARIES) - 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() -else() - install(FILES ${TRGT_cpp} COMPONENT base-dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${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 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) +install(FILES ${TRGT_headers} COMPONENT base-dev + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${TRGT}) # Цель, используемая только для установки заголовочных файлов без компиляции проекта add_custom_target(${TRGT}-install-headers COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=base-dev -P diff --git a/src/myx/qt/posix_signal_watcher.cpp b/src/myx/qt/posix_signal_watcher.cpp index 5688572..2ff13f8 100644 --- a/src/myx/qt/posix_signal_watcher.cpp +++ b/src/myx/qt/posix_signal_watcher.cpp @@ -3,19 +3,14 @@ #include -#ifndef MYXLIB_HEADER_ONLY -#include #include -#else -#pragma once -#endif - +#include namespace myx { namespace qt { -int PosixSignalWatcherPrivate::m_sockpair[2] = {0, 0}; +std::array< int, 2 > PosixSignalWatcherPrivate::mSockpair = { 0, 0 }; PosixSignalWatcherPrivate::~PosixSignalWatcherPrivate() = default; @@ -24,7 +19,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : { #if MYX_QT_HAS_POSIX_SIGNALS // Create socket pair - if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, m_sockpair ) ) + if ( ::socketpair( AF_UNIX, SOCK_STREAM, 0, mSockpair.data() ) != 0 ) { qDebug() << "PosixSignalWatcher: socketpair: " << ::strerror( errno ); return; @@ -32,7 +27,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : #endif // Create a notifier for the read end of the pair - m_notifier.reset( new QSocketNotifier( m_sockpair[1], QSocketNotifier::Read ) ); + m_notifier.reset( new QSocketNotifier( mSockpair[1], QSocketNotifier::Read ) ); // Called when the signal handler has written to the socket pair. @@ -57,7 +52,7 @@ PosixSignalWatcherPrivate::PosixSignalWatcherPrivate( PosixSignalWatcher* q ) : * This provides a way to break out of the asynchronous context from which the * signal handler is called and back into the Qt event loop. */ -void PosixSignalWatcherPrivate::watchForSignal( int signal ) +MYXLIB_INLINE void PosixSignalWatcherPrivate::watchForSignal( int signal ) { if ( m_watchedSignals.contains( signal ) ) { @@ -67,12 +62,12 @@ void PosixSignalWatcherPrivate::watchForSignal( int signal ) #if MYX_QT_HAS_POSIX_SIGNALS // Register a sigaction which will write to the socket pair - struct sigaction sigact; + struct sigaction sigact {}; sigact.sa_handler = PosixSignalWatcherPrivate::signalHandler; sigact.sa_flags = 0; sigemptyset( &sigact.sa_mask ); sigact.sa_flags |= SA_RESTART; - if ( ::sigaction( signal, &sigact, nullptr ) ) + if ( ::sigaction( signal, &sigact, nullptr ) != 0 ) { qDebug() << "PosixSignalWatcher: sigaction: " << ::strerror( errno ); return; @@ -89,7 +84,7 @@ void PosixSignalWatcherPrivate::watchForSignal( int signal ) */ MYXLIB_INLINE void PosixSignalWatcherPrivate::signalHandler( int signal ) { - (void)::write( m_sockpair[0], &signal, sizeof( signal ) ); + (void)::write( mSockpair[0], &signal, sizeof( signal ) ); } diff --git a/src/myx/qt/posix_signal_watcher.hpp b/src/myx/qt/posix_signal_watcher.hpp index 511bca5..b4aaf6b 100644 --- a/src/myx/qt/posix_signal_watcher.hpp +++ b/src/myx/qt/posix_signal_watcher.hpp @@ -33,7 +33,7 @@ class PosixSignalWatcher : public QObject public: explicit PosixSignalWatcher( QObject* parent = nullptr ); - ~PosixSignalWatcher(); + ~PosixSignalWatcher() override; void watchForSignal( int signal ); Q_SIGNAL void posixSignal( int signal ); @@ -47,9 +47,4 @@ private: } // namespace myx -#ifdef MYXLIB_HEADER_ONLY -#include "posix_signal_watcher_p.hpp" -#include "posix_signal_watcher.cpp" -#endif - #endif // ifndef MYX_QT_POSIX_SIGNAL_WATCHER_HPP_ diff --git a/src/myx/qt/posix_signal_watcher_p.hpp b/src/myx/qt/posix_signal_watcher_p.hpp index 067f94c..9564737 100644 --- a/src/myx/qt/posix_signal_watcher_p.hpp +++ b/src/myx/qt/posix_signal_watcher_p.hpp @@ -1,8 +1,9 @@ #ifndef MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_ #define MYX_QT_POSIX_SIGNAL_WATCHER_P_HPP_ -#include +#pragma once +#include #include #include @@ -47,10 +48,10 @@ public: static void signalHandler( int signal ); private: - PosixSignalWatcher* const q_ptr = nullptr; Q_DECLARE_PUBLIC( PosixSignalWatcher ) - static int m_sockpair[2]; + PosixSignalWatcher* const q_ptr = nullptr; + static std::array< int, 2 > mSockpair; std::unique_ptr< QSocketNotifier > m_notifier; QList< int > m_watchedSignals; }; // class PosixSignalWatcherPrivate diff --git a/src/myx/qt/translators.cpp b/src/myx/qt/translators.cpp index 67e97ef..86b4b9c 100644 --- a/src/myx/qt/translators.cpp +++ b/src/myx/qt/translators.cpp @@ -2,12 +2,7 @@ #define MYX_QT_TRANSLATORS_CPP_ #include - -#ifndef MYXLIB_HEADER_ONLY #include -#else -#pragma once -#endif #include #include diff --git a/src/myx/qt/translators.hpp b/src/myx/qt/translators.hpp index a1515c5..ae24a51 100644 --- a/src/myx/qt/translators.hpp +++ b/src/myx/qt/translators.hpp @@ -20,8 +20,4 @@ void append_translators( QTranslatorsList& translators, const QString& appName ) } // namespace myx -#ifdef MYXLIB_HEADER_ONLY -#include "translators.cpp" -#endif - #endif // ifndef MYX_QT_TRANSLATORS_HPP_