agones.dev/agones@v1.53.0/sdks/cpp/cmake/clang-verify.in (about)

     1  # Copyright 2019 Google LLC All Rights Reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  cmake_minimum_required(VERSION 3.15)
    16  
    17  option(AGONES_SILENT_OUTPUT "Show only warnings/error messages" OFF)
    18  if (AGONES_SILENT_OUTPUT)
    19      function(message)
    20          list(GET ARGV 0 MessageType)
    21          list(REMOVE_AT ARGV 0)
    22          if (MessageType STREQUAL FATAL_ERROR OR
    23              MessageType STREQUAL SEND_ERROR OR
    24              MessageType STREQUAL WARNING OR
    25              MessageType STREQUAL AUTHOR_WARNING OR
    26              NOT ${AGONES_SILENT_OUTPUT}
    27              )
    28              _message(${MessageType} "${ARGV}")
    29          endif()
    30      endfunction()
    31  
    32      set(CMAKE_INSTALL_MESSAGE NEVER)
    33      set(CMAKE_VERBOSE_MAKEFILE OFF)
    34      set_property(GLOBAL PROPERTY RULE_MESSAGES OFF)
    35      set_property(GLOBAL PROPERTY TARGET_MESSAGES OFF)
    36  endif(AGONES_SILENT_OUTPUT)
    37  
    38  set(files @CLANGFORMAT_INPUT@)
    39  set(workingdir @CLANGFORMAT_WORKING_DIR@)
    40  set(root @AGONES_ROOT@)
    41  set(temp @AGONES_TEMP@)
    42  
    43  find_package(Git REQUIRED)
    44  find_program(
    45      CLANG_FORMAT_APP
    46      NAMES "clang-format"
    47      DOC "Path to clang-format"
    48  )
    49  if (NOT CLANG_FORMAT_APP)
    50      message(FATAL_ERROR "Could not find clang-format")
    51  endif()
    52  
    53  file(MAKE_DIRECTORY ${temp})
    54  foreach(source_file ${files})
    55      file(COPY ${source_file} DESTINATION ${temp})
    56      file(RELATIVE_PATH source_relative ${root} ${source_file})
    57      get_filename_component(filename ${source_file} NAME ABSOLUTE)
    58      get_filename_component(source_file_temp "${temp}/${filename}" ABSOLUTE)
    59  
    60      execute_process(
    61          COMMAND ${CLANG_FORMAT_APP} -i --style=file --fallback-style=Google ${source_file_temp}
    62          WORKING_DIRECTORY ${workingdir}
    63      )
    64      execute_process(
    65          COMMAND ${GIT_EXECUTABLE} diff --exit-code --quiet --no-index "${source_file}" "${source_file_temp}"
    66          WORKING_DIRECTORY ${root}
    67          RESULT_VARIABLE result
    68      )
    69      
    70      file(REMOVE ${source_file_temp})
    71      if (NOT ${result} EQUAL 0)
    72          message(FATAL_ERROR "clang-format code style check failed for: ${source_relative}")
    73      endif()
    74  endforeach()