Skip to content

Commit

Permalink
STYLE: Initial run of cmake-format
Browse files Browse the repository at this point in the history
With

```sh
./Utilities/Maintenance/cmake-format.bash --tracked
```
  • Loading branch information
thewtex committed Sep 29, 2023
1 parent 788fbc4 commit efa7495
Show file tree
Hide file tree
Showing 1,373 changed files with 43,468 additions and 25,350 deletions.
266 changes: 125 additions & 141 deletions CMake/CppcheckTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,58 +45,64 @@ endif()
# ------------------------------------------------------------------------------
macro(get_cppcheck_arg)

if(FORCE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_FORCE_ARG})
list(REMOVE_ITEM _input FORCE)
endif()

if(VERBOSE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_VERBOSE_ARG})
list(REMOVE_ITEM _input VERBOSE)
endif()

if(QUIET IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_QUIET_ARG})
list(REMOVE_ITEM _input QUIET)
endif()

if(ALL IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_ALL_ARG})
list(REMOVE_ITEM _input ALL)
endif()

if(UNUSED_FUNCTIONS IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
list(REMOVE_ITEM _input UNUSED_FUNCTIONS)
endif()

if(STYLE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
list(REMOVE_ITEM _input STYLE)
endif()

if(INFORMATION IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_INFORMATION_ARG})
list(REMOVE_ITEM _input INFORMATION)
endif()

if(MISSING_INCLUDE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_MISSING_INCLUDE_ARG})
list(REMOVE_ITEM _input MISSING_INCLUDE)
endif()

if(FAIL_ON_WARNINGS IN_LIST _input)
list(APPEND _cppcheck_args
CPPCHECK_FAIL_REGULAR_EXPRESSION
${CPPCHECK_WARN_REGULAR_EXPRESSION})
list(REMOVE_ITEM _input FAIL_ON_WARNINGS)
endif()
if(FORCE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_FORCE_ARG})
list(REMOVE_ITEM _input FORCE)
endif()

if(VERBOSE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_VERBOSE_ARG})
list(REMOVE_ITEM _input VERBOSE)
endif()

if(QUIET IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_QUIET_ARG})
list(REMOVE_ITEM _input QUIET)
endif()

if(ALL IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_ALL_ARG})
list(REMOVE_ITEM _input ALL)
endif()

if(UNUSED_FUNCTIONS IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG})
list(REMOVE_ITEM _input UNUSED_FUNCTIONS)
endif()

if(STYLE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG})
list(REMOVE_ITEM _input STYLE)
endif()

if(INFORMATION IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_INFORMATION_ARG})
list(REMOVE_ITEM _input INFORMATION)
endif()

if(MISSING_INCLUDE IN_LIST _input)
list(APPEND _cppcheck_args ${CPPCHECK_MISSING_INCLUDE_ARG})
list(REMOVE_ITEM _input MISSING_INCLUDE)
endif()

if(FAIL_ON_WARNINGS IN_LIST _input)
list(
APPEND
_cppcheck_args
CPPCHECK_FAIL_REGULAR_EXPRESSION
${CPPCHECK_WARN_REGULAR_EXPRESSION})
list(REMOVE_ITEM _input FAIL_ON_WARNINGS)
endif()

endmacro()

# ------------------------------------------------------------------------------
# add_cppcheck_dir
function(add_cppcheck_dir _name _dir _include_dirs)
function(
add_cppcheck_dir
_name
_dir
_include_dirs)
if(CPPCHECK_FOUND)
set(_cppcheck_args)
set(_input ${ARGN})
Expand All @@ -112,35 +118,24 @@ function(add_cppcheck_dir _name _dir _include_dirs)

itk_add_test(
NAME
${_name}CPPCheckTest
${_name}CPPCheckTest
COMMAND
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_dir}
)

set_tests_properties(${_name}CPPCheckTest
PROPERTIES
FAIL_REGULAR_EXPRESSION
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

add_custom_command(TARGET
all_cppcheck
PRE_BUILD
COMMAND
${CPPCHECK_EXECUTABLE}
${CPPCHECK_QUIET_ARG}
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_dir}
WORKING_DIRECTORY
"${_dir}"
COMMENT
"${_name}_cppcheck: Running cppcheck on ${_dir}..."
VERBATIM)
${_dir})

set_tests_properties(${_name}CPPCheckTest PROPERTIES FAIL_REGULAR_EXPRESSION "${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

add_custom_command(
TARGET all_cppcheck
PRE_BUILD
COMMAND ${CPPCHECK_EXECUTABLE} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_TEMPLATE_ARG} ${_cppcheck_args}
${_cppcheck_compile_args} ${_dir}
WORKING_DIRECTORY "${_dir}"
COMMENT "${_name}_cppcheck: Running cppcheck on ${_dir}..."
VERBATIM)
endif()
endfunction()

