Giter Club home page Giter Club logo

qmsetup's Introduction

QMSetup

QMSetup is a set of CMake Modules and Basic Libraries for C/C++ projects.

This project is independent from Qt and other 3rdparty libraries. Due to the fact that it encompasses some tools that need to be compiled, it's strongly not suggested to be included as a subproject.

Features

Helpful Functions

  • Path, Version functions
  • Target configuration functions
  • Qt related functions

Generators

  • Generate Windows RC files, manifest files
  • Generate MacOS Bundle info files
  • Generate configuration header files
  • Generate Git information header files

Filesystem Utilities

  • Reorganize header files
  • Copy files and directories after build

Install Utilities

  • Deploy project dependencies and fix rpaths

Extended Build Rules

  • Create translations with Qt Linguist tools
  • Create source files with Protobuf compiler
  • Create documentations with Doxygen

Support Platforms

  • Microsoft Windows
  • Apple Macintosh
  • GNU/Linux

Dependencies

Required Packages

Windows

Windows deploy command acquires the shared library paths by reading the PE files and searching the specified paths so that it doesn't depend on dumpbin tool.

Unix

Unix deploy command acquires the shared library paths by running ldd/otool command and fixes the rpaths by runing the patchelf/install_name_tool command, make sure you have installed them.

sudo apt install patchelf

Build System

  • C++ 17
  • CMake 3.19

Open-Source Libraries

Integrate

Clone

Via Https

git clone --recursive https://github.com/stdware/qmsetup.git

Via SSH

git clone --recursive [email protected]:stdware/qmsetup.git

Preinstall (Suggested)

Build & Install

cmake -B build -DCMAKE_BUILD_TYPE=Release \
               -DCMAKE_INSTALL_PREFIX=/path/to
cmake -B build --target all
cmake -B build --target install

Import

cmake -Dqmsetup_DIR=/path/to/lib/cmake/qmsetup ...
find_package(qmsetup REQUIRED)

Sub-project

It still needs to be installed, but the installation occurs during the CMake Configure phase and is executed only once.

find_package(qmsetup QUIET)

if (NOT TARGET qmsetup::library)
    # Modify this variable according to your project structure
    set(_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/qmsetup)

    # Import install function
    include("${_source_dir}/cmake/modules/private/InstallPackage.cmake")

    # Install package in place
    set(_package_path)
    qm_install_package(qmsetup
        SOURCE_DIR ${_source_dir}
        BUILD_TYPE Release
        RESULT_PATH _package_path
    )

    # Find package again
    find_package(qmsetup REQUIRED PATHS ${_package_path})

    # Update import path
    set(qmsetup_DIR ${_package_path} CACHE PATH "" FORCE)
endif()

Quick Start

Examples

You can use the functions in this library to greatly simplify several kinds of common build rules.

Generate Configuration Header

qm_import(Preprocess)

qm_add_definition(FOO false)
qm_add_definition(BAR 114514)
qm_add_definition(BAZ "ABC" STRING_LITERAL)

qm_generate_config(${CMAKE_BINARY_DIR}/conf.h)

Reorganize Include Directory

qm_import(Preprocess)

qm_sync_include(src/core ${CMAKE_BINARY_DIR}/include/MyCore
    INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/MyCore
)

Sync Resource Files After Build

qm_import(Filesystem)

qm_add_copy_command(${PROJECT_NAME}
    SOURCES
        file.txt
        dir_to_copy
        dir_contents_to_copy/
    DESTINATION .
)

Deploy Project And All Dependencies

qm_import(Deploy)

qm_deploy_directory("${CMAKE_INSTALL_PREFIX}"
    COMMENT "Deploy project spectacularly"
    PLUGINS "iconengines/qsvgicon" "bearer/qgenericbearer"
    QML Qt QtQml
    PLUGIN_DIR share/plugins
    QML_DIR share/qml
)

Add Qt Translations

qm_import(Translate)

qm_find_qt(LinguistTools)
qm_add_translation(${PROJECT_NAME}_translations
    LOCALES ja_JP zh_CN zh_TW
    PREFIX ${PROJECT_NAME}
    TARGETS ${PROJECT_NAME}
    TS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/translations
    QM_DIR ${CMAKE_CURRENT_BINARY_DIR}/translations
)

Generate Protubuf Source Files

qm_import(Protobuf)

find_package(Protobuf REQUIRED)
qm_create_protobuf(_proto_src
    INPUT a.proto b.proto
    INCLUDE_DIRECTORIES src/proto
    OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto
)
target_sources(${PROJECT_NAME} PUBLIC ${_proto_src})

Generate Doxygen HTML Documentations

qm_import(Doxygen)

