Warning, /libraries/kproperty/cmake/modules/KPropertyMacros.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 include(FeatureSummary)
0009 include(GetGitRevisionDescription)
0010 
0011 string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
0012 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER)
0013 string(COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "Clang" CMAKE_COMPILER_IS_CLANG)
0014 
0015 # Keep apps in the same bin dir so resources that are kept relative to this dir can be found
0016 # without installing.
0017 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
0018 
0019 # x.81.z or larger means test release, so the stable major version is x+1
0020 if(PROJECT_VERSION_MINOR GREATER 80)
0021     set(PROJECT_UNSTABLE ON)
0022     math(EXPR PROJECT_STABLE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR} + 1")
0023     set(PROJECT_STABLE_VERSION_MINOR 0)
0024     set(PROJECT_STABLE_VERSION_PATCH 0)
0025 # x.y.81 or larger means test release, so the stable minor version is y+1
0026 elseif(PROJECT_VERSION_PATCH GREATER 80)
0027     set(PROJECT_STABLE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
0028     math(EXPR PROJECT_STABLE_VERSION_MINOR "${PROJECT_VERSION_MINOR} + 1")
0029     set(PROJECT_STABLE_VERSION_PATCH 0)
0030 else()
0031     set(PROJECT_STABLE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
0032     set(PROJECT_STABLE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
0033     set(PROJECT_STABLE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
0034 endif()
0035 
0036 set(ICONS_INSTALL_DIR "${DATA_INSTALL_DIR}/${PROJECT_NAME_LOWER}${PROJECT_STABLE_VERSION_MAJOR}/icons")
0037 
0038 # Adds a feature info using add_feature_info() with _NAME and _DESCRIPTION.
0039 # If _NAME is equal to _DEFAULT, shows this fact.
0040 macro(add_simple_feature_info _NAME _DESCRIPTION _DEFAULT)
0041   if("${_DEFAULT}" STREQUAL "${${_NAME}}")
0042     set(_STATUS " (default value)")
0043   else()
0044     set(_STATUS "")
0045   endif()
0046   add_feature_info(${_NAME} ${_NAME} ${_DESCRIPTION}${_STATUS})
0047 endmacro()
0048 
0049 # Adds a simple option using option() with _NAME and _DESCRIPTION and a feature
0050 # info for it using add_simple_feature_info(). If _NAME is equal to _DEFAULT, shows this fact.
0051 macro(simple_option _NAME _DESCRIPTION _DEFAULT)
0052   option(${_NAME} ${_DESCRIPTION} ${_DEFAULT})
0053   add_simple_feature_info(${_NAME} ${_DESCRIPTION} ${_DEFAULT})
0054 endmacro()
0055 
0056 # Fetches git revision and branch from the source dir of the current build if possible.
0057 # Sets ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING and ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING variables.
0058 # If git information is not available but ${CMAKE_SOURCE_DIR}/GIT_VERSION file exists,
0059 # it is parsed. This file can be created by scripts while preparing tarballs and is
0060 # supposed to contain two lines: hash and branch.
0061 macro(get_git_revision_and_branch)
0062   set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING "")
0063   set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING "")
0064   get_git_head_revision(GIT_REFSPEC ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING)
0065   get_git_branch(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING)
0066   if(NOT ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING OR NOT ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING)
0067     if(EXISTS "${CMAKE_SOURCE_DIR}/GIT_VERSION")
0068       file(READ "${CMAKE_SOURCE_DIR}/GIT_VERSION" _ver)
0069       string(REGEX REPLACE "\n" ";" _ver "${_ver}")
0070       list(GET _ver 0 ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING)
0071       list(GET _ver 1 ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING)
0072     endif()
0073   endif()
0074   if(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING OR ${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING)
0075     string(SUBSTRING ${${PROJECT_NAME_UPPER}_GIT_SHA1_STRING} 0 7 ${PROJECT_NAME_UPPER}_GIT_SHA1_STRING)
0076   else()
0077     set(${PROJECT_NAME_UPPER}_GIT_SHA1_STRING "")
0078     set(${PROJECT_NAME_UPPER}_GIT_BRANCH_STRING "")
0079   endif()
0080 endmacro()
0081 
0082 # Adds BUILD_TESTING option to enable all kinds of tests. If enabled, build in autotests/
0083 # and tests/ subdirectory is enabled. IF optional argument ARG1 is ON, building tests will
0084 # be ON by default. Otherwise building tests will be OFF. ARG1 is OFF by default.
0085 # If tests are OFF, BUILD_COVERAGE is set to OFF.
0086 # If tests are on BUILD_TESTING macro is defined.
0087 macro(add_tests)
0088   if (NOT "${ARG1}" STREQUAL "ON")
0089     set(_SET OFF)
0090   endif()
0091   simple_option(BUILD_TESTING "Build tests" ${_SET}) # override default from CTest.cmake
0092   if(BUILD_TESTING)
0093     add_definitions(-DBUILD_TESTING)
0094     include(CTest)
0095     if (EXISTS ${CMAKE_SOURCE_DIR}/autotests)
0096         add_subdirectory(autotests)
0097     endif()
0098     if (EXISTS ${CMAKE_SOURCE_DIR}/tests)
0099         add_subdirectory(tests)
0100     endif()
0101   else()
0102     if (BUILD_COVERAGE)
0103       set(BUILD_COVERAGE OFF)
0104       message(STATUS "Building with gcov support disabled because BUILD_TESTING is OFF")
0105     endif()
0106   endif()
0107 endmacro()
0108 
0109 # Adds BUILD_EXAMPLES option to enable examples. If enabled, build in examples/ subdirectory
0110 # is enabled. If optional argument ARG1 is ON, building examples will be ON by default.
0111 # Otherwise building examples will be OFF. ARG1 is OFF by default.
0112 macro(add_examples)
0113   set(_SET ${ARGV0})
0114   if (NOT "${_SET}" STREQUAL ON)
0115     set(_SET OFF)
0116   endif()
0117   simple_option(BUILD_EXAMPLES "Build example applications" ${_SET})
0118   if (BUILD_EXAMPLES AND EXISTS ${CMAKE_SOURCE_DIR}/examples)
0119     add_subdirectory(examples)
0120   endif()
0121 endmacro()
0122 
0123 # Adds ${PROJECT_NAME_UPPER}_UNFINISHED option. If it is ON, unfinished features
0124 # (useful for testing but may confuse end-user) are compiled-in.
0125 # This option is OFF by default.
0126 macro(add_unfinished_features_option)
0127   string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
0128   simple_option(${PROJECT_NAME_UPPER}_UNFINISHED
0129                 "Include unfinished features (useful for testing but may confuse end-user)" OFF)
0130 endmacro()
0131 
0132 # Sets detailed version information for library co-installability.
0133 # - adds PROJECT_STABLE_VERSION_MAJOR to the lib name
0134 # - sets VERSION to PROJECT_STABLE_VERSION_MAJOR.PROJECT_STABLE_VERSION_MINOR.PROJECT_STABLE_VERSION_PATCH
0135 # - sets SOVERSION to PROJECT_STABLE_VERSION_MAJOR
0136 #        (special case for 3.0 < PROJECT_STABLE_VERSION < 4.0: sets SOVERSION to PROJECT_STABLE_VERSION_MAJOR + 1
0137 #         to separate from incompatible version 3.0)
0138 # - sets ${_target_upper}_BASE_NAME variable to the final lib name
0139 # - sets ${_target_upper}_BASE_NAME_LOWER variable to the final lib name, lowercase
0140 # - sets ${_target_upper}_INCLUDE_INSTALL_DIR to include dir for library headers
0141 # - (where _target_upper is uppercase ${_target}
0142 macro(set_coinstallable_lib_version _target)
0143     set(_name ${_target}${PROJECT_STABLE_VERSION_MAJOR})
0144     set(_soversion ${PROJECT_STABLE_VERSION_MAJOR})
0145     if(${PROJECT_STABLE_VERSION_MAJOR} EQUAL 3)
0146         math(EXPR _soversion "${PROJECT_STABLE_VERSION_MAJOR} + 1")
0147         math(EXPR _version "${PROJECT_STABLE_VERSION_MAJOR} + 1")
0148     else()
0149         set(_soversion ${PROJECT_STABLE_VERSION_MAJOR})
0150     endif()
0151     set(_version "${_version}.${PROJECT_STABLE_VERSION_MINOR}.${PROJECT_STABLE_VERSION_PATCH}")
0152     set_target_properties(${_target}
0153         PROPERTIES VERSION ${_version}
0154                    SOVERSION ${_soversion}
0155                    EXPORT_NAME ${_target}
0156                    OUTPUT_NAME ${_name}
0157     )
0158     string(TOUPPER ${_target} _target_upper)
0159     string(TOUPPER ${_target_upper}_BASE_NAME _var)
0160     set(${_var} ${_name})
0161     string(TOLOWER ${_name} ${_var}_LOWER)
0162     set(${_target_upper}_INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/${_name})
0163     unset(_soversion)
0164     unset(_version)
0165     unset(_target_upper)
0166     unset(_var)
0167 endmacro()
0168 
0169 # Adds custom target ${_target} that updates file ${_file} in the current working dir
0170 # using command ${_command} and add sources ${_sources} to the project files.
0171 # The command is run as a part of the project.
0172 function(add_update_file_target)
0173     set(options)
0174     set(oneValueArgs TARGET FILE)
0175     set(multiValueArgs COMMAND SOURCES)
0176     cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
0177     add_custom_target(${ARG_TARGET}
0178         COMMAND ${ARG_COMMAND}
0179         SOURCES ${ARG_SOURCES}
0180         DEPENDS ${ARG_SOURCES}
0181         WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
0182         COMMENT "Updating ${ARG_FILE}"
0183         VERBATIM
0184     )
0185 endfunction()
0186 
0187 # By default the QMessageLogContext class provides additional log information (file, line, function)
0188 # only in Debug builds (this includes RelWithDebInfo). For Release builds these values appear as "unknown".
0189 # To override this QT_MESSAGELOGCONTEXT should be explicitly defined.
0190 # See http://doc.qt.io/qt-5/qmessagelogcontext.html
0191 add_definitions(-DQT_MESSAGELOGCONTEXT)