Warning, /frameworks/extra-cmake-modules/kde-modules/KDEPackageAppTemplates.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0002 # SPDX-FileCopyrightText: 2014 Simon Wächter <waechter.simon@gmail.com> 0003 # SPDX-FileCopyrightText: 2013 Nico Kruber <nico.kruber@gmail.com> 0004 # SPDX-FileCopyrightText: 2012 Jeremy Whiting <jpwhiting@kde.org> 0005 # 0006 # SPDX-License-Identifier: BSD-3-Clause 0007 0008 #[=======================================================================[.rst: 0009 KDEPackageAppTemplates 0010 ---------------------- 0011 0012 Packages KApptemplate/KDevelop compatible application templates 0013 0014 This module provides a functionality to package in a tarball and 0015 install project templates compatible with the format used by 0016 KApptemplate and KDevelop. Useful for providing minimal examples 0017 for the usage of the KDE Frameworks. 0018 0019 This module provides the following function: 0020 0021 :: 0022 0023 kde_package_app_templates(TEMPLATES <template> [<template> [...]] 0024 INSTALL_DIR <directory>) 0025 0026 ``INSTALL_DIR`` is the directory to install the template package to. 0027 In most cases you will want to use the variable ``KDE_INSTALL_KAPPTEMPLATESDIR`` 0028 from :kde-module:`KDEInstallDirs`. 0029 0030 ``TEMPLATES`` lists subdirectories containing template files; 0031 each ``<template>`` directory will be packaged into a file named 0032 ``<template>.tar.bz2`` and installed to the appropriate location. 0033 0034 The template is a minimal source tree of an application as if it was 0035 an application project by itself, with names (file names or text inside) 0036 the text files replaced by the following placeholders when needed: 0037 0038 ``%{PROJECTDIRNAME}`` 0039 name of generated project base folder ex: ``%{APPNAMELC}`` for KAppTemplate 0040 ``%{APPNAME}`` 0041 project name as entered by user ex: MyKApp 0042 ``%{APPNAMELC}`` 0043 project name in lower case ex: mykapp 0044 ``%{APPNAMEUC}`` 0045 project name in upper case ex: MYKAPP 0046 0047 ``%{CPP_TEMPLATE}`` 0048 license header for cpp file 0049 ``%{H_TEMPLATE}`` 0050 license header for h file 0051 0052 ``%{AUTHOR}`` 0053 author name ex: George Ignacious 0054 ``%{EMAIL}`` 0055 author email ex: foo@bar.org 0056 ``%{VERSION}`` 0057 project version ex: 0.1 0058 0059 Deprecated: 0060 0061 ``%{dest}`` 0062 path of generated project base folder, used in .kdevtemplate with the ``ShowFilesAfterGeneration`` entry 0063 KDevelop >= 5.1.1 supports relative paths with that entry, making this placeholder obsolete 0064 0065 Multiple templates can be passed at once. 0066 0067 0068 Since 5.18 0069 #]=======================================================================] 0070 0071 function(kde_package_app_templates) 0072 set(_oneValueArgs INSTALL_DIR) 0073 set(_multiValueArgs TEMPLATES) 0074 cmake_parse_arguments(ARG "" "${_oneValueArgs}" "${_multiValueArgs}" ${ARGN} ) 0075 0076 if(NOT ARG_TEMPLATES) 0077 message(FATAL_ERROR "No TEMPLATES argument given to kde_package_app_templates") 0078 endif() 0079 0080 if(NOT ARG_INSTALL_DIR) 0081 message(FATAL_ERROR "No INSTALL_DIR argument given to kde_package_app_templates") 0082 endif() 0083 0084 find_program(_tar_executable NAMES gtar tar) 0085 if(_tar_executable) 0086 # NOTE: we also pass `--sort=name` here to check if the tar exe supports that 0087 # this feature was only added in gnu tar v1.28 0088 execute_process( 0089 COMMAND ${_tar_executable} --sort=name --version 0090 TIMEOUT 3 0091 RESULT_VARIABLE _tar_exit 0092 OUTPUT_VARIABLE _tar_version 0093 ERROR_VARIABLE _tar_stderr 0094 ) 0095 if("${_tar_exit}" EQUAL 0 AND "${_tar_version}" MATCHES "GNU tar") 0096 set(GNU_TAR_FOUND ON) 0097 else() 0098 set(GNU_TAR_FOUND OFF) 0099 endif() 0100 else() 0101 set(GNU_TAR_FOUND OFF) 0102 endif() 0103 0104 foreach(_templateName ${ARG_TEMPLATES}) 0105 get_filename_component(_tmp_file ${_templateName} ABSOLUTE) 0106 get_filename_component(_baseName ${_tmp_file} NAME_WE) 0107 set(_template ${CMAKE_CURRENT_BINARY_DIR}/${_baseName}.tar.bz2) 0108 0109 # also enlist directories as deps to catch file removals 0110 file(GLOB_RECURSE _subdirs_entries LIST_DIRECTORIES true CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${_templateName}/*") 0111 0112 add_custom_target(${_baseName}_kapptemplate ALL DEPENDS ${_template}) 0113 0114 if(GNU_TAR_FOUND) 0115 # Honour SOURCE_DATE_EPOCH if set 0116 if(DEFINED ENV{SOURCE_DATE_EPOCH}) 0117 set(TIMESTAMP $ENV{SOURCE_DATE_EPOCH}) 0118 else() 0119 execute_process( 0120 COMMAND "date" "+%s" 0121 OUTPUT_VARIABLE TIMESTAMP 0122 OUTPUT_STRIP_TRAILING_WHITESPACE) 0123 endif() 0124 0125 # Make tar archive reproducible, the arguments are only available with GNU tar 0126 add_custom_command(OUTPUT ${_template} 0127 COMMAND ${_tar_executable} ARGS 0128 --exclude .kdev_ignore --exclude .svn 0129 --sort=name 0130 --mode=go=rX,u+rw,a-s 0131 --numeric-owner --owner=0 --group=0 0132 --mtime="@${TIMESTAMP}" 0133 --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime 0134 -c -j -f ${_template} . 0135 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_templateName} 0136 DEPENDS ${_subdirs_entries} 0137 ) 0138 else() 0139 add_custom_command(OUTPUT ${_template} 0140 COMMAND ${CMAKE_COMMAND} -E tar "cvfj" ${_template} . 0141 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_templateName} 0142 DEPENDS ${_subdirs_entries} 0143 ) 0144 endif() 0145 0146 install(FILES ${_template} DESTINATION ${ARG_INSTALL_DIR}) 0147 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${_template}") 0148 0149 endforeach() 0150 endfunction()