find_package(Doxygen REQUIRED)
qm_setup_doxygen(${PROJECT_NAME}_RunDoxygen
    NAME ${PROJECT_NAME}
    DESCRIPTION "my project"
    MDFILE "${CMAKE_SOURCE_DIR}/README.md"
    OUTPUT_DIR "${CMAK_BINARY_DIR}/doc"
    INPUT src
    TARGETS ${PROJECT_NAME}
    DEPENDS ${PROJECT_NAME}
    NO_EXPAND_MACROS
        Q_OBJECT
        Q_GADGET
        Q_DECLARE_TR_FUNCTIONS
    COMPILE_DEFINITIONS 
        Q_SIGNALS=Q_SIGNALS
        Q_SLOTS=Q_SLOTS
    GENERATE_TAGFILE "${PROJECT_NAME}_tagfile.xml"
    INSTALL_DIR "doc"
)

Find Modules

Use qm_find_package to find supported third-party packages.

Detailed Documentations

The CMake Modules documentations is provided in the comments.

See examples to get detailed use cases.

Contributors

License

QMSetup is licensed under the MIT License.

qmsetup's People

Contributors

crsjimo avatar sinestriker avatar wangwenx190 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

qmsetup's Issues

qm_add_win_rc don't support char ,

When a string uses a comma character, the data after the comma is discarded

In file WinResource.rc.in

BLOCK "040904E4"
       {
          VALUE "FileDescription", STRINGIFY(@RC_DESCRIPTION@)
          VALUE "FileVersion", STRINGIFY(@RC_VERSION_STRING@)
          VALUE "ProductName", STRINGIFY(@RC_APPLICATION_NAME@)
          VALUE "ProductVersion", STRINGIFY(@RC_VERSION_STRING@)
          VALUE "LegalCopyright", STRINGIFY(@RC_COPYRIGHT@)
        }

STRINGIFY changing to double quotes will solve the problem

execute_process fails

im building qwindowkit in github actions on ubuntu-latest with gcc and ninja (cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++)

however this part keeps erroring

execute_process(
COMMAND ${CMAKE_COMMAND} -S ${_src_dir} -B ${_build_dir}
${_generator} ${_build_type}
"-DCMAKE_INSTALL_PREFIX=${_install_dir}" ${FUNC_CONFIGURE_ARGS}
OUTPUT_FILE ${_log_file}
ERROR_FILE ${_log_file}
RESULT_VARIABLE _code
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

CMake Error at DummyProject/ThirdParty/qwindowkit/qmsetup/cmake/modules/InstallPackage.cmake:108 (message):
  Configure failed, check
  "/home/runner/work/DummyProject/DummyProject/build/_build/qmsetup_configure.log"

qmsetup_configure.log:

Run cat /home/runner/work/DummyProject/DummyProject/build/_build/qmsetup_configure.log
CMake Error: CMake was unable to find a build program corresponding to "Ninja".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

so i went back and added some logging just before

execute_process(COMMAND ninja --version)
message("${CMAKE_COMMAND} -S ${_src_dir} -B ${_build_dir} ${_generator} ${_build_type}")

which yields

1.11.1
/usr/local/bin/cmake -S /home/runner/work/DummyProject/DummyProject/ThirdParty/qwindowkit/qmsetup -B /home/runner/work/DummyProject/DummyProject/build/_build/qmsetup -G Ninja -DCMAKE_BUILD_TYPE=Release

the full command cmake runs is:

execute_process(COMMAND /usr/local/bin/cmake -S /home/runner/work/DummyProject/DummyProject/ThirdParty/qwindowkit/qmsetup -B /home/runner/work/DummyProject/DummyProject/build/_build/qmsetup -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/runner/work/DummyProject/DummyProject/build/_install  OUTPUT_FILE /home/runner/work/DummyProject/DummyProject/build/_build/qmsetup_configure.log ERROR_FILE /home/runner/work/DummyProject/DummyProject/build/_build/qmsetup_configure.log RESULT_VARIABLE _code WORKING_DIRECTORY /home/runner/work/DummyProject/DummyProject/ThirdParty/qwindowkit )

so both ninja is found in PATH, and the command run is perfectly fine. how is this possible?
like i said, this happens only in CI, not locally

In qm_add_translation, the .ts file is not updated automatically

In file Translate.cmake, line 275

        add_custom_command(
            TARGET ${_target}
            COMMAND ${_lupdate_exe}
            ARGS ${_LUPDATE_OPTIONS} "@${_ts_lst_file}" -ts ${_ts_file}
            WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
            DEPENDS ${_my_sources}
            BYPRODUCTS ${_ts_lst_file}
            VERBATIM
        )

This code doesn't work, unable to update the ts file.
add_custom_command instructions are executed in the build phase, which is not very friendly to development, can it be generated in the cmake phase.
Or control whether an update is required through a variable.Because this step may be time -consuming.

Tagged releases

Hello there,

Please consider tagging releases so that various GNU/Linux distributions could package qmsetup for use by other projects that depend on it.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.