Warning, /libraries/kreport/cmake/modules/KReportMacros.cmake is written in an unsupported language. File is not indexed.
0001 # Additional CMake macros 0002 # 0003 # Copyright (C) 2015-2018 Jarosław Staniek <staniek@kde.org> 0004 # 0005 # Redistribution and use is allowed according to the terms of the BSD license. 0006 # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 0007 0008 if(__kreport_macros) 0009 return() 0010 endif() 0011 set(__kreport_macros YES) 0012 0013 include(KDbGenerateHeaders) # from KDb, adds support for generated headers to ECMGenerateHeaders 0014 include(KDbCreateSharedDataClasses) # from KDb 0015 include(GenerateExportHeader) 0016 include(GetGitRevisionDescription) 0017 include(KReportAddSimpleOption) 0018 0019 string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) 0020 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) 0021 string(COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "Clang" CMAKE_COMPILER_IS_CLANG) 0022 0023 # Keep apps in the same bin dir so resources that are kept relative to this dir can be found 0024 # without installing. 0025 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 0026 0027 # x.81.z or larger means test release, so the stable major version is x+1 0028 if(PROJECT_VERSION_MINOR GREATER 80) 0029 set(PROJECT_UNSTABLE ON) 0030 math(EXPR PROJECT_STABLE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR} + 1") 0031 set(PROJECT_STABLE_VERSION_MINOR 0) 0032 set(PROJECT_STABLE_VERSION_PATCH 0) 0033 # x.y.81 or larger means test release, so the stable minor version is y+1 0034 elseif(PROJECT_VERSION_PATCH GREATER 80) 0035 set(PROJECT_STABLE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) 0036 math(EXPR PROJECT_STABLE_VERSION_MINOR "${PROJECT_VERSION_MINOR} + 1") 0037 set(PROJECT_STABLE_VERSION_PATCH 0) 0038 else() 0039 set(PROJECT_STABLE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) 0040 set(PROJECT_STABLE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) 0041 set(PROJECT_STABLE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) 0042 endif() 0043 0044 set(ICONS_INSTALL_DIR "${DATA_INSTALL_DIR}/${PROJECT_NAME_LOWER}${PROJECT_STABLE_VERSION_MAJOR}/icons") 0045 0046 # Fetches git revision and branch from the source dir of the current build if possible. 0047 # Sets ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING and ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING variables. 0048 # If git information is not available but ${CMAKE_SOURCE_DIR}/GIT_VERSION file exists, 0049 # it is parsed. This file can be created by scripts while preparing tarballs and is 0050 # supposed to contain two lines: hash and branch. 0051 macro(get_git_revision_and_branch) 0052 set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING "") 0053 set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING "") 0054 get_git_head_revision(GIT_REFSPEC ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING) 0055 get_git_branch(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) 0056 if(NOT ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING OR NOT ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) 0057 if(EXISTS "${CMAKE_SOURCE_DIR}/GIT_VERSION") 0058 file(READ "${CMAKE_SOURCE_DIR}/GIT_VERSION" _ver) 0059 string(REGEX REPLACE "\n" ";" _ver "${_ver}") 0060 list(GET _ver 0 ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING) 0061 list(GET _ver 1 ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) 0062 endif() 0063 endif() 0064 if(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING OR ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING) 0065 string(SUBSTRING ${${PROJECT_NAME_UPPER}_GIT_SHA1_STRING} 0 7 ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING) 0066 else() 0067 set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING "") 0068 set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING "") 0069 endif() 0070 endmacro() 0071 0072 # Adds ${PROJECT_NAME_UPPER}_UNFINISHED option. If it is ON, unfinished features 0073 # (useful for testing but may confuse end-user) are compiled-in. 0074 # This option is OFF by default. 0075 macro(add_unfinished_features_option) 0076 simple_option(${PROJECT_NAME_UPPER}_UNFINISHED 0077 "Include unfinished features (useful for testing but may confuse end-user)" OFF) 0078 endmacro() 0079 0080 # Sets detailed version information for library co-installability. 0081 # - adds PROJECT_STABLE_VERSION_MAJOR to the lib name 0082 # - sets VERSION to PROJECT_STABLE_VERSION_MAJOR.PROJECT_STABLE_VERSION_MINOR.PROJECT_STABLE_VERSION_PATCH 0083 # - sets SOVERSION to PROJECT_STABLE_VERSION_MAJOR 0084 # (special case for 3.0 < PROJECT_STABLE_VERSION < 4.0: sets SOVERSION to PROJECT_STABLE_VERSION_MAJOR + 1 0085 # to separate from incompatible version 3.0) 0086 # - sets ${_target_upper}_BASE_NAME variable to the final lib name 0087 # - sets ${_target_upper}_BASE_NAME_LOWER variable to the final lib name, lowercase 0088 # - sets ${_target_upper}_INCLUDE_INSTALL_DIR to include dir for library headers 0089 # - (where _target_upper is uppercase ${_target} 0090 macro(set_coinstallable_lib_version _target) 0091 set(_name ${_target}${PROJECT_STABLE_VERSION_MAJOR}) 0092 set(_soversion ${PROJECT_STABLE_VERSION_MAJOR}) 0093 if(${PROJECT_STABLE_VERSION_MAJOR} EQUAL 3) 0094 math(EXPR _soversion "${PROJECT_STABLE_VERSION_MAJOR} + 1") 0095 math(EXPR _version "${PROJECT_STABLE_VERSION_MAJOR} + 1") 0096 else() 0097 set(_soversion ${PROJECT_STABLE_VERSION_MAJOR}) 0098 endif() 0099 set(_version "${_version}.${PROJECT_STABLE_VERSION_MINOR}.${PROJECT_STABLE_VERSION_PATCH}") 0100 set_target_properties(${_target} 0101 PROPERTIES VERSION ${_version} 0102 SOVERSION ${_soversion} 0103 EXPORT_NAME ${_target} 0104 OUTPUT_NAME ${_name} 0105 ) 0106 string(TOUPPER ${_target} _target_upper) 0107 string(TOUPPER ${_target_upper}_BASE_NAME _var) 0108 set(${_var} ${_name}) 0109 string(TOLOWER ${_name} ${_var}_LOWER) 0110 set(${_target_upper}_INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/${_name}) 0111 unset(_soversion) 0112 unset(_version) 0113 unset(_target_upper) 0114 unset(_var) 0115 endmacro() 0116 0117 # Adds custom target ${_target} that updates file ${_file} in the current working dir 0118 # using command ${_command} and add sources ${_sources} to the project files. 0119 # The command is run as a part of the project. 0120 function(add_update_file_target) 0121 set(options) 0122 set(oneValueArgs TARGET FILE) 0123 set(multiValueArgs COMMAND SOURCES) 0124 cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 0125 add_custom_target(${ARG_TARGET} 0126 COMMAND ${ARG_COMMAND} 0127 SOURCES ${ARG_SOURCES} 0128 DEPENDS ${ARG_SOURCES} 0129 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 0130 COMMENT "Updating ${ARG_FILE}" 0131 VERBATIM 0132 ) 0133 endfunction() 0134 0135 # Checks if ${_package} has at most version ${_maximum_version}. 0136 macro(check_maximum_package_version _package _maximum_version) 0137 if(NOT ${_package}_FOUND OR NOT ${${_package}_VERSION} VERSION_LESS ${_maximum_version}) 0138 message(FATAL_ERROR "Maximum version of ${_package} is ${_maximum_version}, " 0139 "found ${${_package}_VERSION}") 0140 endif() 0141 endmacro()