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