CMake: added 'make cppcheck' build target and WITH_CPPCHECK build flag
authorTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Fri, 15 Mar 2013 15:07:49 +0000 (16:07 +0100)
committerTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Mon, 18 Mar 2013 08:56:55 +0000 (09:56 +0100)
- support for 'make cppcheck' to run configured tests
- enable WITH_CPPCHECK to run cppcheck for each compiled file

Signed-off-by: Timo Lotterbach <timo.lotterbach@bmw-carit.de>
CMakeLists.txt
cmake/modules/DefaultSettings.txt

index da4bd73..0664600 100644 (file)
@@ -68,6 +68,16 @@ else (WITH_DOCUMENTATION)
 endif (WITH_DOCUMENTATION)
 
 #===========================================================================================================
+build_flag (WITH_CPPCHECK "Run cppcheck during build (requires cppcheck)" OFF)
+# add build target 'cppcheck' to run pre-defined configuration of cppcheck
+#===========================================================================================================
+if (WITH_CPPCHECK)
+    set(CMAKE_C_COMPILE_OBJECT "${CMAKE_C_COMPILE_OBJECT}; cppcheck <SOURCE> ${CPPCHECK_CONFIG_STRING}")
+    set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_CXX_COMPILE_OBJECT}; cppcheck <SOURCE> ${CPPCHECK_CONFIG_STRING}")
+endif (WITH_CPPCHECK)
+add_custom_target(cppcheck COMMAND cppcheck ${CMAKE_SOURCE_DIR}/LayerManager*/ ${CPPCHECK_CONFIG})
+
+#===========================================================================================================
 build_flag (WITH_TESTS "Build unit test binaries for all enabled components" OFF)
 #===========================================================================================================
 if (WITH_TESTS)
@@ -288,3 +298,4 @@ endif (WITH_CONTROL_LIB)
 # store used build configuration
 #===========================================================================================================
 add_subdirectory_once(config)
+
index 8b2945a..0c342a9 100644 (file)
@@ -86,3 +86,17 @@ set (STATICALLY_LINKED_PLUGINS "" CACHE INTERNAL "list of static plugins")
 set (BUILD_FLAG_LIST           "" CACHE INTERNAL "list of build flag names")
 set (BUILD_FLAG_ARRAY          "" CACHE INTERNAL "array of build flags for logging")
 
+
+#==============================================================================
+# cppcheck configuration
+#==============================================================================
+set (CPPCHECK_CONFIG
+    --quiet
+    --enable=performance,portability
+    --template='{file}:{line}: warning: {message} [{severity}]'
+)
+
+FOREACH (ARG ${CPPCHECK_CONFIG})
+    set (CPPCHECK_CONFIG_STRING "${CPPCHECK_CONFIG_STRING} ${ARG}")
+ENDFOREACH(ARG)
+