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 not suggested to be included as a subproject.
- Helpful CMake utilities
- Generate configuration header files
- Reorganize header files
- Deploy project dependencies and fix rpaths
- Support calling Doxygen via CMake conveniently
- Support calling Qt Linguist Tools via CMake conveniently
- Microsoft Windows
- Apple Macintosh
- GNU/Linux
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 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
- C++ 17
- CMake 3.19
Via Https
git clone --recursive https://github.com/stdware/qmsetup.git
Via SSH
git clone --recursive git@github.com:stdware/qmsetup.git
cmake -B build -DCMAKE_INSTALL_PREFIX=/path/to
cmake -B build --target all
cmake -B build --target install
cmake -Dqmsetup_DIR=/path/to/lib/cmake/qmsetup ...
find_package(qmsetup REQUIRED)
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/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()
Here are some common use cases of CMake project, you can simplify many operations when using this library.
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)
qm_import(Preprocess)
qm_sync_include(src/core ${CMAKE_BINARY_DIR}/include/MyCore
INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/MyCore
)
qm_import(Filesystem)
qm_add_copy_command(${PROJECT_NAME}
SOURCES
file.txt
dir_to_copy
dir_contents_to_copy/
DESTINATION .
)
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
)
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
)
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"
)
The CMake Modules documentations is provided in the form of comment.
See examples
to get detailed use cases.
QMSetup is licensed under the MIT License.