From 0e1a0b97edb280f3e377afb227649d594e217bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Wed, 13 Apr 2022 20:56:07 +0200 Subject: [PATCH] added make targets `checkCWEEntries`, `validateXML` and `validateRules` to CMake (#4010) --- CMakeLists.txt | 22 +++++++++++++++++++++- cmake/findDependencies.cmake | 16 ++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a65938d2d..edc824ad7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,6 @@ file(GLOB addons "addons/*.py") file(GLOB cfgs "cfg/*.cfg") file(GLOB platforms "platforms/*.xml") -find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint) if (LIBXML2_XMLLINT_EXECUTABLE) add_custom_target(validateCFG ${LIBXML2_XMLLINT_EXECUTABLE} --noout ${CMAKE_SOURCE_DIR}/cfg/cppcheck-cfg.rng) foreach(cfg ${cfgs}) @@ -31,6 +30,27 @@ if (LIBXML2_XMLLINT_EXECUTABLE) add_custom_target(validateCFG-${cfgname} ${LIBXML2_XMLLINT_EXECUTABLE} --noout --relaxng ${CMAKE_SOURCE_DIR}/cfg/cppcheck-cfg.rng ${cfg}) add_dependencies(validateCFG validateCFG-${cfgname}) endforeach() + + add_custom_target(errorlist-xml $ --errorlist > ${CMAKE_BINARY_DIR}/errorlist.xml + DEPENDS cppcheck) + + add_custom_target(example-xml $ --xml --enable=all --inconclusive --max-configs=1 ${CMAKE_SOURCE_DIR}/samples 2> ${CMAKE_BINARY_DIR}/example.xml + DEPENDS cppcheck) + + add_custom_target(createXMLExamples DEPENDS errorlist-xml example-xml) + + if (PYTHON_EXECUTABLE) + add_custom_target(checkCWEEntries ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/listErrorsWithoutCWE.py -F ${CMAKE_BINARY_DIR}/errorlist.xml + DEPENDS errorlist-xml) + endif() + + add_custom_target(validateXML ${LIBXML2_XMLLINT_EXECUTABLE} --noout ${CMAKE_SOURCE_DIR}/cppcheck-errors.rng + COMMAND ${LIBXML2_XMLLINT_EXECUTABLE} --noout --relaxng ${CMAKE_SOURCE_DIR}/cppcheck-errors.rng ${CMAKE_BINARY_DIR}/errorlist.xml + COMMAND ${LIBXML2_XMLLINT_EXECUTABLE} --noout --relaxng ${CMAKE_SOURCE_DIR}/cppcheck-errors.rng ${CMAKE_BINARY_DIR}/example.xml + DEPENDS createXMLExamples + ) + + add_custom_target(validateRules ${LIBXML2_XMLLINT_EXECUTABLE} --noout ${CMAKE_SOURCE_DIR}/rules/*.xml) endif() if (BUILD_TESTS) diff --git a/cmake/findDependencies.cmake b/cmake/findDependencies.cmake index 918f3d5a5..49a7c0ee2 100644 --- a/cmake/findDependencies.cmake +++ b/cmake/findDependencies.cmake @@ -19,15 +19,13 @@ endif() set(CMAKE_INCLUDE_CURRENT_DIR ON) -if (NOT USE_MATCHCOMPILER_OPT MATCHES "Off") - find_package(PythonInterp 3 QUIET) +find_package(PythonInterp 3 QUIET) +if (NOT PYTHONINTERP_FOUND) + set(PYTHONINTERP_FOUND "") + find_package(PythonInterp 2.7 QUIET) if (NOT PYTHONINTERP_FOUND) - set(PYTHONINTERP_FOUND "") - find_package(PythonInterp 2.7 QUIET) - if (NOT PYTHONINTERP_FOUND) - message(WARNING "No python interpreter found. Therefore, the match compiler is switched off.") - set(USE_MATCHCOMPILER_OPT "Off") - endif() + message(WARNING "No python interpreter found. Therefore, the match compiler is switched off.") + set(USE_MATCHCOMPILER_OPT "Off") endif() endif() @@ -52,3 +50,5 @@ endif() if (USE_BOOST) find_package(Boost COMPONENTS container QUIET) endif() + +find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)