100 lines
3.3 KiB
CMake
100 lines
3.3 KiB
CMake
|
#
|
||
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
||
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||
|
#
|
||
|
option(CODECHECKER "Turns on codecheck processing if it is found." OFF)
|
||
|
option(CODECHECKER_STORE "Store results on central codechecker server" OFF)
|
||
|
option(CODECHECKER_RUN "Name of the codechecker run" "run-1")
|
||
|
option(CODECHECKER_URL "URL and product link to codechecker server" "http://localhost:8001/Default")
|
||
|
|
||
|
find_program(CODECHECKER_VENV_PATH
|
||
|
NAME activate
|
||
|
PATHS ~/Apps/codechecker/venv/bin/
|
||
|
~/codechecker/venv/bin/
|
||
|
/usr/src/codechecker/venv/bin/
|
||
|
)
|
||
|
|
||
|
find_program(CODECHECKER_PATH
|
||
|
NAME CodeChecker
|
||
|
PATHS ~/Apps/codechecker/build/CodeChecker/bin/
|
||
|
~/codechecker/build/CodeChecker/bin/
|
||
|
/usr/src/~/codechecker/build/CodeChecker/bin/
|
||
|
)
|
||
|
|
||
|
|
||
|
execute_process(
|
||
|
COMMAND git rev-parse --abbrev-ref HEAD
|
||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||
|
OUTPUT_VARIABLE CODECHECK_GIT_BRANCH
|
||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||
|
)
|
||
|
|
||
|
|
||
|
|
||
|
if (CODECHECKER_PATH AND CODECHECKER_VENV_PATH)
|
||
|
message(STATUS "CodeChecker found")
|
||
|
else()
|
||
|
message(STATUS "CodeChecker not found")
|
||
|
endif()
|
||
|
|
||
|
# export compile commands to json file to be used by atom c++ ide (clangd)
|
||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||
|
set(CODECHECKER_COMPILE_COMMANDS "${CMAKE_BINARY_DIR}/compile_commands.json")
|
||
|
|
||
|
# check if a skip file exists
|
||
|
if(EXISTS ${CMAKE_SOURCE_DIR}/codecheck.skip)
|
||
|
set(CODECHECKER_SKIP "-i${CMAKE_SOURCE_DIR}/codecheck.skip")
|
||
|
endif()
|
||
|
|
||
|
|
||
|
# output directory for codecheck analysis
|
||
|
set(CODECHECKER_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/codechecker_results)
|
||
|
|
||
|
# html output directory
|
||
|
set(CODECHECKER_HTML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/codechecker_html)
|
||
|
|
||
|
# Common initialization/checks
|
||
|
if(CODECHECKER AND CODECHECKER_PATH AND CODECHECKER_VENV_PATH AND NOT CODECHECKER_ADDED)
|
||
|
set(CODECHECKER_ADDED ON)
|
||
|
|
||
|
add_custom_target(codechecker
|
||
|
COMMAND . ${CODECHECKER_VENV_PATH}\;
|
||
|
${CODECHECKER_PATH}
|
||
|
analyze
|
||
|
${CODECHECKER_SKIP}
|
||
|
-e sensitive
|
||
|
-j 4
|
||
|
-o ${CODECHECKER_OUTPUT_DIRECTORY}
|
||
|
${CODECHECKER_COMPILE_COMMANDS}
|
||
|
)
|
||
|
|
||
|
add_custom_target(codechecker-clean
|
||
|
COMMAND rm -rf ${CODECHECKER_OUTPUT_DIRECTORY}
|
||
|
)
|
||
|
|
||
|
|
||
|
add_custom_target(codechecker-html
|
||
|
COMMAND . ${CODECHECKER_VENV_PATH}\;
|
||
|
${CODECHECKER_PATH}
|
||
|
parse
|
||
|
${CODECHECKER_OUTPUT_DIRECTORY}
|
||
|
-e html
|
||
|
-o ${CODECHECKER_HTML_OUTPUT_DIRECTORY}
|
||
|
)
|
||
|
|
||
|
if (CODECHECKER_STORE)
|
||
|
add_custom_target(codechecker-store
|
||
|
COMMAND . ${CODECHECKER_VENV_PATH}\;
|
||
|
${CODECHECKER_PATH}
|
||
|
store
|
||
|
--tag ${CODECHECK_GIT_BRANCH}
|
||
|
-n ${CODECHECKER_RUN}
|
||
|
--url ${CODECHECKER_URL}
|
||
|
${CODECHECKER_OUTPUT_DIRECTORY}
|
||
|
)
|
||
|
endif()
|
||
|
|
||
|
|
||
|
endif()
|