json/tests/clang_tidy_plugin/CMakeLists.txt
Mike Crowe 4eda97d6bb Add clang-tidy plugin for modernize-nlohmann-json-explicit-conversions
Add a clang-tidy plugin containing one check to replace implicit
conversions (as enabled by default with JSON_USE_IMPLICIT_CONVERSIONS)
with explicit ones. This will make it easier for library users to switch
away from using implicit conversions which should make it possible for
the library to start disallowing them sooner.

Being able to test the plugin in a similar way to how checks are tested
within clang-tidy itself requires copying the check_clang_tidy.py script
from the LLVM code itself.

The check itself is virtually identical to the one proposed for
inclusion in clang-tidy itself at
https://github.com/llvm/llvm-project/pull/126425 .

Unfortunately it is necessary to add "C" to the languages for the
project in CMakeLists.txt for find_package to work for LLVM.

Signed-off-by: Mike Crowe <mac@mcrowe.com>
2025-02-23 19:28:47 +00:00

11 lines
502 B
CMake

include(CTest)
if(NOT LLVM_TOOLS_BINARY_DIR)
message(FATAL_ERROR "Could not determine LLVM binary directory")
endif()
add_test(NAME modernize-nlohmann-json-explicit-conversions-check COMMAND ${CMAKE_COMMAND} -E env PATH=${LLVM_TOOLS_BINARY_DIR}:$ENV{PATH}
${CMAKE_CURRENT_LIST_DIR}/check_clang_tidy.py -std=c++17
-plugin=$<TARGET_FILE:NlohmannJsonClangTidyPlugin>
${CMAKE_CURRENT_LIST_DIR}/modernize-nlohmann-json-explicit-conversions.cpp modernize-nlohmann-json-explicit-conversions temp)