Skip to content

Commit

Permalink
refactor: handle missing commands and false options
Browse files Browse the repository at this point in the history
Signed-off-by: msclock <msclock@qq.com>
  • Loading branch information
msclock committed Apr 1, 2024
1 parent 2e89e36 commit 57f94f7
Show file tree
Hide file tree
Showing 6 changed files with 314 additions and 304 deletions.
4 changes: 2 additions & 2 deletions cmake/build/Ccache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ message(STATUS "Use Ccache with USE_CCACHE: ${USE_CCACHE}
USE_CCACHE: If use ccache to speed up compiling. Default is ON.")

if(NOT USE_CCACHE)
message(STATUS "Disable ccache because of USE_CCACHE is OFF")
message(STATUS "Disable ccache by USE_CCACHE evaluates to false.")
return()
endif()

Expand All @@ -28,7 +28,7 @@ find_program(
DOC "ccache executable")

if(NOT CCACHE_COMMAND)
message(WARNING "Disable ccache because of no ccache installed")
message(WARNING "No ccache found, disable ccache optimization.")
return()
endif()

Expand Down
41 changes: 22 additions & 19 deletions cmake/build/Cppcheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ message(
)

if(NOT USE_CPPCHECK)
message(STATUS "Disable cppcheck by USE_CPPCHECK evaluates to false.")
return()
endif()

Expand All @@ -52,26 +53,28 @@ find_program(
NAMES cppcheck
DOC "Path to cppcheck executable")

if(CPPCHECK_COMMAND)
if(CMAKE_GENERATOR MATCHES ".*Visual Studio.*")
set(CPPCHECK_TEMPLATE "vs")
else()
set(CPPCHECK_TEMPLATE "gcc")
endif()
if(NOT CPPCHECK_COMMAND)
message(WARNING "No cppcheck found, disable cppcheck static analysis.")
return()
endif()

set(CMAKE_CXX_CPPCHECK
${CPPCHECK_COMMAND} --template=${CPPCHECK_TEMPLATE}
${USE_CPPCHECK_OPTIONS} --suppress=${USE_CPPCHECK_SUPPRESS_DIR})
# Set cppcheck template based on the generator used
if(CMAKE_GENERATOR MATCHES ".*Visual Studio.*")
set(CPPCHECK_TEMPLATE "vs")
else()
set(CPPCHECK_TEMPLATE "gcc")
endif()

if(NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
list(APPEND CMAKE_CXX_CPPCHECK --std=c++${CMAKE_CXX_STANDARD})
endif()
set(CMAKE_CXX_CPPCHECK
${CPPCHECK_COMMAND} --template=${CPPCHECK_TEMPLATE} ${USE_CPPCHECK_OPTIONS}
--suppress=${USE_CPPCHECK_SUPPRESS_DIR})

if(USE_CPPCHECK_WARNINGS_AS_ERRORS)
list(APPEND CMAKE_CXX_CPPCHECK --error-exitcode=2)
endif()
list(REMOVE_DUPLICATES CMAKE_CXX_CPPCHECK)
message(STATUS "Cppcheck final command: ${CMAKE_CXX_CPPCHECK}")
else()
message(WARNING "Not found cppcheck, please check cppcheck existence")
if(NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
list(APPEND CMAKE_CXX_CPPCHECK --std=c++${CMAKE_CXX_STANDARD})
endif()

if(USE_CPPCHECK_WARNINGS_AS_ERRORS)
list(APPEND CMAKE_CXX_CPPCHECK --error-exitcode=2)
endif()
list(REMOVE_DUPLICATES CMAKE_CXX_CPPCHECK)
message(STATUS "Cppcheck final command: ${CMAKE_CXX_CPPCHECK}")
Loading

0 comments on commit 57f94f7

Please sign in to comment.