Warning, /office/kexi/cmake/modules/KexiMacros.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(__kexi_macros) 0009 return() 0010 endif() 0011 set(__kexi_macros YES) 0012 0013 #unused: include(KDbCreateSharedDataClasses) # from KDb 0014 include(CheckFunctionExists) 0015 include(GenerateExportHeader) 0016 include(GetGitRevisionDescription) 0017 include(MacroBoolTo01) 0018 include(KexiAddSimpleOption) 0019 0020 string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) 0021 string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) 0022 string(COMPARE EQUAL "${CMAKE_CXX_COMPILER_ID}" "Clang" CMAKE_COMPILER_IS_CLANG) 0023 0024 # Keep apps in the same bin dir so resources that are kept relative to this dir can be found 0025 # without installing. 0026 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") 0027 0028 macro(ensure_out_of_source_build _extra_message) 0029 string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _isBuildInSource) 0030 if(isBuildInSource) 0031 message(FATAL_ERROR "Compiling ${PROJECT_NAME} inside the source directory is not possible. " 0032 "${_extra_message}") 0033 endif() 0034 unset(_isBuildInSource) 0035 endmacro() 0036 0037 # Sets RELEASE_BUILD to TRUE for release builds 0038 macro(detect_release_build) 0039 if(NOT DEFINED RELEASE_BUILD) 0040 # estimate mode by CMAKE_BUILD_TYPE content if not set on cmdline 0041 string(TOLOWER "${CMAKE_BUILD_TYPE}" _CMAKE_BUILD_TYPE_TOLOWER) 0042 set(_RELEASE_BUILD_TYPES "release" "relwithdebinfo" "minsizerel") 0043 list(FIND _RELEASE_BUILD_TYPES "${CMAKE_BUILD_TYPE_TOLOWER}" INDEX) 0044 if (INDEX EQUAL -1) 0045 set(RELEASE_BUILD FALSE) 0046 else() 0047 set(RELEASE_BUILD TRUE) 0048 endif() 0049 unset(_RELEASE_BUILD_TYPES) 0050 unset(_CMAKE_BUILD_TYPE_TOLOWER) 0051 endif() 0052 endmacro() 0053 0054 set(ICONS_INSTALL_DIR "${DATA_INSTALL_DIR}/${KEXI_BASE_PATH}/icons") 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 ${PROJECT_NAME_UPPER}_UNFINISHED option. If it is ON, unfinished features 0083 # (useful for testing but may confuse end-user) are compiled-in. 0084 # This option is OFF by default. 0085 macro(add_unfinished_features_option) 0086 simple_option(${PROJECT_NAME_UPPER}_UNFINISHED 0087 "Include unfinished features (useful for testing but may confuse end-user)" OFF) 0088 endmacro() 0089 0090 # Adds commands that generate ${_filename}${KEXI_DISTRIBUTION_VERSION}.pc file 0091 # out of ${_filename}.pc.cmake file and installs the .pc file to ${LIB_INSTALL_DIR}/pkgconfig. 0092 # These commands are not executed for WIN32. 0093 # ${CMAKE_SOURCE_DIR}/${_filename}.pc.cmake should exist. 0094 macro(add_pc_file _filename) 0095 if (NOT WIN32) 0096 set(_name ${_filename}${KEXI_DISTRIBUTION_VERSION}) 0097 configure_file(${CMAKE_SOURCE_DIR}/${_filename}.pc.cmake ${CMAKE_BINARY_DIR}/${_name}.pc @ONLY) 0098 install(FILES ${CMAKE_BINARY_DIR}/${_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) 0099 endif() 0100 endmacro() 0101 0102 # Sets detailed version information for library co-installability. 0103 # - adds PROJECT_STABLE_VERSION_MAJOR to the lib name 0104 # - sets VERSION to PROJECT_STABLE_VERSION_MAJOR.PROJECT_STABLE_VERSION_MINOR.PROJECT_STABLE_VERSION_RELEASE 0105 # - sets SOVERSION to KEXI_DISTRIBUTION_VERSION 0106 # - sets OUTPUT_NAME to ${_target}${KEXI_DISTRIBUTION_VERSION} 0107 # - sets ${_target_upper}_BASE_NAME variable to the final lib name 0108 # - sets ${_target_upper}_BASE_NAME_LOWER variable to the final lib name, lowercase 0109 # - sets ${_target_upper}_INCLUDE_INSTALL_DIR to include dir for library headers 0110 # - (where _target_upper is uppercase ${_target} 0111 macro(set_coinstallable_lib_version _target) 0112 set(_name ${_target}${KEXI_DISTRIBUTION_VERSION}) 0113 set(_version "${PROJECT_STABLE_VERSION_MAJOR}.${PROJECT_STABLE_VERSION_MINOR}.${PROJECT_STABLE_VERSION_RELEASE}") 0114 set(_soversion ${KEXI_DISTRIBUTION_VERSION}) 0115 set_target_properties(${_target} 0116 PROPERTIES VERSION ${_version} 0117 SOVERSION ${_soversion} 0118 EXPORT_NAME ${_target} 0119 OUTPUT_NAME ${_name} 0120 ) 0121 string(TOUPPER ${_target} _target_upper) 0122 string(TOUPPER ${_target_upper}_BASE_NAME _var) 0123 set(${_var} ${_name}) 0124 string(TOLOWER ${_name} ${_var}_LOWER) 0125 set(${_target_upper}_INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}/${_name}) 0126 unset(_soversion) 0127 unset(_version) 0128 unset(_target_upper) 0129 unset(_var) 0130 endmacro() 0131 0132 # Combines add_library() with set_coinstallable_lib_version() 0133 macro(kexi_add_library) 0134 set(args ${ARGV}) 0135 list(GET args 0 _target) 0136 add_library(${args}) 0137 set_coinstallable_lib_version(${_target}) 0138 unset(_target) 0139 endmacro() 0140 0141 # Sets detailed version information for executable co-installability. 0142 # - sets OUTPUT_NAME to ${_target}-${KEXI_DISTRIBUTION_VERSION} 0143 macro(set_coinstallable_executable_version _target) 0144 set_target_properties(${_target} 0145 PROPERTIES OUTPUT_NAME ${_target}-${KEXI_DISTRIBUTION_VERSION} 0146 ) 0147 endmacro() 0148 0149 # Combines add_executable() with set_coinstallable_executable_version() 0150 macro(kexi_add_executable) 0151 set(args ${ARGV}) 0152 list(GET args 0 _target) 0153 add_executable(${args}) 0154 set_coinstallable_executable_version(${_target}) 0155 unset(_target) 0156 endmacro() 0157 0158 # Adds custom target that updates given file in the current working dir using specified 0159 # command and adds its source files to the project files. 0160 # The target is not executed by default, if dependencies to/from other targets are needed 0161 # they can be set separately using add_dependencies(). 0162 # Execution of the command shows status "Updating <filename>". 0163 # Options: 0164 # TARGET - name of the new custom target 0165 # FILE - <filename> - name of the file that is updated using the command 0166 # COMMAND <cmd> [args...] - command to be executed 0167 # SOURCES [files...] - source files that are used by the command 0168 function(add_update_file_target) 0169 set(options) 0170 set(oneValueArgs TARGET FILE) 0171 set(multiValueArgs COMMAND SOURCES) 0172 cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) 0173 add_custom_target(${ARG_TARGET} 0174 COMMAND ${ARG_COMMAND} 0175 SOURCES ${ARG_SOURCES} 0176 DEPENDS ${ARG_SOURCES} 0177 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 0178 COMMENT "Updating ${ARG_FILE}" 0179 VERBATIM 0180 ) 0181 endfunction() 0182 0183 if(WIN32) 0184 set(_chmod_name attrib) 0185 else() 0186 set(_chmod_name chmod) 0187 endif() 0188 find_program(kexi_chmod_program ${_chmod_name} DOC "chmod program") 0189 if(kexi_chmod_program) 0190 message(STATUS "Found program for changing file permissions: ${kexi_chmod_program}") 0191 else() 0192 message(WARNING "Could not find \"${_chmod_name}\" program for changing file permissions") 0193 endif() 0194 0195 # Sets file or directory read-only for all (non-root) users. 0196 # The _path should exist. If it is not absolute, ${CMAKE_CURRENT_SOURCE_DIR} path is prepended. 0197 function(kexi_set_file_read_only _path) 0198 if(NOT kexi_chmod_program) 0199 return() 0200 endif() 0201 if(IS_ABSOLUTE ${_path}) 0202 set(_fullpath ${_path}) 0203 else() 0204 set(_fullpath ${CMAKE_CURRENT_SOURCE_DIR}/${_path}) 0205 endif() 0206 if(NOT EXISTS ${_fullpath}) 0207 message(FATAL_ERROR "File or directory \"${_fullpath}\" does not exist") 0208 return() 0209 endif() 0210 if(WIN32) 0211 set(_command "${kexi_chmod_program}" +R "${_fullpath}") 0212 else() 0213 set(_command "${kexi_chmod_program}" a-w "${_fullpath}") 0214 endif() 0215 execute_process( 0216 COMMAND ${_command} 0217 RESULT_VARIABLE _result 0218 OUTPUT_VARIABLE _output 0219 ERROR_VARIABLE _output 0220 ) 0221 if(NOT _result EQUAL 0) 0222 message(FATAL_ERROR "Command failed (${_result}): ${_command}\n\nOutput:\n${_output}") 0223 endif() 0224 endfunction() 0225 0226 # Adds example KEXI project (.kexi file) 0227 # - sets it read-only in the source directory 0228 # - installs to ${KEXI_EXAMPLES_INSTALL_DIR} as read-only for everyone 0229 macro(kexi_add_example_project _path) 0230 #DISABLED - source code should not be modified even regarding the read-only flag 0231 #TODO: port the shell scripts from src/examples to cmake to generate .kexi file(s) 0232 # into build dirs and remove the .kexi example files from git. Keep .kexi.sql only in git. 0233 #kexi_set_file_read_only(${_path}) 0234 0235 install(FILES ${_path} DESTINATION ${KEXI_EXAMPLES_INSTALL_DIR} 0236 PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) 0237 endmacro()