cmake_minimum_required (VERSION 3.13) project (accounts-qml-module VERSION 0.7 LANGUAGES CXX ) # CMAKE_BUILD_TYPE either empty, or user-specified, or goes unused with multi-configuration generators # Makefile and Ninja are single-configuration, so going with that assumption if (NOT CMAKE_BUILD_TYPE) # If unset by user, default to Release-level optimisations set (CMAKE_BUILD_TYPE "Release") endif() # To not care about capitalisation string (TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) option (ENABLE_DOCS "Enable documentation generation & installation" ON) option (ENABLE_UBUNTU_DOCS "Ubuntu App Developer-ify the documentation" OFF) set (QT_MAJOR_VERSION "6" CACHE STRING "The Qt major version to target") if (QT_MAJOR_VERSION VERSION_GREATER_EQUAL "6") set (CMAKE_CXX_STANDARD 17) else() set (CMAKE_CXX_STANDARD 11) endif() set (CMAKE_CXX_EXTENSIONS OFF) set (CMAKE_CXX_STANDARD_REQUIRED ON) if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set (CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Installation prefix" FORCE) endif() include (CTest) include (GNUInstallDirs) message (STATUS "install prefix set to ${CMAKE_INSTALL_PREFIX}") message (STATUS "binaries will be installed to ${CMAKE_INSTALL_FULL_BINDIR}") message (STATUS "documentation will be installed to ${CMAKE_INSTALL_FULL_DOCDIR}") message (STATUS "headers will be installed to ${CMAKE_INSTALL_FULL_INCLUDEDIR}") message (STATUS "libraries will be installed to ${CMAKE_INSTALL_FULL_LIBDIR}") message (STATUS "NOTE: To override these installation path, define these cache variable:") message (STATUS "- CMAKE_INSTALL_PREFIX: general prefix") message (STATUS "- CMAKE_INSTALL_BINDIR: path relative to CMAKE_INSTALL_PREFIX, or absolute path, to install binaries to") message (STATUS "- CMAKE_INSTALL_DOCDIR: path relative to CMAKE_INSTALL_PREFIX, or absolute path, to install documentation to") message (STATUS "- CMAKE_INSTALL_INCLUDEDIR: path relative to CMAKE_INSTALL_PREFIX, or absolute path, to install headers to") message (STATUS "- CMAKE_INSTALL_LIBDIR: path relative to CMAKE_INSTALL_PREFIX, or absolute path, to install libraries to") find_package (QT NAMES Qt${QT_MAJOR_VERSION}) list (APPEND QT_COMPONENTS Core Qml ) if (BUILD_TESTING) list (APPEND QT_COMPONENTS Test ) endif() find_package (Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS ${QT_COMPONENTS}) set (CMAKE_AUTOMOC ON) set (QT_IMPORTS_DIR "${CMAKE_INSTALL_LIBDIR}/qt${QT_MAJOR_VERSION}/qml") if (ENABLE_DOCS) find_program (QDOC NAMES qdoc) message (STATUS "qdoc: ${QDOC}") if (NOT QDOC) message (FATAL_ERROR "qdoc not found, but required for documentation!") endif() endif() find_package (PkgConfig REQUIRED) pkg_check_modules (ACCOUNTS_QT REQUIRED accounts-qt${QT_MAJOR_VERSION}) pkg_check_modules (LIBSIGNON_QT REQUIRED libsignon-qt${QT_MAJOR_VERSION}) find_program (QMLPLUGINDUMP NAMES qmlplugindump) message (STATUS "qmlplugindump: ${QMLPLUGINDUMP}") if (NOT QMLPLUGINDUMP) message (FATAL_ERROR "qmlplugindump not found, but required for building!") endif() add_compile_options ( # we don't like warnings... -Wno-write-strings # Disable RTTI -fno-exceptions -fno-rtti ) # Error on undefined symbols add_link_options ( -Wl,--no-undefined ) set (REALLY_COVERAGE OFF) if (CMAKE_BUILD_TYPE_UPPER STREQUAL "COVERAGE") message (STATUS "Coverage generation mode enabled") # Want to be able to check for coverage of debug-specific bits if present set (REALLY_COVERAGE ON) set (CMAKE_BUILD_TYPE "Debug") string (TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER) if (NOT BUILD_TESTING) message (FATAL_ERROR "BUILD_TESTING disabled, but required for gathering coverage data!") endif() find_program (LCOV NAMES lcov) message (STATUS "lcov: ${LCOV}") if (NOT LCOV) message (FATAL_ERROR "lcov not found, but required for evaluating coverage data!") endif() find_program (GENHTML NAMES genhtml) message (STATUS "genhtml: ${GENHTML}") if (NOT GENHTML) message (FATAL_ERROR "genhtml not found, but required for evaluating coverage data!") endif() add_compile_options (--coverage) add_link_options (--coverage) link_libraries (gcov) set (COVERAGE_HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/coverage-html") add_custom_target (generate-coverage-html COMMENT "Generating coverage report in ${COVERAGE_HTML_DIR}" COMMAND ${CMAKE_CTEST_COMMAND} ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${LCOV} --directory ${CMAKE_CURRENT_BINARY_DIR} --capture --output-file ${CMAKE_CURRENT_BINARY_DIR}/coverage.info --no-checksum --compat-libtool COMMAND ${LCOV} --extract ${CMAKE_CURRENT_BINARY_DIR}/coverage.info \"*/src/*.cpp\" -o ${CMAKE_CURRENT_BINARY_DIR}/coverage.info COMMAND ${LCOV} --remove ${CMAKE_CURRENT_BINARY_DIR}/coverage.info \"moc_*.cpp\" -o ${CMAKE_CURRENT_BINARY_DIR}/coverage.info COMMAND ${CMAKE_COMMAND} -E env LANG=C ${GENHTML} --prefix ${CMAKE_CURRENT_BINARY_DIR} --output-directory ${COVERAGE_HTML_DIR} --title \"Code Coverage\" --legend --show-details ${CMAKE_CURRENT_BINARY_DIR}/coverage.info ) endif() if (ENABLE_DOCS) add_subdirectory (doc) endif() add_subdirectory (src) if (BUILD_TESTING) find_program (XVFB_RUN NAMES xvfb-run) message (STATUS "xvfb-run: ${XVFB_RUN}") if (NOT XVFB_RUN) message (FATAL_ERROR "xvfb-run not found, but required for tests!") endif() find_program (DBUS_TEST_RUNNER NAMES dbus-test-runner) message (STATUS "dbus-test-runner: ${DBUS_TEST_RUNNER}") if (NOT DBUS_TEST_RUNNER) message (FATAL_ERROR "dbus-test-runner not found, but required for tests!") endif() add_subdirectory (tests) endif() if (REALLY_COVERAGE) add_dependencies (generate-coverage-html Accounts signon-qt${QT_MAJOR_VERSION} tst_plugin) endif() set (DISTNAME "${PROJECT_NAME}-${PROJECT_VERSION}") set (LOCATION_TARBALL "${CMAKE_CURRENT_BINARY_DIR}/${DISTNAME}.tar") set (LOCATION_TARBALL_COMPRESSED "${LOCATION_TARBALL}.bz2") add_custom_target (dist-tar COMMENT "Creating distribution tarball at ${LOCATION_TARBALL}" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND git archive --format=tar --prefix=${DISTNAME}/ HEAD > ${LOCATION_TARBALL} ) add_custom_target (dist COMMENT "Compressing distribution tarball at ${LOCATION_TARBALL_COMPRESSED}" COMMAND bzip2 -9ck ${LOCATION_TARBALL} > ${LOCATION_TARBALL_COMPRESSED} ) add_dependencies (dist dist-tar)