Files
FairMQ/fairmq/tidy/CMakeLists.txt
Claude cbcd0d3324 refactor(tidy)!: rebuild fairmq-tidy on top of clang-tidy
- Implement the checks as a clang-tidy module (object library
  fairmq-tidy-module) instead of a standalone LibTooling program.
- Build fairmq-tidy from clangTidyMain plus the module. It gets all
  clang-tidy features: --fix, --export-fixes, .clang-tidy files, NOLINT,
  header filter, and the upstream checks on the same parse.
- Without a --checks option, add fairmq-* to the configured checks.
- Point the driver to the resource directory of the LLVM installation it
  was built with, so it finds the Clang builtin headers from any install
  location. The -I hint in fairmq_target_tidy() is no longer necessary.
- Add the include directories of LLVM and Clang. The old target compiled
  only where they are in /usr/include.
- Port fairmq-modernize-nonnamespaced-types. Match deprecated global
  aliases into fair::mq instead of the name prefix "FairMQ": this also
  finds e.g. InputMsgCallback and skips aliases that are not deprecated.
  Match only the TypedefTypeLoc, so each use is reported once.

BREAKING CHANGE: fairmq-tidy takes the options of clang-tidy and reads
.clang-tidy files. With no .clang-tidy file it now also runs the default
clang-tidy checks (clang-diagnostic-*, clang-analyzer-*).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 09:23:27 +00:00

63 lines
2.7 KiB
CMake

################################################################################
# Copyright (C) 2021-2026 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH #
# #
# This software is distributed under the terms of the #
# GNU Lesser General Public Licence (LGPL) version 3, #
# copied verbatim in the file "LICENSE" #
################################################################################
if(NOT TARGET clangTidy OR NOT TARGET clangTidyMain)
message(FATAL_ERROR "BUILD_TIDY_TOOL=ON needs the clang-tidy libraries "
"(clangTidy, clangTidyMain) of the found Clang ${LLVM_PACKAGE_VERSION} "
"installation at ${Clang_DIR}. Install the clang-tidy development package "
"(e.g. libclang-<version>-dev on Debian/Ubuntu).")
endif()
# The clang driver searches its builtin headers relative to the executable.
# Remember the resource directory of the LLVM installation that we build
# against, so that fairmq-tidy works from any install location.
foreach(candidate IN ITEMS "${LLVM_LIBRARY_DIR}/clang/${LLVM_VERSION_MAJOR}"
"${LLVM_LIBRARY_DIR}/clang/${LLVM_PACKAGE_VERSION}")
if(EXISTS "${candidate}/include/stddef.h")
set(FAIRMQ_TIDY_CLANG_RESOURCE_DIR "${candidate}"
CACHE PATH "Clang resource directory used by fairmq-tidy")
break()
endif()
endforeach()
if(NOT FAIRMQ_TIDY_CLANG_RESOURCE_DIR)
message(FATAL_ERROR "Cannot find the Clang resource directory below "
"${LLVM_LIBRARY_DIR}/clang. Set FAIRMQ_TIDY_CLANG_RESOURCE_DIR to the "
"output of `clang -print-resource-dir`.")
endif()
# The fairmq-* checks as a clang-tidy module.
add_library(fairmq-tidy-module OBJECT
Module.cxx
NonNamespacedTypesCheck.cxx
NonNamespacedTypesCheck.h
)
target_compile_features(fairmq-tidy-module PUBLIC cxx_std_17)
target_include_directories(fairmq-tidy-module
SYSTEM PUBLIC ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}
)
target_include_directories(fairmq-tidy-module PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
)
if(NOT LLVM_ENABLE_RTTI)
target_compile_options(fairmq-tidy-module PUBLIC -fno-rtti)
endif()
set_target_properties(fairmq-tidy-module PROPERTIES POSITION_INDEPENDENT_CODE ON)
# fairmq-tidy: the clang-tidy driver plus the fairmq-* checks.
set(target fairmq-tidy)
add_executable(${target} runTidy.cxx)
add_executable("${PROJECT_NAME}::${target}" ALIAS ${target})
target_compile_definitions(${target} PRIVATE
FAIRMQ_TIDY_CLANG_RESOURCE_DIR="${FAIRMQ_TIDY_CLANG_RESOURCE_DIR}"
)
target_link_libraries(${target} PRIVATE fairmq-tidy-module clangTidyMain)
install(TARGETS ${target}
EXPORT ${PROJECT_EXPORT_SET}
RUNTIME DESTINATION ${PROJECT_INSTALL_BINDIR}
)