From afbd1b6025078071692c448dca75e7c734024306 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Fri, 2 Sep 2022 11:29:56 -0400 Subject: [PATCH 1/2] Use OBCMake --- CMakeLists.txt | 16 ++-- cmake/module/QI-QMP/BetterFindQt6.cmake | 39 --------- cmake/module/QI-QMP/FetchOBCMake.cmake | 13 +++ cmake/module/QI-QMP/FetchQx.cmake | 13 --- cmake/module/QI-QMP/QtDocsHelper.cmake | 46 ---------- cmake/module/QI-QMP/Utility.cmake | 24 ------ cmake/module/QI-QMP/VerboseVersioning.cmake | 96 --------------------- 7 files changed, 24 insertions(+), 223 deletions(-) delete mode 100644 cmake/module/QI-QMP/BetterFindQt6.cmake create mode 100644 cmake/module/QI-QMP/FetchOBCMake.cmake delete mode 100644 cmake/module/QI-QMP/FetchQx.cmake delete mode 100644 cmake/module/QI-QMP/QtDocsHelper.cmake delete mode 100644 cmake/module/QI-QMP/Utility.cmake delete mode 100644 cmake/module/QI-QMP/VerboseVersioning.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 50d548f..1561acb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,7 +34,13 @@ set(CMAKE_AUTOMOC ON) # Add local modules set(PROJ_SCRIPTS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${PROJ_SCRIPTS_PATH}/module") -include(QI-QMP/Utility) + +# Get helper scripts +include(QI-QMP/FetchOBCMake) +fetch_ob_cmake("v0.1") + +# Include utility functions +include(OB/Utility) # General Variables if(CMAKE_SIZEOF_VOID_P EQUAL 8) @@ -87,7 +93,7 @@ set(PACKAGE_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/out/dist") #------------Set Global Build Rules---------------- # Versioning -include(QI-QMP/VerboseVersioning) +include(OB/VerboseVersioning) setup_verbose_versioning(PROJECT_VERSION_VERBOSE) #================= Build ========================= @@ -102,11 +108,11 @@ set(QT_FIND_COMPONENTS add_compile_definitions(QT_DISABLE_DEPRECATED_BEFORE=0x060000) # Find Qt package -include(QI-QMP/BetterFindQt6) +include(OB/BetterFindQt6) find_qt6_package(REQUIRED COMPONENTS ${QT_FIND_COMPONENTS}) # Fetch Qx (build and import from source) -include(QI-QMP/FetchQx) +include(OB/FetchQx) fetch_qx("v0.3.1") # Set lib sources @@ -217,7 +223,7 @@ if(QI_QMP_DOCS_TARGET) ) # Determine Qt related doc paths - include(QI-QMP/QtDocsHelper) + include(OB/QtDocsHelper) configure_qt_doc_link(${Qt6_PREFIX_PATH}) # Set Doxygen parameters diff --git a/cmake/module/QI-QMP/BetterFindQt6.cmake b/cmake/module/QI-QMP/BetterFindQt6.cmake deleted file mode 100644 index 60ab9b0..0000000 --- a/cmake/module/QI-QMP/BetterFindQt6.cmake +++ /dev/null @@ -1,39 +0,0 @@ -macro(find_qt6_package) - # Find Qt normally - find_package(Qt6 ${ARGN}) - - # Determine install prefix - if(PACKAGE_PREFIX_DIR) # Defined by Qt6Config.cmake - set(Qt6_PREFIX_PATH ${PACKAGE_PREFIX_DIR}) - else() - # Determine based on config script path - cmake_path(REMOVE_FILENAME ${Qt6_CONFIG} - OUTPUT_VARIABLE __QT_CONFIG_PATH - ) - cmake_path(ABSOLUTE_PATH "${__QT_CONFIG_PATH}/../../../" - NORMALIZE - OUTPUT_VARIABLE Qt6_PREFIX_PATH - ) - endif() - - # Ensure install prefix is valid - if(CMAKE_SYSTEM_NAME STREQUAL Windows) - set(__QMAKE_NAME "qmake.exe") - elseif(CMAKE_SYSTEM_NAME STREQUAL Linux) - set(__QMAKE_NAME "qmake") - endif() - - if(NOT EXISTS "${Qt6_PREFIX_PATH}/bin/${__QMAKE_NAME}") - message(FATAL_ERROR "Qt6_PREFIX_PATH could not be determined!") - endif() - - # Determine Linkage - get_target_property(__QT_CORE_TARGET_TYPE Qt6::Core TYPE) - if(__QT_CORE_TARGET_TYPE STREQUAL SHARED_LIBRARY) - set(Qt6_LINKAGE shared) - elseif(__QT_CORE_TARGET_TYPE STREQUAL STATIC_LIBRARY) - set(Qt6_LINKAGE static) - else() - message(FATAL_ERROR "Qt6 Core target type has an unexpected value!") - endif() -endmacro() diff --git a/cmake/module/QI-QMP/FetchOBCMake.cmake b/cmake/module/QI-QMP/FetchOBCMake.cmake new file mode 100644 index 0000000..1c8413d --- /dev/null +++ b/cmake/module/QI-QMP/FetchOBCMake.cmake @@ -0,0 +1,13 @@ +# Sets up OBCMake to be imported via git + +# git_ref - Tag, branch name, or commit hash to retrieve. According to CMake docs, +# a commit hash is preferred for speed and reliability + +macro(fetch_ob_cmake git_ref) + include(FetchContent) + FetchContent_Declare(OBCMake + GIT_REPOSITORY "https://github.com/oblivioncth/OBCMake" + GIT_TAG ${git_ref} + ) + FetchContent_MakeAvailable(OBCMake) +endmacro() diff --git a/cmake/module/QI-QMP/FetchQx.cmake b/cmake/module/QI-QMP/FetchQx.cmake deleted file mode 100644 index e9187c2..0000000 --- a/cmake/module/QI-QMP/FetchQx.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# Sets up Qx to be built/installed as an external project for use in the main project - -# git_ref - Tag, branch name, or commit hash to retrieve. According to CMake docs, -# a commit hash is preferred for speed and reliability - -function(fetch_qx git_ref) - include(FetchContent) - FetchContent_Declare(Qx - GIT_REPOSITORY "https://github.com/oblivioncth/Qx" - GIT_TAG ${git_ref} - ) - FetchContent_MakeAvailable(Qx) -endfunction() diff --git a/cmake/module/QI-QMP/QtDocsHelper.cmake b/cmake/module/QI-QMP/QtDocsHelper.cmake deleted file mode 100644 index f757061..0000000 --- a/cmake/module/QI-QMP/QtDocsHelper.cmake +++ /dev/null @@ -1,46 +0,0 @@ -function(configure_qt_doc_link qt_prefix) - # Handle using cache so that users can easily override via UI or command-line - - # Could use crazy amounts of file system searching to check for every Qt root under the standard Qt install - # location for each platform (i.e. C:/Program Files/Qt/6.3.0/msvc2019/) and then add those as PATHS to the - # below commands, but for now, lets not - - # Locate qhelpgenerator - find_file(QT_HELP_GEN_PATH - NAMES - "qhelpgenerator" - "qhelpgenerator.exe" - HINTS - "${qt_prefix}" - PATH_SUFFIXES - "bin" - "libexec" - DOC "Path to the qhelpgenerator executable" - NO_DEFAULT_PATH - ) - - if(QT_HELP_GEN_PATH) - message(STATUS "qhelpgenerator found at: ${QT_HELP_GEN_PATH}") - else() - message(WARNING "Could not find qhelpgenerator. Please set QT_HELP_GEN_PATH to its location if you want to generate a .qch file for documentation.") - endif() - - # Locate Qt documentation - find_path(QT_DOCS_DIR - NAMES - "qtcore.qch" - "qtcore" - HINTS - "${qt_prefix}/doc" - PATHS - "C:/Program Files/Qt/Docs/Qt-${Qt6_VERSION}" - DOC "Path to Qt documentation" - NO_DEFAULT_PATH - ) - - if(QT_DOCS_DIR) - message(STATUS "Qt documentation found at: ${QT_DOCS_DIR}") - else() - message(WARNING "Could not find documentation for the in-use Qt version. Please set QT_DOCS_DIR to its location if you want the generated documentation to reference Qt.") - endif() -endfunction() diff --git a/cmake/module/QI-QMP/Utility.cmake b/cmake/module/QI-QMP/Utility.cmake deleted file mode 100644 index 9b10e52..0000000 --- a/cmake/module/QI-QMP/Utility.cmake +++ /dev/null @@ -1,24 +0,0 @@ -function(get_proper_system_name return) - if(CMAKE_SYSTEM_NAME STREQUAL Windows) - set(${return} Windows PARENT_SCOPE) - elseif(CMAKE_SYSTEM_NAME STREQUAL Linux) - # Get distro name - execute_process( - COMMAND sh -c "( awk -F= '\$1==\"NAME\" { print \$2 ;}' /etc/os-release || lsb_release -is ) 2>/dev/null" - ERROR_QUIET - RESULT_VARIABLE res - OUTPUT_VARIABLE distro_name - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # Handle cleanup and fallback - if(("${distro_name}" STREQUAL "")) - message(WARNING "Could not determine distro name. Falling back to 'Linux'") - set(distro_name "Linux") - else() - string(REPLACE "\"" "" distro_name ${distro_name}) # Remove possible quotation - endif() - - set(${return} "${distro_name}" PARENT_SCOPE) - endif() -endfunction() diff --git a/cmake/module/QI-QMP/VerboseVersioning.cmake b/cmake/module/QI-QMP/VerboseVersioning.cmake deleted file mode 100644 index 7ca0b20..0000000 --- a/cmake/module/QI-QMP/VerboseVersioning.cmake +++ /dev/null @@ -1,96 +0,0 @@ -### verbose_versioning.cmake ### - -# Include this script as part of a CMakeList.txt used for configuration -# and call the function "setup_verbose_versioning" to get the project's git-based -# verbose version and setup the build scripts to reconfigure if the verbose version is out -# of date. - -# Version acquisition function -function(__get_verbose_version repo fallback return) - find_package(Git) - - if(Git_FOUND) - # Describe repo - execute_process( - COMMAND "${GIT_EXECUTABLE}" describe --tags --match v*.* --dirty --always - WORKING_DIRECTORY "${repo}" - COMMAND_ERROR_IS_FATAL ANY - RESULT_VARIABLE res - OUTPUT_VARIABLE GIT_DESC - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - # Command result - if(NOT ("${GIT_DESC}" STREQUAL "")) - set(${return} "${GIT_DESC}" PARENT_SCOPE) - else() - message(FATAL_ERROR "Git returned a null description!") - endif() - - elseif(NOT (${fallback} STREQUAL "")) - set(${return} "${fallback}" PARENT_SCOPE) - else() - message(FATAL_ERROR "Git could not be found! You can define NO_GIT to acknowledge building without verbose versioning.") - endif() -endfunction() - -# Build script usage -if(CMAKE_SCRIPT_MODE_FILE) - # Get cached verbose version from disk - if(EXISTS "${VERBOSE_VER_CACHE}") - file(READ ${VERBOSE_VER_CACHE} CACHED_VERBOSE_VER) - else() - set(CACHED_VERBOSE_VER "") - endif() - - # Get fresh verbose version - __get_verbose_version("${GIT_REPO}" "${VERSION_FALLBACK}" VERBOSE_VER) - - # Compare values, and update if necessary - if(NOT ("${CACHED_VERBOSE_VER}" STREQUAL "${VERBOSE_VER}")) - message(STATUS "Verbose version is out of date") - # This will update verbose_ver.txt, causing cmake to reconfigure - file(WRITE ${VERBOSE_VER_CACHE} ${VERBOSE_VER}) - endif() -# Configure usage (make function available) -else() - function(setup_verbose_versioning return) - # Handle fallback value - if(NO_GIT) - set(VERSION_FALLBACK "v${PROJECT_VERSION}") - else() - set(VERSION_FALLBACK "") - endif() - - # Get verbose version - __get_verbose_version("${CMAKE_CURRENT_SOURCE_DIR}" "${VERSION_FALLBACK}" VERBOSE_VER) - - # Write to "cache" file - set(VERBOSE_VER_CACHE ${CMAKE_CURRENT_BINARY_DIR}/verbose_ver.txt) - file(WRITE ${VERBOSE_VER_CACHE} ${VERBOSE_VER}) - - # Add custom target to allow for build time re-check (byproduct important!) - add_custom_target( - ${PROJECT_NAME}_verbose_ver_check - BYPRODUCTS - ${VERBOSE_VER_CACHE} - COMMAND - ${CMAKE_COMMAND} - "-DVERBOSE_VER_CACHE=${VERBOSE_VER_CACHE}" - "-DGIT_REPO=${CMAKE_CURRENT_SOURCE_DIR}" - "-DVERSION_FALLBACK=${VERSION_FALLBACK}" - "-P" "${CMAKE_CURRENT_FUNCTION_LIST_FILE}" - COMMENT - "Re-checking verbose version..." - VERBATIM - USES_TERMINAL - ) - - # This configure_file makes cmake reconfigure dependent on verbose_ver.txt - configure_file(${VERBOSE_VER_CACHE} ${VERBOSE_VER_CACHE}.old COPYONLY) - - message(STATUS "Verbose Version: ${VERBOSE_VER}") - set(${return} "${VERBOSE_VER}" PARENT_SCOPE) - endfunction() -endif() - From 0e60675151545d36f60da29b06d2ad7a225e7e64 Mon Sep 17 00:00:00 2001 From: Christian Heimlich Date: Sat, 3 Sep 2022 10:33:09 -0400 Subject: [PATCH 2/2] Minor doc fixes --- CMakeLists.txt | 2 +- README.md | 2 +- src/qmpi.cpp | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1561acb..b3e9503 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ option(QI_QMP_DOCS_TARGET "Build QI-QMP documentation" OFF) # Project # NOTE: DON'T USE TRAILING ZEROS IN VERSIONS -set(QI_QMP_BASE_VERSION 0.1.2) # Required for CI/CD +set(QI_QMP_BASE_VERSION 0.1.2.1) # Required for CI/CD project(QI-QMP VERSION ${QI_QMP_BASE_VERSION} LANGUAGES CXX diff --git a/README.md b/README.md index 0bcb757..2a3710b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # QI-QMP -QI-QMP is a minuscule C++ library, which utilizes Qt, that provides an interface to QEMU instances via the QEMU Machine Protocol. In other words, this library implements the client side of QMP for C++. +QI-QMP is a minuscule C++/Qt library that provides an interface to QEMU instances via the QEMU Machine Protocol. In other words, this library implements the client side of QMP for C++. It presents as a QObject derived class, `Qmpi`, that is operated via member functions and connecting to its signals. diff --git a/src/qmpi.cpp b/src/qmpi.cpp index 8e7022a..1980f56 100644 --- a/src/qmpi.cpp +++ b/src/qmpi.cpp @@ -531,18 +531,18 @@ void Qmpi::setTransactionTimeout(int timeout) { mTransactionTimer.setInterval(ti int Qmpi::transactionTimeout() const { return mTransactionTimer.interval(); } /*! - * Attempts to make a connection to the QEMU instance specified by IP address and port + * Attempts to make a connection to the QEMU instance specified by address and port * during the interface's construction. * * The interface's state immediately changes to @ref Connecting, followed by * @ref AwaitingWelcome if the underlying socket successfully establishes a connection. - * Once the interface has received the server's welcome message connected() is emitted + * Once the interface has received the server's welcome message, connected() is emitted * and Qmpi enters the @ref Negotiating state. At this point capabilities negotiation is * handled automatically since only the base protocol capabilities are currently supported, * upon which readyForCommands() is emitted and the interface enters the @ref Idle state. * * At any point, the interface can emit connectionErrorOccurred() or communicationErrorOccurred() - * signal an error occurred. + * to signal an error occurred. * * @sa state(), and disconnectFromHost(). */ @@ -722,7 +722,7 @@ void Qmpi::handleTransactionTimeout() { raiseCommunicationError(CommunicationErr * @fn void Qmpi::readyForCommands() * * This signal is emitted once capabilities negotiation has been completed and the server is ready to - * received commands. + * receive commands. * * @sa connected(). */ @@ -755,12 +755,12 @@ void Qmpi::handleTransactionTimeout() { raiseCommunicationError(CommunicationErr /*! * @fn void Qmpi::responseReceived(QJsonValue value, std::any context) * - * This signal is emitted when the a successful (i.e. `return`) response is received from the server + * This signal is emitted when a success (i.e. `return`) response is received from the server * after executing a command. * - * @a value contains the return value of the command, which may be an empty QJsonObject if the command + * @a value contains the return value of the command, which will be an empty QJsonObject if the command * does not return data, while @a context contains the context object provided when the command was - * executed, if it was set. + * executed, if set. * * @sa errorResponseReceived(). */ @@ -807,7 +807,7 @@ void Qmpi::handleTransactionTimeout() { raiseCommunicationError(CommunicationErr * * @a errorClass contains the type of error and @a description contains a human readable * summary of the error, while @a context contains the context object provided when the - * command was executed, if it was set. + * command was executed, if set. * * @sa responseReceived(). */