Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ INCLUDE(cmake/Modules/UseMultiArch.cmake)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)

IF(CMAKE_CXX_COMPILER_ID MATCHES GNU)
IF(CMAKE_CXX_COMPILER_ID MATCHES GNU OR
CMAKE_CXX_COMPILER_ID MATCHES Clang)
# check if compiler supports c++-0x
CHECK_CXX_COMPILER_FLAG("-std=gnu++0x" HAVE_0x)
IF(HAVE_0x)
Expand All @@ -36,7 +37,7 @@ IF(CMAKE_CXX_COMPILER_ID MATCHES GNU)
MESSAGE("A compiler with c++-0x support is needed")
EXIT(1)
ENDIF(HAVE_0x)
ENDIF(CMAKE_CXX_COMPILER_ID MATCHES GNU)
ENDIF()

# Check that the required C++11 features are available
CHECK_CXX_SOURCE_COMPILES("
Expand Down Expand Up @@ -127,6 +128,36 @@ TARGET_LINK_LIBRARIES(LRSpline ${DEPLIBS})
SET_TARGET_PROPERTIES(LRSpline PROPERTIES VERSION ${LRSpline_VERSION}
SOVERSION ${LRSpline_VERSION_MAJOR}.${LRSpline_VERSION_MINOR})

# Add static analysis tests
configure_file(test/clang-check-test.sh.in bin/clang-check-test.sh @ONLY)
configure_file(test/cppcheck-test.sh.in bin/cppcheck-test.sh @ONLY)
find_program(CLANGCHECK_COMMAND clang-check)
find_program(CPPCHECK_COMMAND cppcheck)
if(CPPCHECK_COMMAND)
foreach(include ${INCLUDES})
list(APPEND IPATH -I ${include})
endforeach()
endif()
foreach(src ${LRSPLINE_SRCS})
get_filename_component(name ${src} NAME)
get_filename_component(EXT ${src} EXT)
if(EXT STREQUAL .cpp)
if(NOT IS_ABSOLUTE ${src})
set(src ${PROJECT_SOURCE_DIR}/${src})
endif()
if(CLANGCHECK_COMMAND AND CMAKE_EXPORT_COMPILE_COMMANDS)
add_test(NAME clang-check+${name}
COMMAND bin/clang-check-test.sh ${CLANGCHECK_COMMAND} ${src}
CONFIGURATIONS analyze clang-check)
endif()
if(CPPCHECK_COMMAND)
add_test(NAME cppcheck+${name}
COMMAND bin/cppcheck-test.sh ${CPPCHECK_COMMAND} ${src} ${IPATHS}
CONFIGURATIONS analyze cppcheck)
endif()
endif()
endforeach()

# Make some Apps
ADD_EXECUTABLE(reduceContinuity ${PROJECT_SOURCE_DIR}/Apps/reduceContinuity.cpp)
TARGET_LINK_LIBRARIES(reduceContinuity LRSpline ${DEPLIBS})
Expand Down
23 changes: 23 additions & 0 deletions test/clang-check-test.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# This script performs a single analysis using clang-check
# It is used by the 'make test' target in the buildsystems
# Usually you should use 'ctest -C clang-check' rather than calling this script directly
#
# Parameters: $1 = Application binary
# $2 = Source file to process

clangcheck_cmd=$1
source_file=$2

tmpfil=`mktemp`
$clangcheck_cmd -p @CMAKE_BINARY_DIR@ -analyze $source_file &> $tmpfil
cat $tmpfil
if test -s $tmpfil
then
rm $tmpfil
exit 1
fi

rm $tmpfil
exit 0
29 changes: 29 additions & 0 deletions test/cppcheck-test.sh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# This script performs a single analysis using cppcheck
# It is used by the 'make test' target in the buildsystems
# Usually you should use 'ctest -C cppcheck' rather than calling this script directly
#
# Parameters: $1 = Application binary
# $2 = Source file to process
# $3..$N = include path parameters (-I dir1 -I dir2 ...)

cppcheck_cmd=$1
source_file=$2
shift 2

tmpfil=`mktemp`
$cppcheck_cmd $@ --force --enable=all --suppress=unusedFunction $source_file &> $tmpfil
nmatch=`cat $tmpfil | grep "\[.*\]" | wc -l`
nsys=`cat $tmpfil | grep "\[/usr.*\]" | wc -l`
nnone=`cat $tmpfil | grep "\[\\*]" | wc -l`
let "nval=$nmatch-$nsys-$nnone"
if test $nval -gt 0
then
cat $tmpfil
rm $tmpfil
exit 1
fi

rm $tmpfil
exit 0