Commit 3ab4dbaa authored by David Fairbrother's avatar David Fairbrother
Browse files

Create dedicated cppcheck build dir + protect args

Creates a dedicated cppcheck build directory for us to add the various
things, rather than cluttering up the users build dir.

Adds quotes to protect arguments, as we weren't doing this everywhere
previously
parent 7c738fc1
...@@ -5,13 +5,15 @@ if ( CPPCHECK_EXECUTABLE ) ...@@ -5,13 +5,15 @@ if ( CPPCHECK_EXECUTABLE )
# We must export the compile commands for cppcheck to be able to check # We must export the compile commands for cppcheck to be able to check
# everything correctly # everything correctly
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
configure_file(${CMAKE_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt.in ${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt) set ( CPPCHECK_BUILD_DIR "${CMAKE_BINARY_DIR}/cppcheck" )
file(MAKE_DIRECTORY "${CPPCHECK_BUILD_DIR}" )
configure_file(${CMAKE_SOURCE_DIR}/buildconfig/CMake/CppCheck_Suppressions.txt.in "${CPPCHECK_BUILD_DIR}/CppCheck_Suppressions.txt")
# setup the standard arguments # setup the standard arguments
# --inline-suppr appears to be ignored if --suppresions-list is specified # --inline-suppr appears to be ignored if --suppresions-list is specified
set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120 set ( CPPCHECK_ARGS --enable=all --inline-suppr --max-configs=120
--std=c++${CMAKE_CXX_STANDARD} # use the standard from cmake --std=c++${CMAKE_CXX_STANDARD} # use the standard from cmake
--suppressions-list=${CMAKE_BINARY_DIR}/CppCheck_Suppressions.txt --suppressions-list="${CPPCHECK_BUILD_DIR}/CppCheck_Suppressions.txt"
--project=${CMAKE_BINARY_DIR}/compile_commands.json --project=${CMAKE_BINARY_DIR}/compile_commands.json
# Force cppcheck to check when we use project-wide macros # Force cppcheck to check when we use project-wide macros
-DDLLExport= -DDLLExport=
...@@ -30,9 +32,9 @@ if ( CPPCHECK_EXECUTABLE ) ...@@ -30,9 +32,9 @@ if ( CPPCHECK_EXECUTABLE )
# put the finishing bits on the final command call # put the finishing bits on the final command call
set (_cppcheck_xml_args) set (_cppcheck_xml_args)
if (CPPCHECK_GENERATE_XML) if (CPPCHECK_GENERATE_XML)
list( APPEND _cppcheck_xml_args --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml ) list( APPEND _cppcheck_xml_args --xml --xml-version=2 "${_cppcheck_source_dirs}" 2> ${CMAKE_BINARY_DIR}/cppcheck.xml )
else (CPPCHECK_GENERATE_XML) else (CPPCHECK_GENERATE_XML)
list( APPEND _cppcheck_xml_args ${_cppcheck_source_dirs} ) list( APPEND _cppcheck_xml_args "${_cppcheck_source_dirs}" )
endif (CPPCHECK_GENERATE_XML) endif (CPPCHECK_GENERATE_XML)
...@@ -41,7 +43,7 @@ if ( CPPCHECK_EXECUTABLE ) ...@@ -41,7 +43,7 @@ if ( CPPCHECK_EXECUTABLE )
if (NOT TARGET cppcheck) if (NOT TARGET cppcheck)
add_custom_target ( cppcheck add_custom_target ( cppcheck
COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_xml_args} COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_xml_args}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Running cppcheck" COMMENT "Running cppcheck"
) )
set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE) set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment