1# 2# Arm SCP/MCP Software 3# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. 4# 5# SPDX-License-Identifier: BSD-3-Clause 6# 7 8#[=======================================================================[.rst: 9FindCMakeFormat 10--------------- 11 12Finds cmake-format, the suite of quality assurance tools for CMake source files. 13 14Use this module by invoking ``find_package`` with the form:: 15 16 find_package(CMakeFormat [REQUIRED] [COMPONENTS <component>...] 17 [OPTIONAL_COMPONENTS <component>...]) 18 19This module supports the following components: 20 21* ``Format``: Locate ``cmake-format``, the CMake formatter. 22* ``Lint``: Locate ``cmake-lint``, the CMake linter. 23 24Imported Targets 25^^^^^^^^^^^^^^^^ 26 27``CMakeFormat::Format`` 28 ``cmake-format``. Target defined if component ``Format`` is found. 29 30``CMakeFormat::Lint`` 31 ``cmake-lint``. Target defined if component ``Lint`` is found. 32 33Result Variables 34^^^^^^^^^^^^^^^^ 35 36``CMakeFormat_FOUND`` 37 If false, none of the requested components were found. 38 39``CMakeFormat_Format_FOUND`` 40 If false, ``cmake-format`` was not found. 41 42``CMakeFormat_Format_EXECUTABLE`` 43 The full path to ``cmake-format``. 44 45``CMakeFormat_Lint_FOUND`` 46 If false, ``cmake-lint`` was not found. 47 48``CMakeFormat_Lint_EXECUTABLE`` 49 The full path to ``cmake-lint``. 50#]=======================================================================] 51 52include_guard() 53 54# cmake-lint: disable=C0103 55 56find_program(CMakeFormat_Format_EXECUTABLE "cmake-format") 57find_program(CMakeFormat_Lint_EXECUTABLE "cmake-lint") 58 59if(CMakeFormat_Format_EXECUTABLE) 60 set(CMakeFormat_Format_FOUND TRUE) 61 62 mark_as_advanced(CMakeFormat_Format_EXECUTABLE) 63 64 add_executable(CMakeFormat::Format IMPORTED) 65 66 set_target_properties( 67 CMakeFormat::Format 68 PROPERTIES IMPORTED_LOCATION "${CMakeFormat_Format_EXECUTABLE}") 69endif() 70 71if(CMakeFormat_Lint_EXECUTABLE) 72 set(CMakeFormat_Lint_FOUND TRUE) 73 74 mark_as_advanced(CMakeFormat_Lint_EXECUTABLE) 75 76 add_executable(CMakeFormat::Lint IMPORTED) 77 78 set_target_properties( 79 CMakeFormat::Lint 80 PROPERTIES IMPORTED_LOCATION "${CMakeFormat_Lint_EXECUTABLE}") 81endif() 82 83include(FindPackageHandleStandardArgs) 84 85find_package_handle_standard_args(CMakeFormat HANDLE_COMPONENTS) 86