Skip to content

Commit

Permalink
💥 Only allow clang-tidy version 15 or above
Browse files Browse the repository at this point in the history
This should resolve the clang-14 chrono issue that seems to have popped
up out of nowhere. This repo made the same change:

intel/compile-time-init-build@f8c3642
  • Loading branch information
Khalil Estell authored and kammce committed Nov 1, 2023
1 parent ce9c5af commit fc91f21
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 21 deletions.
61 changes: 41 additions & 20 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an "AS IS"BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Expand All @@ -18,30 +18,51 @@ include(CheckCXXCompilerFlag)
# manger) puts it.
set(LIBHAL_SCRIPT_PATH ${CMAKE_CURRENT_LIST_DIR})

# Check if clang-tidy exists on the system and if so, evaluate each file
# against
find_program(LIBHAL_CLANG_TIDY_PROGRAM NAMES "clang-tidy")

# If ti exists, add it as an additional check for each source file
if(DEFINED LIBHAL_CLANG_TIDY_PROGRAM)
message(STATUS "LIBHAL: clang-tidy AVAILABLE!")
set(LIBHAL_CLANG_TIDY_CONFIG_FILE
"${LIBHAL_SCRIPT_PATH}/clang-tidy.conf")
set(LIBHAL_CLANG_TIDY "${LIBHAL_CLANG_TIDY_PROGRAM}"
"--config-file=${LIBHAL_CLANG_TIDY_CONFIG_FILE}")
# Colored LIBHAL text
set(LIBHAL_TITLE "${BoldMagenta}[LIBHAL]:${ColourReset}")

# Find clang-tidy
find_program(LIBHAL_CLANG_TIDY_PROGRAM NAMES "clang-tidy" DOC
"Path to clang-tidy executable")

if(NOT LIBHAL_CLANG_TIDY_PROGRAM)
message(STATUS "${LIBHAL_TITLE} clang-tidy not found.")
else()
message(WARNING
"LIBHAL:'clang-tidy' program is NOT available! Install it to run checks!")
endif(DEFINED LIBHAL_CLANG_TIDY_PROGRAM)
# Execute clang-tidy --version and parse the output
execute_process(
COMMAND ${LIBHAL_CLANG_TIDY_PROGRAM} --version
OUTPUT_VARIABLE clang_tidy_version_output
)

# Regex to extract version number
string(REGEX MATCH ".* version ([0-9]+)\\.([0-9]+)\\.([0-9]+)"
_
${clang_tidy_version_output})
set(clang_tidy_major_version ${CMAKE_MATCH_1})
set(clang_tidy_minor_version ${CMAKE_MATCH_2})
set(clang_tidy_patch_version ${CMAKE_MATCH_3})

# Check if version is 15 or higher
if(clang_tidy_major_version LESS 15)
message(WARNING "clang-tidy version is too old. Version 15 or newer is required. Found: ${clang_tidy_major_version}.${clang_tidy_minor_version}.${clang_tidy_patch_version}")
else()
# Set clang-tidy as a CXX language standard option
set(CMAKE_CXX_CLANG_TIDY ${LIBHAL_CLANG_TIDY_PROGRAM})
message(STATUS "${LIBHAL_TITLE} clang-tidy version ${clang_tidy_major_version}.${clang_tidy_minor_version}.${clang_tidy_patch_version} AVAILABLE!")
set(LIBHAL_CLANG_TIDY_CONFIG_FILE
"${LIBHAL_SCRIPT_PATH}/clang-tidy.conf")
set(LIBHAL_CLANG_TIDY "${LIBHAL_CLANG_TIDY_PROGRAM}"
"--config-file=${LIBHAL_CLANG_TIDY_CONFIG_FILE}")
endif()
endif()

# Adds clang tidy check to target for host builds (skipped if a cross build)
function(_libhal_add_clang_tidy_check TARGET)
if(NOT ${CMAKE_CROSSCOMPILING})
set_target_properties(${TARGET} PROPERTIES CXX_CLANG_TIDY
"${LIBHAL_CLANG_TIDY}")
else()
message(STATUS
"LIBHAL: Cross compiling, skipping clang-tidy checks for \"${TARGET}\"")
message(STATUS "${LIBHAL_TITLE} Cross compiling, skipping clang-tidy checks for \"${TARGET}\"")
endif()
endfunction()

Expand Down Expand Up @@ -122,11 +143,11 @@ function(libhal_unit_test)
endblock()

if(${ADDRESS_SANITIZER_SUPPORT})
message(STATUS "LIBHAL: Address Sanitizer available! Using it for tests!")
message(STATUS "${LIBHAL_TITLE} Address Sanitizer available! Using it for tests!")
target_compile_options(unit_test PRIVATE -fsanitize=address)
target_link_options(unit_test PRIVATE -fsanitize=address)
else()
message(STATUS "LIBHAL: Address Sanitizer not supported!")
message(STATUS "${LIBHAL_TITLE} Address Sanitizer not supported!")
endif(${ADDRESS_SANITIZER_SUPPORT})

_libhal_add_clang_tidy_check(unit_test)
Expand Down Expand Up @@ -254,7 +275,7 @@ function(libhal_build_demos)

foreach(demo ${DEMO_ARGS_DEMOS})
set(elf ${demo}.elf)
message(STATUS "LIBHAL: Generating Demo for \"${elf}\"")
message(STATUS "${LIBHAL_TITLE} Generating Demo for \"${elf}\"")
add_executable(${elf} ${CMAKE_SOURCE_DIR}/applications/${demo}.cpp)
target_compile_features(${elf} PRIVATE cxx_std_20)
target_include_directories(${elf} PUBLIC ${DEMO_ARGS_INCLUDES})
Expand Down
33 changes: 33 additions & 0 deletions cmake/colors.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
9 changes: 8 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class libhal_cmake_util_conan(ConanFile):
name = "libhal-cmake-util"
version = "2.2.0"
version = "3.0.0"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://libhal.github.io/libhal-armcortex"
Expand Down Expand Up @@ -63,6 +63,8 @@ def package_info(self):
self.package_folder, "cmake/optimize_debug_build.cmake")
build_path = os.path.join(
self.package_folder, "cmake/build.cmake")
colors_path = os.path.join(
self.package_folder, "cmake/colors.cmake")
clang_tidy_config_path = os.path.join(
self.package_folder, "cmake/clang-tidy.conf")

Expand All @@ -76,10 +78,15 @@ def package_info(self):
"tools.cmake.cmaketoolchain:user_toolchain",
optimize_debug_build_path)

self.conf_info.append(
"tools.cmake.cmaketoolchain:user_toolchain",
colors_path)

self.conf_info.append(
"tools.cmake.cmaketoolchain:user_toolchain",
build_path)


self.output.info(
f"clang_tidy_config_path: {clang_tidy_config_path}")
self.output.info(
Expand Down

0 comments on commit fc91f21

Please sign in to comment.