QMSetup is a set of CMake Modules and Basic Libraries for C/C++ projects.
This project is independent from Qt and other 3rdparty libraries. It ships tools that have to be compiled and then run on the build machine, so adding it with add_subdirectory is strongly discouraged. Install it first, or let your project install it during configure, as described under Integrate.
- Path, Version functions
- Target configuration functions
- Qt related functions
- Generate Windows RC files, manifest files
- Generate macOS bundle info files
- Generate configuration header files
- Generate Git information header files
- Reorganize header files
- Copy files and directories after build
- Deploy project dependencies and fix rpaths
- Create translations with Qt Linguist tools
- Create source files with Protobuf compiler
- Create documentation with Doxygen
- Microsoft Windows
- Apple macOS
- GNU/Linux
The deploy command reads the import table out of the PE file itself and looks for each name along the paths it was given, so nothing has to be installed and dumpbin is not needed.
The deploy command reads what a binary asks for with patchelf, works out where each of those resolves to with ldd, and fixes the rpaths with patchelf again. ldd comes with the C library, so patchelf is the one to install.
sudo apt install patchelfThe deploy command reads dependencies with otool, fixes install names and rpaths with install_name_tool, and thins a universal binary with lipo. All three come with the Xcode command line tools, so there is nothing to install.
- C++ 17
- CMake 3.19
Via Https
git clone --recursive https://github.com/stdware/qmsetup.gitVia SSH
git clone --recursive git@github.com:stdware/qmsetup.gitcmake -B build -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/path/to
cmake --build build --config Release
cmake --install build --config Releasecmake -Dqmsetup_DIR=/path/to/lib/cmake/qmsetup ...find_package(qmsetupREQUIRED)It still needs to be installed, but the installation occurs during the CMake Configure phase and is executed only once.
# `qmsetup` provides tools that run on the build machine, so it must always be# searched for there. Cross compiling toolchains that set# `CMAKE_FIND_ROOT_PATH_MODE_PACKAGE` to `ONLY` would otherwise redirect the lookups# below into the target sysroot, where the package was never installed.find_package(qmsetupQUIETNO_CMAKE_FIND_ROOT_PATH)
if (NOTTARGET qmsetup::library)
# Modify this variable according to your project structureset(_source_dir ${CMAKE_CURRENT_SOURCE_DIR}/qmsetup)
# Import install functioninclude("${_source_dir}/cmake/modules/private/InstallPackage.cmake")
# Install package in placeset(_package_path)
qm_install_package(qmsetupHOSTSOURCE_DIR${_source_dir}BUILD_TYPEReleaseRESULT_PATH_package_path
)
# Find package again, still on the build machine (see the note above)find_package(qmsetupREQUIREDPATHS${_package_path}NO_DEFAULT_PATHNO_CMAKE_FIND_ROOT_PATH
)
# Update import pathset(qmsetup_DIR ${_package_path}CACHEPATH""FORCE)
endif()You can use the functions in this library to greatly simplify several kinds of common build rules.
qm_import(Preprocess)
qm_add_definition(FOOfalse)
qm_add_definition(BAR114514)
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/MyCoreINSTALL_DIR${CMAKE_INSTALL_INCLUDEDIR}/MyCore
)qm_import(Filesystem)
qm_add_copy_command(${PROJECT_NAME}SOURCESfile.txtdir_to_copydir_contents_to_copy/DESTINATION.
)qm_import(Deploy)
qm_deploy_directory("${CMAKE_INSTALL_PREFIX}"COMMENT"Deploy project spectacularly"PLUGINS"iconengines/qsvgicon""bearer/qgenericbearer"QMLQtQtQmlPLUGIN_DIRshare/pluginsQML_DIRshare/qml
)qm_import(QtLinguist)
qm_find_qt(LinguistTools)
qm_add_translation(${PROJECT_NAME}_translationsLOCALESja_JPzh_CNzh_TWPREFIX${PROJECT_NAME}TARGETS${PROJECT_NAME}TS_DIR${CMAKE_CURRENT_SOURCE_DIR}/translationsQM_DIR${CMAKE_CURRENT_BINARY_DIR}/translations
)qm_import(Protobuf)
find_package(ProtobufCONFIGREQUIRED)
qm_create_protobuf(_proto_srcINPUTa.protob.protoINCLUDE_DIRECTORIESsrc/protoOUTPUT_DIR${CMAKE_CURRENT_BINARY_DIR}/proto
)
target_sources(${PROJECT_NAME}PUBLIC${_proto_src})qm_import(Doxygen)
find_package(DoxygenREQUIRED)
qm_setup_doxygen(${PROJECT_NAME}_RunDoxygenNAME${PROJECT_NAME}DESCRIPTION"my project"MDFILE"${CMAKE_SOURCE_DIR}/README.md"OUTPUT_DIR"${CMAKE_BINARY_DIR}/doc"INPUTsrcTARGETS${PROJECT_NAME}DEPENDS${PROJECT_NAME}NO_EXPAND_MACROSQ_OBJECTQ_GADGETQ_DECLARE_TR_FUNCTIONSCOMPILE_DEFINITIONSQ_SIGNALS=Q_SIGNALSQ_SLOTS=Q_SLOTSGENERATE_TAGFILE"${PROJECT_NAME}_tagfile.xml"INSTALL_DIR"doc"
)Use qm_find_package to find supported third-party packages.
- YY-Thunks: https://github.com/Chuyu-Team/YY-Thunks
- VC-LTL5: https://github.com/Chuyu-Team/VC-LTL5
The CMake modules are documented in the comments above each function.
QMSetup is licensed under the MIT License.