Expand All @@ -159,7 +154,7 @@ function(add_cppcheck_sources _targetname)
foreach(_source ${_input})
get_source_file_property(_cppcheck_loc "${_source}" LOCATION)
if(_cppcheck_loc)
# This file has a source file property, carry on.
# This file has a source file property, carry on.
get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE)
if("${_cppcheck_lang}" MATCHES "CXX")
list(APPEND _files "${_cppcheck_loc}")
Expand All @@ -170,17 +165,20 @@ function(add_cppcheck_sources _targetname)
if(EXISTS "${_cppcheck_loc}")
list(APPEND _files "${_cppcheck_loc}")
else()
message(FATAL_ERROR
"Adding CPPCHECK for file target ${_targetname}: "
"File ${_source} does not exist or needs a corrected path location "
"since we think its absolute path is ${_cppcheck_loc}")
message(
FATAL_ERROR
"Adding CPPCHECK for file target ${_targetname}: "
"File ${_source} does not exist or needs a corrected path location "
"since we think its absolute path is ${_cppcheck_loc}")
endif()
endif()
endforeach()

# let's take of include dirs here
get_property(mytargINCLUDES DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY INCLUDE_DIRECTORIES)
get_property(
mytargINCLUDES
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
PROPERTY INCLUDE_DIRECTORIES)

set(_cppcheck_include)
foreach(_includeDirs ${mytargINCLUDES})
Expand All @@ -191,8 +189,10 @@ function(add_cppcheck_sources _targetname)
# let's take of compile definitions here
# NOTE: it does not work, you need to get all definitions by
# another way
get_property(mytargDEFINITIONS DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY COMPILE_DEFINITIONS)
get_property(
mytargDEFINITIONS
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
PROPERTY COMPILE_DEFINITIONS)

set(_cppcheck_def)
foreach(_compiledef ${mytargDEFINITIONS})
Expand All @@ -204,43 +204,33 @@ function(add_cppcheck_sources _targetname)

itk_add_test(
NAME
${_targetname}CPPCheckTest
${_targetname}CPPCheckTest
COMMAND
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_files})

set_tests_properties(${_targetname}CPPCheckTest
PROPERTIES
FAIL_REGULAR_EXPRESSION
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

add_custom_command(TARGET
all_cppcheck
PRE_BUILD
COMMAND
${CPPCHECK_EXECUTABLE}
${CPPCHECK_QUIET_ARG}
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_files}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT
"${_targetname}_cppcheck: Running cppcheck on target ${_targetname}..."
VERBATIM)
${_files})

set_tests_properties(${_targetname}CPPCheckTest PROPERTIES FAIL_REGULAR_EXPRESSION
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

add_custom_command(
TARGET all_cppcheck
PRE_BUILD
COMMAND ${CPPCHECK_EXECUTABLE} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_TEMPLATE_ARG} ${_cppcheck_args}
${_cppcheck_compile_args} ${_files}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "${_targetname}_cppcheck: Running cppcheck on target ${_targetname}..."
VERBATIM)
endif()
endfunction()

# ------------------------------------------------------------------------------
# add_cppcheck
function(add_cppcheck _name)
if(NOT TARGET ${_name})
message(FATAL_ERROR
"add_cppcheck given a target name that does not exist: '${_name}' !")
message(FATAL_ERROR "add_cppcheck given a target name that does not exist: '${_name}' !")
endif()
if(CPPCHECK_FOUND)
set(_cppcheck_args)
Expand All @@ -259,8 +249,10 @@ function(add_cppcheck _name)
endforeach()

# let's take of include dirs here
get_property(mytargINCLUDES DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY INCLUDE_DIRECTORIES)
get_property(
mytargINCLUDES
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
PROPERTY INCLUDE_DIRECTORIES)

set(_cppcheck_include)
foreach(_includeDirs ${mytargINCLUDES})
Expand All @@ -269,8 +261,10 @@ function(add_cppcheck _name)

# --------------------------------------------------------------
# let's take of compile definitions here
get_property(mytargDEFINITIONS DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY COMPILE_DEFINITIONS)
get_property(
mytargDEFINITIONS
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
PROPERTY COMPILE_DEFINITIONS)

set(_cppcheck_def)
foreach(_compiledef ${mytargDEFINITIONS})
Expand All @@ -280,35 +274,25 @@ function(add_cppcheck _name)
# --------------------------------------------------------------
set(_cppcheck_compile_args --check-config ${_cppcheck_include} ${_cppcheck_def})

itk_add_test(
NAME
${_name}CPPCheckTest
COMMAND
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_files})

set_tests_properties(${_name}CPPCheckTest
PROPERTIES
FAIL_REGULAR_EXPRESSION
"${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

add_custom_command(TARGET
all_cppcheck
PRE_BUILD
COMMAND
${CPPCHECK_EXECUTABLE}
${CPPCHECK_QUIET_ARG}
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_files}
WORKING_DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT
"${_name}_cppcheck: Running cppcheck on target ${_name}..."
VERBATIM)
endif()
itk_add_test(
NAME
${_name}CPPCheckTest
COMMAND
"${CPPCHECK_EXECUTABLE}"
${CPPCHECK_TEMPLATE_ARG}
${_cppcheck_args}
${_cppcheck_compile_args}
${_files})

set_tests_properties(${_name}CPPCheckTest PROPERTIES FAIL_REGULAR_EXPRESSION "${CPPCHECK_FAIL_REGULAR_EXPRESSION}")

add_custom_command(
TARGET all_cppcheck
PRE_BUILD
COMMAND ${CPPCHECK_EXECUTABLE} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_TEMPLATE_ARG} ${_cppcheck_args} ${_files}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "${_name}_cppcheck: Running cppcheck on target ${_name}..."
VERBATIM)
endif()

endfunction()
Loading

0 comments on commit efa7495

Please sign in to comment.