diff --git a/CMakeLists.txt b/CMakeLists.txt index b95fc88c..50f7438a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,53 +1,65 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR) find_package(ECM 1.8.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) include(SetKReportCMakePolicies NO_POLICY_SCOPE) project(KReport VERSION 3.0.90) # Update this +include(KReportAddTests) +include(KReportAddExamples) +kreport_add_tests(OFF) +kreport_add_examples(OFF) + # CMake include(CMakePackageConfigHelpers) # ECM include(ECMGeneratePriFile) include(ECMPoQmTools) include(ECMSetupVersion) include(ECMInstallIcons) include(ECMOptionalAddSubdirectory) include(KDEInstallDirs) include(KDECMakeSettings NO_POLICY_SCOPE) include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE) # Own include(KReportAddIconsRccFile) include(KReportAddQCH) include(KReportMacros) simple_option(BUILD_QCH "Build API documentation in QCH format" OFF) # Dependencies set(REQUIRED_QT_VERSION 5.4.0) set(REQUIRED_KF5_VERSION 5.16.0) set(REQUIRED_KPROPERTY_VERSION 3.0.90) # Required components to build this framework # TODO move Widgets/KF5WidgetsAddons-dependent part to a libKReportDesigner find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Core Widgets Xml PrintSupport) find_package(KF5 ${REQUIRED_KF5_VERSION} REQUIRED CoreAddons WidgetsAddons GuiAddons Config) find_package(KPropertyWidgets ${REQUIRED_KPROPERTY_VERSION} COMPONENTS KF) set_package_properties(KPropertyWidgets PROPERTIES TYPE REQUIRED PURPOSE "Required by KReport for handling properties") get_git_revision_and_branch() -add_tests() -add_examples() add_unfinished_features_option() add_pc_file(${PROJECT_NAME}) add_subdirectory(src) +if(BUILD_TESTING) + add_subdirectory(autotests) + #add_subdirectory(tests) +endif() + +if(BUILD_EXAMPLES) + add_subdirectory(examples) +endif() + if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/po") ecm_install_po_files_as_qm(po) endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/cmake/modules/KReportAddExamples.cmake b/cmake/modules/KReportAddExamples.cmake new file mode 100644 index 00000000..122f91a2 --- /dev/null +++ b/cmake/modules/KReportAddExamples.cmake @@ -0,0 +1,24 @@ +# Additional CMake macros +# +# Copyright (C) 2015-2017 Jarosław Staniek +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +if(__kreport_add_examples) + return() +endif() +set(__kreport_add_examples YES) + +include(KReportAddSimpleOption) + +# Adds BUILD_EXAMPLES option to enable examples. If enabled, build in examples/ subdirectory +# is enabled. If optional argument ARG1 is ON, building examples will be ON by default. +# Otherwise building examples will be OFF. ARG1 is OFF by default. +macro(kreport_add_examples) + set(_SET ${ARGV0}) + if (NOT "${_SET}" STREQUAL ON) + set(_SET OFF) + endif() + simple_option(BUILD_EXAMPLES "Build example applications" ${_SET}) +endmacro() diff --git a/cmake/modules/KReportAddSimpleOption.cmake b/cmake/modules/KReportAddSimpleOption.cmake new file mode 100644 index 00000000..9d856713 --- /dev/null +++ b/cmake/modules/KReportAddSimpleOption.cmake @@ -0,0 +1,31 @@ +# Additional CMake macros +# +# Copyright (C) 2015-2017 Jarosław Staniek +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +if(__kreport_add_simple_option) + return() +endif() +set(__kreport_add_simple_option YES) + +include(FeatureSummary) + +# Adds a feature info using add_feature_info() with _NAME and _DESCRIPTION. +# If _NAME is equal to _DEFAULT, shows this fact. +macro(add_simple_feature_info _NAME _DESCRIPTION _DEFAULT) + if("${_DEFAULT}" STREQUAL "${${_NAME}}") + set(_STATUS " (default value)") + else() + set(_STATUS "") + endif() + add_feature_info(${_NAME} ${_NAME} ${_DESCRIPTION}${_STATUS}) +endmacro() + +# Adds a simple option using option() with _NAME and _DESCRIPTION and a feature +# info for it using add_simple_feature_info(). If _NAME is equal to _DEFAULT, shows this fact. +macro(simple_option _NAME _DESCRIPTION _DEFAULT) + option(${_NAME} ${_DESCRIPTION} ${_DEFAULT}) + add_simple_feature_info(${_NAME} ${_DESCRIPTION} ${_DEFAULT}) +endmacro() diff --git a/cmake/modules/KReportAddTests.cmake b/cmake/modules/KReportAddTests.cmake new file mode 100644 index 00000000..4b243490 --- /dev/null +++ b/cmake/modules/KReportAddTests.cmake @@ -0,0 +1,37 @@ +# Additional CMake macros +# +# Copyright (C) 2015-2017 Jarosław Staniek +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +# +# Note: the file must be included before KDEInstallDirs or add_tests() won't fully work + +if(__kreport_add_tests) + return() +endif() +set(__kreport_add_tests YES) + +include(KReportAddSimpleOption) + +# Adds BUILD_TESTING option to enable all kinds of tests. If enabled, build in autotests/ +# and tests/ subdirectory is enabled. If optional argument ARG1 is ON, building tests will +# be ON by default. Otherwise building tests will be OFF. ARG1 is OFF by default. +# If tests are OFF, BUILD_COVERAGE is set to OFF. +# If tests are on BUILD_TESTING macro is defined. +macro(kreport_add_tests) + if(KDE_INSTALL_TARGETS_DEFAULT_ARGS) + message(FATAL_ERROR "Include before KDEInstallDirs!") + endif() + if (NOT "${ARG1}" STREQUAL "ON") + set(_SET OFF) + endif() + simple_option(BUILD_TESTING "Build tests" ${_SET}) # override default from CTest.cmake + if(BUILD_TESTING) + add_definitions(-DBUILD_TESTING) + include(CTest) + else() + set(BUILD_COVERAGE OFF) + simple_option(BUILD_COVERAGE "Build test coverage (disabled because BUILD_TESTING is OFF)" OFF) + endif() +endmacro() diff --git a/cmake/modules/KReportMacros.cmake b/cmake/modules/KReportMacros.cmake index 39732298..50f684c4 100644 --- a/cmake/modules/KReportMacros.cmake +++ b/cmake/modules/KReportMacros.cmake @@ -1,206 +1,154 @@ # Additional CMake macros # # Copyright (C) 2015-2016 Jarosław Staniek # # Redistribution and use is allowed according to the terms of the BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. +if(__kreport_macros) + return() +endif() +set(__kreport_macros YES) + include(KDbGenerateHeaders) # from KDb, adds support for generated headers to ECMGenerateHeaders include(KDbCreateSharedDataClasses) # from KDb include(GenerateExportHeader) -include(FeatureSummary) include(GetGitRevisionDescription) +include(KReportAddSimpleOption) string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) string(COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "Clang" CMAKE_COMPILER_IS_CLANG) # Keep apps in the same bin dir so resources that are kept relative to this dir can be found # without installing. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") # x.81.z or larger means test release, so the stable major version is x+1 if(PROJECT_VERSION_MINOR GREATER 80) set(PROJECT_UNSTABLE ON) math(EXPR PROJECT_STABLE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR} + 1") set(PROJECT_STABLE_VERSION_MINOR 0) set(PROJECT_STABLE_VERSION_PATCH 0) # x.y.81 or larger means test release, so the stable minor version is y+1 elseif(PROJECT_VERSION_PATCH GREATER 80) set(PROJECT_STABLE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) math(EXPR PROJECT_STABLE_VERSION_MINOR "${PROJECT_VERSION_MINOR} + 1") set(PROJECT_STABLE_VERSION_PATCH 0) else() set(PROJECT_STABLE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) set(PROJECT_STABLE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) set(PROJECT_STABLE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) endif() if(WIN32) set(LIB_INSTALL_DIR ${LIB_INSTALL_DIR} RUNTIME DESTINATION ${BIN_INSTALL_DIR} LIBRARY ${INSTALL_TARGETS_DEFAULT_ARGS} ARCHIVE ${INSTALL_TARGETS_DEFAULT_ARGS} ) set(DATA_INSTALL_DIR "$ENV{APPDATA}") STRING(REGEX REPLACE "\\\\" "/" DATA_INSTALL_DIR ${DATA_INSTALL_DIR}) # Install own icons to CMAKE_INSTALL_FULL_ICONDIR (relative to bin/data/ on Windows) on Windows. # We're consistent because icons from breeze-icons.git are installed there as well. set(ICONS_INSTALL_DIR ${CMAKE_INSTALL_FULL_ICONDIR}) else() # On other OSes install own icons in app's data dir set(ICONS_INSTALL_DIR "${DATA_INSTALL_DIR}/${PROJECT_NAME_LOWER}${PROJECT_STABLE_VERSION_MAJOR}/icons") endif() -# Adds a feature info using add_feature_info() with _NAME and _DESCRIPTION. -# If _NAME is equal to _DEFAULT, shows this fact. -macro(add_simple_feature_info _NAME _DESCRIPTION _DEFAULT) - if("${_DEFAULT}" STREQUAL "${${_NAME}}") - set(_STATUS " (default value)") - else() - set(_STATUS "") - endif() - add_feature_info(${_NAME} ${_NAME} ${_DESCRIPTION}${_STATUS}) -endmacro() - -# Adds a simple option using option() with _NAME and _DESCRIPTION and a feature -# info for it using add_simple_feature_info(). If _NAME is equal to _DEFAULT, shows this fact. -macro(simple_option _NAME _DESCRIPTION _DEFAULT) - option(${_NAME} ${_DESCRIPTION} ${_DEFAULT}) - add_simple_feature_info(${_NAME} ${_DESCRIPTION} ${_DEFAULT}) -endmacro() - # Fetches git revision and branch from the source dir of the current build if possible. # Sets ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING and ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING variables. # If git information is not available but ${CMAKE_SOURCE_DIR}/GIT_VERSION file exists, # it is parsed. This file can be created by scripts while preparing tarballs and is # supposed to contain two lines: hash and branch. macro(get_git_revision_and_branch) set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING "") set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING "") get_git_head_revision(GIT_REFSPEC ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING) get_git_branch(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) if(NOT ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING OR NOT ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) if(EXISTS "${CMAKE_SOURCE_DIR}/GIT_VERSION") file(READ "${CMAKE_SOURCE_DIR}/GIT_VERSION" _ver) string(REGEX REPLACE "\n" ";" _ver "${_ver}") list(GET _ver 0 ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING) list(GET _ver 1 ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) endif() endif() if(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING OR ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) string(SUBSTRING ${${PROJECT_NAME_UPPER}_GIT_SHA1_STRING} 0 7 ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING) else() set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING "") set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING "") endif() endmacro() -# Adds BUILD_TESTING option to enable all kinds of tests. If enabled, build in autotests/ -# and tests/ subdirectory is enabled. IF optional argument ARG1 is ON, building tests will -# be ON by default. Otherwise building tests will be OFF. ARG1 is OFF by default. -# If tests are OFF, BUILD_COVERAGE is set to OFF. -# If tests are on BUILD_TESTING macro is defined. -macro(add_tests) - if (NOT "${ARG1}" STREQUAL "ON") - set(_SET OFF) - endif() - simple_option(BUILD_TESTING "Build tests" ${_SET}) # override default from CTest.cmake - if(BUILD_TESTING) - add_definitions(-DBUILD_TESTING) - include(CTest) - if (EXISTS ${CMAKE_SOURCE_DIR}/autotests) - add_subdirectory(autotests) - endif() - if (EXISTS ${CMAKE_SOURCE_DIR}/tests) - add_subdirectory(tests) - endif() - else() - set(BUILD_COVERAGE OFF) - simple_option(BUILD_COVERAGE "Build test coverage (disabled because BUILD_TESTING is OFF)" OFF) - endif() -endmacro() - -# Adds BUILD_EXAMPLES option to enable examples. If enabled, build in examples/ subdirectory -# is enabled. If optional argument ARG1 is ON, building examples will be ON by default. -# Otherwise building examples will be OFF. ARG1 is OFF by default. -macro(add_examples) - set(_SET ${ARGV0}) - if (NOT "${_SET}" STREQUAL ON) - set(_SET OFF) - endif() - simple_option(BUILD_EXAMPLES "Build example applications" ${_SET}) - if (BUILD_EXAMPLES AND EXISTS ${CMAKE_SOURCE_DIR}/examples) - add_subdirectory(examples) - endif() -endmacro() - # Adds ${PROJECT_NAME_UPPER}_UNFINISHED option. If it is ON, unfinished features # (useful for testing but may confuse end-user) are compiled-in. # This option is OFF by default. macro(add_unfinished_features_option) simple_option(${PROJECT_NAME_UPPER}_UNFINISHED "Include unfinished features (useful for testing but may confuse end-user)" OFF) endmacro() # Adds commands that generate ${_filename}${PROJECT_STABLE_VERSION_MAJOR}.pc file # out of ${_filename}.pc.cmake file and installs the .pc file to ${LIB_INSTALL_DIR}/pkgconfig. # These commands are not executed for WIN32. # ${CMAKE_SOURCE_DIR}/${_filename}.pc.cmake should exist. macro(add_pc_file _filename) if (NOT WIN32) set(_name ${_filename}${PROJECT_STABLE_VERSION_MAJOR}) configure_file(${CMAKE_SOURCE_DIR}/${_filename}.pc.cmake ${CMAKE_BINARY_DIR}/${_name}.pc @ONLY) install(FILES ${CMAKE_BINARY_DIR}/${_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) endif() endmacro() # Sets detailed version information for library co-installability. # - adds PROJECT_VERSION_MAJOR to the lib name # - sets VERSION and SOVERSION to PROJECT_VERSION_MAJOR.PROJECT_VERSION_MINOR # - sets ${_target_upper}_BASE_NAME variable to the final lib name # - sets ${_target_upper}_BASE_NAME_LOWER variable to the final lib name, lowercase # - sets ${_target_upper}_INCLUDE_INSTALL_DIR to include dir for library headers # - (where _target_upper is uppercase ${_target} macro(set_coinstallable_lib_version _target) set(_name ${_target}${PROJECT_STABLE_VERSION_MAJOR}) set_target_properties(${_target} PROPERTIES VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} SOVERSION ${PROJECT_VERSION_MAJOR} EXPORT_NAME ${_target} OUTPUT_NAME ${_name} ) string(TOUPPER ${_target} _target_upper) string(TOUPPER ${_target_upper}_BASE_NAME _var) set(${_var} ${_name}) string(TOLOWER ${_name} ${_var}_LOWER) set(${_target_upper}_INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/${_name}) unset(_target_upper) unset(_var) endmacro() # Adds custom target ${_target} that updates file ${_file} in the current working dir # using command ${_command} and add sources ${_sources} to the project files. # The command is run as a part of the project. function(add_update_file_target) set(options) set(oneValueArgs TARGET FILE) set(multiValueArgs COMMAND SOURCES) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) add_custom_target(${ARG_TARGET} COMMAND ${ARG_COMMAND} SOURCES ${ARG_SOURCES} DEPENDS ${ARG_SOURCES} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" COMMENT "Updating ${ARG_FILE}" VERBATIM ) endfunction() # Checks if ${_package} has at most version ${_maximum_version}. macro(check_maximum_package_version _package _maximum_version) if(NOT ${_package}_FOUND OR NOT ${${_package}_VERSION} VERSION_LESS ${_maximum_version}) message(FATAL_ERROR "Maximum version of ${_package} is ${_maximum_version}, " "found ${${_package}_VERSION}") endif() endmacro()