Warning, /utilities/telly-skout/QmlFormat.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2022 Plata Hill <plata.hill@kdemail.net> 0002 # SPDX-License-Identifier: BSD-2-Clause 0003 0004 #[=======================================================================[.rst: 0005 QmlFormat 0006 -------------------- 0007 0008 This module provides a functionality to format the qml 0009 code of your repository according to the QML Coding Conventions. 0010 0011 This module provides the following function: 0012 0013 :: 0014 0015 qml_format(<files>) 0016 0017 Using this function will create a qml-format target that will format all 0018 ``<files>`` passed to the function according to the QML Coding Conventions. 0019 To format the files you have to invoke the target with ``make qml-format`` or ``ninja qml-format``. 0020 Once the project is formatted, it is recommended to enforce the formatting using a pre-commit hook, 0021 this can be done using :kde-module:`KDEGitCommitHooks`. 0022 0023 Example usage: 0024 0025 .. code-block:: cmake 0026 0027 include(QmlFormat) 0028 file(GLOB_RECURSE ALL_QML_FORMAT_SOURCE_FILES *.qml) 0029 qml_format(${ALL_QML_FORMAT_SOURCE_FILES}) 0030 0031 #]=======================================================================] 0032 0033 # try to find qml-format in path 0034 find_program(QML_FORMAT_EXECUTABLE qmlformat) 0035 0036 # formatting target 0037 function(QML_FORMAT) 0038 if (TARGET qml-format) 0039 message(WARNING "the qml_format function was already called") 0040 return() 0041 endif() 0042 0043 # add target without specific commands first, we add the real calls file-per-file to avoid command line length issues 0044 add_custom_target(qml-format COMMENT "Formatting qml files in ${CMAKE_CURRENT_SOURCE_DIR} with ${QML_FORMAT_EXECUTABLE}...") 0045 0046 # run qml-format only if available, else signal the user what is missing 0047 if(QML_FORMAT_EXECUTABLE) 0048 get_filename_component(_binary_dir ${CMAKE_BINARY_DIR} REALPATH) 0049 foreach(_file ${ARGV}) 0050 # check if the file is inside the build directory => ignore such files 0051 get_filename_component(_full_file_path ${_file} REALPATH) 0052 string(FIND ${_full_file_path} ${_binary_dir} _index) 0053 if(NOT _index EQUAL 0) 0054 add_custom_command(TARGET qml-format 0055 COMMAND 0056 ${QML_FORMAT_EXECUTABLE} 0057 -i 0058 ${_full_file_path} 0059 WORKING_DIRECTORY 0060 ${CMAKE_CURRENT_SOURCE_DIR} 0061 COMMENT 0062 "Formatting ${_full_file_path}..." 0063 ) 0064 endif() 0065 endforeach() 0066 else() 0067 add_custom_command(TARGET qml-format 0068 COMMAND 0069 ${CMAKE_COMMAND} -E echo "Could not set up the qml-format target as the qml-format executable is missing." 0070 ) 0071 endif() 0072 endfunction()