deskflow/CMakeLists.txt

258 lines
7.9 KiB
CMake
Raw Normal View History

# SPDX-FileCopyrightText: (C) 2024 - 2026 Deskflow Developers
# SPDX-FileCopyrightText: (C) 2012 - 2024 Symless Ltd
# SPDX-FileCopyrightText: (C) 2009 - 2012 Nick Bolton
# SPDX-License-Identifier: MIT
2012-06-10 16:50:54 +00:00
2024-10-16 04:35:31 +00:00
cmake_minimum_required(VERSION 3.24)
# Link items by fill path
cmake_policy(SET CMP0003 NEW)
# Fix define escaping
cmake_policy(SET CMP0005 NEW)
# De-duplicate libraries on linker calls
if(POLICY CMP0156)
cmake_policy(SET CMP0156 NEW)
endif()
# Use native paths to collect dependents on windows
if(POLICY CMP0207)
cmake_policy(SET CMP0207 NEW)
endif()
#Project level options
option(BUILD_INSTALLER "Build installer" ON)
option(ENABLE_COVERAGE "Enable test coverage" OFF)
if(UNIX)
if(APPLE)
option(BUILD_OSX_BUNDLE "Build mac os bundle" ON)
else()
option(BUILD_X11_SUPPORT "Build with x11 support" ON)
endif()
elseif(WIN32)
option (VCPKG_QT "Use Qt from VCPKG" OFF)
endif()
# Set CXX Requirements
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2024-10-14 02:00:12 +00:00
# Fallback for when git can not be found
set(DESKFLOW_VERSION_MAJOR 1)
2026-02-16 13:02:20 +00:00
set(DESKFLOW_VERSION_MINOR 26)
2025-05-28 16:17:02 +00:00
set(DESKFLOW_VERSION_PATCH 0)
2024-10-14 02:00:12 +00:00
set(DESKFLOW_VERSION_TWEAK 0)
# Get the version from git if it's a git repository
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA_SHORT
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
2024-10-14 02:00:12 +00:00
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --long --match v* --always
2024-10-14 02:00:12 +00:00
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GITREV
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(FIND "${GITREV}" "v" isRev)
if(NOT ${isRev} EQUAL -1)
string(REGEX MATCH [0-9]+ MAJOR ${GITREV})
string(REGEX MATCH \\.[0-9]+ MINOR ${GITREV})
string(REPLACE "." "" MINOR "${MINOR}")
string(REGEX MATCH [0-9]+\- PATCH ${GITREV})
string(REPLACE "-" "" PATCH "${PATCH}")
string(REGEX MATCH \-[0-9]+\- TWEAK ${GITREV})
string(REPLACE "-" "" TWEAK "${TWEAK}")
set(DESKFLOW_VERSION_MAJOR ${MAJOR})
set(DESKFLOW_VERSION_MINOR ${MINOR})
set(DESKFLOW_VERSION_PATCH ${PATCH})
set(DESKFLOW_VERSION_TWEAK ${TWEAK})
else()
set(DESKFLOW_VERSION_TWEAK "9999")
2024-10-14 02:00:12 +00:00
endif()
unset(GITREV)
2024-10-14 02:00:12 +00:00
endif()
endif()
#generate vcpkg file if needed
if(WIN32)
if(VCPKG_QT)
set(QT_LIBS ", \"qttranslations\", \"qtsvg\"")
endif()
configure_file(cmake/vcpkg.json.in ${CMAKE_SOURCE_DIR}/vcpkg.json @ONLY)
endif()
2024-10-14 02:00:12 +00:00
#Define our project
project(
deskflow
VERSION "${DESKFLOW_VERSION_MAJOR}.${DESKFLOW_VERSION_MINOR}.${DESKFLOW_VERSION_PATCH}.${DESKFLOW_VERSION_TWEAK}"
DESCRIPTION "Keyboard and mouse sharing utility"
HOMEPAGE_URL "https://deskflow.org"
LANGUAGES C CXX
)
2024-10-14 02:00:12 +00:00
# Define Additional "PROJECT" vars for packaging and metadata
set(CMAKE_PROJECT_PROPER_NAME "Deskflow")
set(CMAKE_PROJECT_VENDOR "${CMAKE_PROJECT_PROPER_NAME} Devs")
set(CMAKE_PROJECT_COPYRIGHT "(C) 2024-2026 ${CMAKE_PROJECT_VENDOR}")
set(CMAKE_PROJECT_CONTACT "${CMAKE_PROJECT_PROPER_NAME} <maintainers@deskflow.org>")
set(CMAKE_PROJECT_REV_FQDN "org.deskflow.deskflow")
#Unset the vars used in the project call
unset(DESKFLOW_VERSION_MAJOR)
unset(DESKFLOW_VERSION_MINOR)
unset(DESKFLOW_VERSION_PATCH)
unset(DESKFLOW_VERSION_TWEAK)
2024-10-14 02:00:12 +00:00
message(STATUS "Building ${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}")
2012-06-10 16:50:54 +00:00
2024-12-02 01:21:22 +00:00
# Set lib versions
set(REQUIRED_OPENSSL_VERSION 3.0)
set(REQUIRED_LIBEI_VERSION 1.3)
2026-02-25 23:42:11 +00:00
set(REQUIRED_LIBPORTAL_VERSION 0.9.1)
set(REQUIRED_QT_VERSION 6.7.0)
if (WIN32)
# VSCMD_ARG_TGT_ARCH is set on CI
if ("$ENV{VSCMD_ARG_TGT_ARCH}" STREQUAL "")
# NOT on CI
if (CMAKE_SYSTEM_PROCESSOR MATCHES "[Aa][Rr][Mm]64")
set(BUILD_ARCHITECTURE arm64)
else()
set(BUILD_ARCHITECTURE x64)
endif()
else()
set (BUILD_ARCHITECTURE $ENV{VSCMD_ARG_TGT_ARCH})
endif()
else()
set (BUILD_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
endif()
if (MSVC)
# Require the same MSVC runtime that built the binary. Mitigates access violations
# from accidental ABI-compatibility breakage across runtime minor versions.
#
# Derive the minor from the compiler toolset (cl major 19 maps to CRT major 14 and
# the minor matches, e.g. 19.44 -> 14.44) rather than the host's installed redist
# from the registry. The toolset version tracks the runtime it actually produces,
# including the debug CRT (vcruntime140d.dll); the registry redist can be newer than
# the loaded DLL and make the runtime guard reject a valid local build.
set(REQUIRED_MSVC_RUNTIME_MAJOR 14)
if (CMAKE_CXX_COMPILER_VERSION MATCHES "^[0-9]+\\.([0-9]+)")
set(REQUIRED_MSVC_RUNTIME_MINOR "${CMAKE_MATCH_1}")
message(STATUS "MSVC runtime: ${REQUIRED_MSVC_RUNTIME_MAJOR}.${REQUIRED_MSVC_RUNTIME_MINOR}")
else()
message(FATAL_ERROR "Failed to parse MSVC compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
endif()
endif()
2024-12-02 01:21:22 +00:00
2024-12-04 19:24:04 +00:00
# Control debug item visibility
# When not set logging is forced to DEBUG and show code locations
# Also exposes a test menu
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Disabling debug build")
add_definitions(-DNDEBUG)
endif()
# Set Output Folders
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
# disables the use of signals,slots and emit
# Instead use Q_SIGNAL, Q_SLOT and Q_EMIT
# prevents issues when used with glib for libportal
add_definitions(-DQT_NO_KEYWORDS)
2026-07-19 15:28:29 +00:00
#Find and setup Qt
find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Widgets Network)
if(UNIX AND NOT APPLE)
find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS DBus Xml)
endif()
# Define the location of Qt deployment tool
if(WIN32)
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND VCPKG_QT)
set(DEPLOY_TOOL windeployqt.debug.bat)
else()
set(DEPLOY_TOOL windeployqt)
endif()
elseif(APPLE)
set(DEPLOY_TOOL macdeployqt)
endif()
if (WIN32 OR APPLE)
find_program(DEPLOYQT ${DEPLOY_TOOL})
if(DEPLOYQT STREQUAL "DEPLOYQT-NOTFOUND")
message(FATAL_ERROR "Unable to locate the Qt Deploy Tool: \"${DEPLOY_TOOL}\"")
endif()
unset(DEPLOY_TOOL)
endif()
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
message(STATUS "Qt version: ${Qt6_VERSION}")
Re-implement packaging for GitHub workflows (Linux) (#7361) * Reorganize CMake Packaging module * Match if statements to function order * Cleanup root, res, and doc dirs * Move deps to requirements.txt file * Reorganize and format CMake files * Rename changelog lint * Add reccomended extension * Workflow to lint CMake files * Move CMake lint to script * Try lighter dep * Use venv * Add --format arg * Format all CMake files * Convert bash script to Python * Set CMake line ending format * Restore formatting * Add pyyaml dep * Remove unused arg * Rename config file * Remove comment * Repair copyrights (broken by defualt cmake-format) * Restore 3rd party copyright * Break up libs config into smaller macros * Better macro name * Load config after venv * Make intentional noop clearer * Only use upload step if required (make skip clearer) * Use CPack for deb and rpm packaging * Add upload step for Linux * Remove cpack dep, doesn't exist * Roll back presets version * Fixed distro like match * Update ChangeLog * Legacy checkout for some distros * All distros support v4 * Trying out newer Linux distros * Install Git on Docker images * Install without actions (not available before checkout) * Delete useless action * Install Python * Support for Arch and OpenSUSE * Add Arch and OpenSUSE to deps * Name steps * Full OpenSUSE names * Mark Git dir safe * Add pkgconf * Legacy CMake for Debian 11 * Add OpenSSL to OpenSUSE * Drop OpenSUSE Leap (no C++20 support) * Skip packaging for Arch and OpenSUSE (for now) * Shorten Arch/OpenSUSE names * Clearer step name * SImpler bootstrap * Shell not needed * Update apt * Don't check return code * Simplify python deps commands * Add STGZ/.sh package type * Prevent input prompt * Only config git safe dir when needed * Try cache v4 * Safe dir for Ubuntu * Safe dir for Arch * All Docker images seem to need safe dir config * Refactor env var getters * Make Ubuntu build extra packages * Condense bootstep to single step * Fixed var name * Fixed bootstrap logic * Simplify logic for upload condition (Windows and macOS) * Make package/upload condition easier to understand * Add Manjaro * Generic names for Linux .tar.gz and .sh packages * Add Manjaro deps * Swap macOS matrix entries * Add Red Hat UBI * Remove RHEL subscription manager * Throw on unsupported package distro * Conditionally install pip and venv * Remove extra pip arg * Add config for RHEL * Install EPEL for RHEL * Back-out RHEL as EPEL requires subscription * Restore Python deps logic * Fixed bug: Packacking run twice * Testing arm32v7 and arm64v8 * Revert "Testing arm32v7 and arm64v8" This reverts commit cb3caf188d2b79ed083a62fc091de295f9889f3d. * Re-add icon and shortcut file for Linux to package * Support OpenSUSE RPM build * Check return code * Add `rpm-build` for OpenSUSE * Reorg packages * Remove busybox-which * Add --non-interactive * Move --non-interactive to correct position * Experiment with makepkg * Check and print package commands * Make distro version optional * Use 8 cores to build * Default to distro name only * Fixed bad PKGBUILD filename * Use 4-part version for Arch * Remove comma from conflicts * Use .tar.gz from cwd * Generate checksum for Arch * Fixed file extension * Use shell to print output * Don't use shell * Gaurd against bad cmd_utils.run * Fixed bad import * Use list command * Fixed unable to run list commands * Use source file name * Simplify PKGBUILD to use make install * Change install prefix * Use DESTDIR * Copy .desktop and .png to build dir * Restore original `install(FILES...` * Improving comments * Fixed: makepkg runs from `src` by default * Move error after command print * Remove shell arg * Package as a user instead of root (makepkg can't run as root) * Fixed codesign runs in shell * Allow list commands in shell on windows * Don't use sudo on arch * Install sudo on Arch * Fixed typo * Fix ownership of build directory for package user * Improve example .env * Change to depend on libstdc++6 * Add TODO * Fixed Fedora version * Remove libstdc++ deps (names vary between distros) * Roll back to Fedora 40 and 39 * Improve comment * Remove unneccesary default
2024-07-02 10:23:56 +00:00
include(cmake/Libraries.cmake)
configure_libs()
Re-implement packaging for GitHub workflows (macOS) (#7353) * Restore Azure macOS dist scripts * Move steps to workflow for testing * Always upload to GitHub * Add codesign ID * Echo codesign ID * Add cert import code * Stub file for Mac * Self-install pyyaml and choco * Auto add env var on Windows * Auto add CMAKE_PREFIX_PATH to .zshrc * Shorter var names * Append env var instead of replace * Only set env var if not CI * Improve function names and print output * Simplify Linux package command * Support continuation sequence * Add note about Windows * Remove dead doc file * Tidy up version file and move to .env format * Use Python venv for deps * Only use venv on Mac * Rename package script for all OS * Add package and dist steps, and use common upload * Remove version source * Fixed vars not available * Fixed python paths * Use RuntimeError which is sufficient * Remove dead code * Add extras command for Linux * Always install deps on Linux * Move Python deps to CI * More env bootstrapping, ugh * Forgot to return! * Simplify code * Use shell * Simplify command * Skip sudo if no sudo * Update package managers * Fixed Fedora package name * Tidy up commands * Use newer upload artifact * Strip don't trim! * Check for version file and reduce log verbosity * Remove CentOS 7.6 * Print more info about return code and log more to stderr * Install certificate on macOS * Better errors for no env var * Implement Mac signing and notary * Move dmgbuild load * Simplify notary * Rename dist files to same as dest * Fixed paths for dist * Move checked-in dist files to res (dist is meant to be a temp dir) * Fixed Mac path in CMake * Fixed dmg path * Format Python * Ignore import warnings and move function * Fixed cmake paths * Add missing env var secrets * Remove extensions from GH upload * Make deps.yml general purpose config * Add cspell config * Pass codesign ID * Use new general config file * Sign bundle on Mac * Move imports to functions * Escape chars in docs * Fixed config key accessor * Change module import order * Move file to tmp dir in workflow dir * Persist temp dir * Add tmp dir to ignore * Flush stdio before running process * Trying quotes around env values * Add codesigning certificate validation for Mac signing * Revert "Trying quotes around env values" This reverts commit 0dd741e8cd6fde21e69d4fb871e835a5f4fa1a23. * Extract codesign verify * Fixed version number * Ignore .cache dir * Fix macro name * Package name with version number and arch * Improve package function readability * Change order of vars * Testing upload to GDrive * Add missing return code * Use positional args and declare error * Use machine instead of arch and remove build from filename * Remove redundant build jobs * Replace massively over-complicated `build_version.py` script * Move version info to env module * Use version info script * Fixed: too many values to unpack * Chmod version script * Use shebang * Don't check return code on Linux * Fixed function name * Convert to GitHub specific script * Env vars must be after configure * Fixed Windows env var command * Remove && from deps command so it's not conditional * Fixed position of set env * Change order of env script * Only upload when not draft * Test * Tweak config * Fixed if condition * Don't package in draft (Windows and Linux)
2024-06-24 09:36:30 +00:00
if(ENABLE_COVERAGE)
message(STATUS "Enabling code coverage")
include(cmake/CodeCoverage.cmake)
append_coverage_compiler_flags()
# Apparently solves the bug in gcov where it returns negative counts and confuses gcovr.
# > Got negative hit value in gcov line 'branch 2 taken -1' caused by a bug in gcov tool
# Bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68080
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-update=atomic")
endif()
if(BUILD_OSX_BUNDLE AND APPLE_CODESIGN_DEV)
include(cmake/MacCodesign.cmake)
endif()
# setup install paths
include(GNUInstallDirs)
if (WIN32)
set(CMAKE_INSTALL_BINDIR .)
set(CMAKE_INSTALL_LIBDIR .)
set(CMAKE_INSTALL_DOCDIR docs)
set(CMAKE_INSTALL_LICENSE_DIR .)
set(CMAKE_INSTALL_I18N_DIR translations)
elseif(BUILD_OSX_BUNDLE)
set(CMAKE_INSTALL_BINDIR ${CMAKE_PROJECT_PROPER_NAME}.app/Contents/MacOS)
set(CMAKE_INSTALL_LICENSE_DIR ${CMAKE_PROJECT_PROPER_NAME}.app/Contents/Resources)
else()
set(CMAKE_INSTALL_LICENSE_DIR ${CMAKE_INSTALL_DATADIR}/licenses/${CMAKE_PROJECT_NAME})
set(CMAKE_INSTALL_I18N_DIR ${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/translations)
endif()
2026-02-22 20:51:20 +00:00
add_subdirectory(docs)
# build translations before source, I18N unit tests fail if they are missing
2025-10-15 02:39:45 +00:00
add_subdirectory(translations)
Solve low hanging reliability and maintainability issues (#7403) * Add missing atom ctor init * Init members with `None` * Use in-class init and delcare getter inside if init * Temp revert of changes ahead of unit test repair * Move IPC header to shared, restore X clipboard test, simplify test cmake, new X clipboard unit test * Suppress sonar for undefs * Remove base dir include * Revert "Temp revert of changes ahead of unit test repair" This reverts commit 8f84b6ea5d5828f1be1362de3809279bcacb8cc8. * Use new accessor * Use default dtor * Beef up to 32 core * Use enum class * Make IPC protocol headers const at all levels * Use enum class and const char for better type safety * Use unique_ptr for m_clipboard * Use `-j` instead of `-j8` to utilize full parallelism * Increase thread count for sonar-scanner * Use 32 threads * Use in-class init for IpcClientProxy members * Use const instead of #define * Remove ctor member inits * Use unique_ptr on win * Implement temp bin dir for windows with more robust post-build copy * Fixed missing iostream * Add warning about copy errors * Only run clean-gcda on Linux * Use in-class init for IPC mutex * Do no-op on Windows * Hide clean-gcda task * Move flakey test to integtests * Delete dead code * Test * Temp disable post_config_all * Disable post config step * Revert "Disable post config step" This reverts commit 2f956a7714ba9bedacd4b39d4ae00940c3d565d6. * Revert "Temp disable post_config_all" This reverts commit b44ed72e44f838bfe1309f6e9672d2f1c6f21b75. * Restore -j8 * Simplify error handling * Use const for test port * Remove python check * Update changelog * Fixed order * Fixed bad issue number * Fixed bin copy source path * Remove redundant except
2024-07-18 07:04:39 +00:00
add_subdirectory(src)
if(BUILD_INSTALLER)
add_subdirectory(deploy)
endif()
install(
FILES ${PROJECT_SOURCE_DIR}/LICENSE
DESTINATION ${CMAKE_INSTALL_LICENSE_DIR}
)
install(
FILES ${PROJECT_SOURCE_DIR}/LICENSES/LicenseRef-OpenSSL-Exception.txt
DESTINATION ${CMAKE_INSTALL_LICENSE_DIR}
RENAME LICENSE_EXCEPTION
)