{"id":5601,"date":"2018-12-30T18:31:53","date_gmt":"2018-12-30T18:31:53","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/cppdepend-a-review\/"},"modified":"2018-12-30T18:31:53","modified_gmt":"2018-12-30T18:31:53","slug":"cppdepend-a-review","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/cppdepend-a-review\/","title":{"rendered":"CppDepend  &#8211; A Review"},"content":{"rendered":"<p>In my concurrency class, I use more than 60 programs. Most of the programs consist of a single source file. I&#8217;m quite curious if the static code analysis tool <a href=\"https:\/\/www.cppdepend.com\/\">CppDepend<\/a> can find any issues in my sources. Let me try it out.<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5592\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/cppDepend.png\" alt=\"cppDepend\" width=\"400\" height=\"90\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/cppDepend.png 473w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/cppDepend-300x67.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<h2>My Special Use-Case<\/h2>\n<p>My use case is unique for two reasons. First, I don&#8217;t expect too many issues with my examples for one reason: I give quite often concurrency classes and use these examples in my classes; therefore, I had many code reviewer. Second, my programs are most of the times not really sophisticated and quite short. They should only serve one purpose: show the particular concurrency features in isolation.<\/p>\n<h2>My Strategy<\/h2>\n<p>Due to my unique circumstances, here are my steps to get the static code analysis with CppDepend.<\/p>\n<ol>\n<li>Generate a CMake file for Visual Studio, GCC, and Clang<\/li>\n<li>Generate a Visual Studio Project from CMake<\/li>\n<li>Import the Visual Studio Project project into CppDepend<\/li>\n<li>Make the code analysis in CppDepend<\/li>\n<\/ol>\n<p>Here we go.<\/p>\n<h3>1. Generate a CMake file for Visual Studio, GCC, and Clang<\/h3>\n<p>My customers work with Visual Studio, GCC, or Clang. To provide a way to compile all C++ sources to executables automatically, I use <a href=\"https:\/\/cmake.org\/\">CMake.<\/a> In sum, I have more than 300 C++ sources files in various directories. Each source file should become an executable. Writing a <span style=\"font-family: courier new, courier;\">CMakeList.txt<\/span> manually for each directory would be a boring step. Additionally, I would have to adapt it each time, if I modified the file names. Terrible!. To automate the boring stuff, I wrote a small python script <span style=\"font-family: courier new, courier;\">generateCMakeFile.py<\/span>. <span style=\"font-family: courier new, courier;\">generateCMakeFile.py<\/span> generates a <span style=\"font-family: courier new, courier;\">CMakeList.txt<\/span> file for the directory, in which I invoke it.<\/p>\n<p>Here it is.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\"># generateCMakeFile.py<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">import<\/span> <span style=\"color: #00ccff; font-weight: bold;\">fnmatch<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">import<\/span> <span style=\"color: #00ccff; font-weight: bold;\">os<\/span>\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># A few constants<\/span>\r\nSUFFIX <span style=\"color: #555555;\">=<\/span> <span style=\"color: #cc3300;\">\"*.cpp\"<\/span>\r\nOUTPUT <span style=\"color: #555555;\">=<\/span> <span style=\"color: #cc3300;\">\"CMakeLists.txt\"<\/span>\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># The output file<\/span>\r\noutputFile <span style=\"color: #555555;\">=<\/span> <span style=\"color: #336666;\">open<\/span>(OUTPUT, <span style=\"color: #cc3300;\">\"w\"<\/span>)\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># Return the full path to all files respecting the pattern<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">def<\/span> <span style=\"color: #cc00ff;\">getFiles<\/span>(dir_, patterns<span style=\"color: #555555;\">=<\/span><span style=\"color: #cc3300;\">\"*\"<\/span>, recursive<span style=\"color: #555555;\">=<\/span><span style=\"color: #336666;\">True<\/span>):\r\n    patterns <span style=\"color: #555555;\">=<\/span> patterns<span style=\"color: #555555;\">.<\/span>split()\r\n    retValue <span style=\"color: #555555;\">=<\/span> []\r\n    <span style=\"color: #006699; font-weight: bold;\">for<\/span> path, dirs, files <span style=\"color: #000000; font-weight: bold;\">in<\/span> os<span style=\"color: #555555;\">.<\/span>walk(dir_):\r\n        <span style=\"color: #006699; font-weight: bold;\">for<\/span> file_ <span style=\"color: #000000; font-weight: bold;\">in<\/span> files:\r\n            <span style=\"color: #006699; font-weight: bold;\">for<\/span> pattern <span style=\"color: #000000; font-weight: bold;\">in<\/span> patterns:\r\n                <span style=\"color: #006699; font-weight: bold;\">if<\/span> fnmatch<span style=\"color: #555555;\">.<\/span>fnmatch(file_, pattern):\r\n                    retValue<span style=\"color: #555555;\">.<\/span>append(os<span style=\"color: #555555;\">.<\/span>path<span style=\"color: #555555;\">.<\/span>join(path, file_))\r\n                    <span style=\"color: #006699; font-weight: bold;\">break<\/span>\r\n        <span style=\"color: #006699; font-weight: bold;\">if<\/span> <span style=\"color: #000000; font-weight: bold;\">not<\/span> recursive: <span style=\"color: #006699; font-weight: bold;\">break<\/span>\r\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> retValue\r\n\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># Get all files of the current working directory ending with *.cpp<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">def<\/span> <span style=\"color: #cc00ff;\">getAllFilenames<\/span>():\r\n    allFiles <span style=\"color: #555555;\">=<\/span> getFiles(os<span style=\"color: #555555;\">.<\/span>getcwd(), SUFFIX , <span style=\"color: #336666;\">False<\/span>) \r\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> [ os<span style=\"color: #555555;\">.<\/span>path<span style=\"color: #555555;\">.<\/span>basename(file_)[:<span style=\"color: #555555;\">-<\/span><span style=\"color: #336666;\">len<\/span>(SUFFIX)<span style=\"color: #555555;\">+<\/span><span style=\"color: #ff6600;\">1<\/span>] <span style=\"color: #006699; font-weight: bold;\">for<\/span> file_ <span style=\"color: #000000; font-weight: bold;\">in<\/span> allFiles ]\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># Create the CMakeLists.txt header for GCC, Clang, and MSVC<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">def<\/span> <span style=\"color: #cc00ff;\">getHeader<\/span>():\r\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> <span style=\"color: #cc3300;\">\"\"\"# Require a recent version of cmake<\/span>\r\n<span style=\"color: #cc3300;\">cmake_minimum_required(VERSION 2.8.4 FATAL_ERROR)<\/span>\r\n\r\n<span style=\"color: #cc3300;\"># This project is C++ based.<\/span>\r\n<span style=\"color: #cc3300;\">project(seminar)<\/span>\r\n\r\n<span style=\"color: #cc3300;\">if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)<\/span>\r\n<span style=\"color: #cc3300;\">    set(CMAKE_CXX_FLAGS \"-O3 -std=c++14 -pthread\")<\/span>\r\n<span style=\"color: #cc3300;\">    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.0)<\/span>\r\n<span style=\"color: #cc3300;\">\t    message(WARNING \"!!!! GCC versions must be at least 5.0 !!!!\")<\/span>\r\n<span style=\"color: #cc3300;\">        message(WARNING \"!!!! Adust the makefile to build with a different compiler. !!!!\")<\/span>\r\n<span style=\"color: #cc3300;\">    endif()<\/span>\r\n<span style=\"color: #cc3300;\">elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)<\/span>\r\n<span style=\"color: #cc3300;\">    set(CMAKE_CXX_FLAGS \"-O3 -std=c++14 -pthread\")<\/span>\r\n<span style=\"color: #cc3300;\">    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)<\/span>\r\n<span style=\"color: #cc3300;\">        message(WARNING \"!!!! Clang version must be at least 3.5 !!!!\")<\/span>\r\n<span style=\"color: #cc3300;\">\t\tmessage(WARNING \"!!!! Adust the makefile to build with a different compiler. !!!!\")<\/span>\r\n<span style=\"color: #cc3300;\">    endif()<\/span>\r\n<span style=\"color: #cc3300;\">elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)<\/span>\r\n<span style=\"color: #cc3300;\">    set(CMAKE_CXX_FLAGS \"\/Ox \/EHsc\")<\/span>\r\n<span style=\"color: #cc3300;\">    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10)    <\/span>\r\n<span style=\"color: #cc3300;\">        message(WARNING \"!!!! MSVC version must be at least 19.10 !!!!\")<\/span>\r\n<span style=\"color: #cc3300;\">    endif()\t<\/span>\r\n<span style=\"color: #cc3300;\">else()<\/span>\r\n<span style=\"color: #cc3300;\">    message(WARNING \"!!! You are using an unsupported compiler! Compilation has only been tested with GCC &gt;= 5.0, Clang &gt;= 3.5, or MSVC &gt;= 19.10. !!!\")<\/span>\r\n<span style=\"color: #cc3300;\">endif()<\/span>\r\n<span style=\"color: #cc3300;\">    <\/span>\r\n\r\n<span style=\"color: #cc3300;\">set(CMAKE_RUNTIME_OUTPUT_DIRECTORY \"bin\/\")<\/span>\r\n\r\n<span style=\"color: #cc3300;\">set(CMAKE_VERBOSE_MAKEFILE on)<\/span>\r\n\r\n<span style=\"color: #cc3300;\">\"\"\"<\/span>\r\n    \r\n<span style=\"color: #0099ff; font-style: italic;\"># Create the list of all source files    <\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">def<\/span> <span style=\"color: #cc00ff;\">getAllNames<\/span>(allNames):    \r\n    outNames <span style=\"color: #555555;\">=<\/span> <span style=\"color: #cc3300;\">\"set(example_programs\"<\/span> \r\n    <span style=\"color: #006699; font-weight: bold;\">for<\/span> entry <span style=\"color: #000000; font-weight: bold;\">in<\/span> allNames:\r\n        outNames <span style=\"color: #555555;\">+=<\/span> <span style=\"color: #cc3300;\">\"    \"<\/span> <span style=\"color: #555555;\">+<\/span> entry <span style=\"color: #555555;\">+<\/span> <span style=\"color: #cc3300;\">\"<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">\"<\/span>\r\n    outNames <span style=\"color: #555555;\">+=<\/span> <span style=\"color: #cc3300;\">\"   )\"<\/span>\r\n    outNames <span style=\"color: #555555;\">+=<\/span> <span style=\"color: #cc3300;\">\"<\/span><span style=\"color: #cc3300; font-weight: bold;\">\\n<\/span><span style=\"color: #cc3300;\">\"<\/span>\r\n    \r\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> outNames\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># Create an executable from the source file<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">def<\/span> <span style=\"color: #cc00ff;\">getTail<\/span>():\r\n    tail <span style=\"color: #555555;\">=<\/span> <span style=\"color: #cc3300;\">\"\"\"foreach(example_program ${example_programs})<\/span>\r\n<span style=\"color: #cc3300;\">  set(sources ${example_program}.cpp)<\/span>\r\n<span style=\"color: #cc3300;\">  source_group(\"Source Files\" FILES{sources})<\/span>\r\n<span style=\"color: #cc3300;\">  add_executable(${example_program} ${sources})<\/span>\r\n<span style=\"color: #cc3300;\">endforeach()\"\"\"<\/span>\r\n    <span style=\"color: #006699; font-weight: bold;\">return<\/span> tail\r\n\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># Create the CMakeLists.txt<\/span>\r\nallNames <span style=\"color: #555555;\">=<\/span> getAllFilenames()\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">print<\/span> <span style=\"color: #555555;\">&gt;&gt;<\/span> outputFile, getHeader()\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">print<\/span> <span style=\"color: #555555;\">&gt;&gt;<\/span> outputFile, getAllNames(allNames)\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">print<\/span> <span style=\"color: #555555;\">&gt;&gt;<\/span> outputFile, getTail()\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>To understand the program, you should start with the three print statements add the end. The brown font goes directly into <span style=\"font-family: courier new, courier;\">CMakeList.txt.<\/span><\/p>\n<p>Using the <span style=\"font-family: courier new, courier;\">generateCMakeFile.py<\/span> <span style=\"font-family: courier new, courier;\"><\/span>is straightforward. I copied the&nbsp; <span style=\"font-family: courier new, courier;\">generateCMakeFile.py <\/span>to the directory, I wanted to use it. This step is not necessary but make the commandline easier to write.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5593\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/GenerateCmakeFile.png\" alt=\"GenerateCmakeFile\" width=\"600\" height=\"150\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/GenerateCmakeFile.png 684w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/GenerateCmakeFile-300x75.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>Finally, this is the autogenerate <span style=\"font-family: courier new, courier;\">CMakeList.txt.<\/span><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\"># Require a recent version of cmake<\/span>\r\n<span style=\"color: #336666;\">cmake_minimum_required<\/span>(<span style=\"color: #cc3300;\">VERSION<\/span> <span style=\"color: #cc3300;\">2.8.4<\/span> <span style=\"color: #cc3300;\">FATAL_ERROR<\/span>)\r\n\r\n<span style=\"color: #0099ff; font-style: italic;\"># This project is C++ based.<\/span>\r\n<span style=\"color: #336666;\">project<\/span>(<span style=\"color: #cc3300;\">seminar<\/span>)\r\n\r\n<span style=\"color: #336666;\">if<\/span>(<span style=\"color: #555555;\">${<\/span><span style=\"color: #003333;\">CMAKE_CXX_COMPILER_ID<\/span><span style=\"color: #555555;\">}<\/span> <span style=\"color: #cc3300;\">STREQUAL<\/span> <span style=\"color: #cc3300;\">GNU<\/span>)\r\n    <span style=\"color: #336666;\">set<\/span>(<span style=\"color: #cc3300;\">CMAKE_CXX_FLAGS<\/span> <span style=\"color: #cc3300;\">\"-O3 -std=c++14 -pthread\"<\/span>)\r\n    <span style=\"color: #336666;\">if<\/span> (<span style=\"color: #cc3300;\">CMAKE_CXX_COMPILER_VERSION<\/span> <span style=\"color: #cc3300;\">VERSION_LESS<\/span> <span style=\"color: #cc3300;\">5.0<\/span>)\r\n\t    <span style=\"color: #336666;\">message<\/span>(<span style=\"color: #cc3300;\">WARNING<\/span> <span style=\"color: #cc3300;\">\"!!!! GCC versions must be at least 5.0 !!!!\"<\/span>)\r\n        <span style=\"color: #336666;\">message<\/span>(<span style=\"color: #cc3300;\">WARNING<\/span> <span style=\"color: #cc3300;\">\"!!!! Adust the makefile to build with a different compiler. !!!!\"<\/span>)\r\n    <span style=\"color: #336666;\">endif<\/span>()\r\n<span style=\"color: #336666;\">elseif<\/span> (<span style=\"color: #555555;\">${<\/span><span style=\"color: #003333;\">CMAKE_CXX_COMPILER_ID<\/span><span style=\"color: #555555;\">}<\/span> <span style=\"color: #cc3300;\">STREQUAL<\/span> <span style=\"color: #cc3300;\">Clang<\/span>)\r\n    <span style=\"color: #336666;\">set<\/span>(<span style=\"color: #cc3300;\">CMAKE_CXX_FLAGS<\/span> <span style=\"color: #cc3300;\">\"-O3 -std=c++14 -pthread\"<\/span>)\r\n    <span style=\"color: #336666;\">if<\/span> (<span style=\"color: #cc3300;\">CMAKE_CXX_COMPILER_VERSION<\/span> <span style=\"color: #cc3300;\">VERSION_LESS<\/span> <span style=\"color: #cc3300;\">3.5<\/span>)\r\n        <span style=\"color: #336666;\">message<\/span>(<span style=\"color: #cc3300;\">WARNING<\/span> <span style=\"color: #cc3300;\">\"!!!! Clang version must be at least 3.5 !!!!\"<\/span>)\r\n\t\t<span style=\"color: #336666;\">message<\/span>(<span style=\"color: #cc3300;\">WARNING<\/span> <span style=\"color: #cc3300;\">\"!!!! Adust the makefile to build with a different compiler. !!!!\"<\/span>)\r\n    <span style=\"color: #336666;\">endif<\/span>()\r\n<span style=\"color: #336666;\">elseif<\/span> (<span style=\"color: #555555;\">${<\/span><span style=\"color: #003333;\">CMAKE_CXX_COMPILER_ID<\/span><span style=\"color: #555555;\">}<\/span> <span style=\"color: #cc3300;\">STREQUAL<\/span> <span style=\"color: #cc3300;\">MSVC<\/span>)\r\n    <span style=\"color: #336666;\">set<\/span>(<span style=\"color: #cc3300;\">CMAKE_CXX_FLAGS<\/span> <span style=\"color: #cc3300;\">\"\/Ox \/EHsc\"<\/span>)\r\n    <span style=\"color: #336666;\">if<\/span> (<span style=\"color: #cc3300;\">CMAKE_CXX_COMPILER_VERSION<\/span> <span style=\"color: #cc3300;\">VERSION_LESS<\/span> <span style=\"color: #cc3300;\">19.10<\/span>)    \r\n        <span style=\"color: #336666;\">message<\/span>(<span style=\"color: #cc3300;\">WARNING<\/span> <span style=\"color: #cc3300;\">\"!!!! MSVC version must be at least 19.10 !!!!\"<\/span>)\r\n    <span style=\"color: #336666;\">endif<\/span>()\t\r\n<span style=\"color: #336666;\">else<\/span>()\r\n    <span style=\"color: #336666;\">message<\/span>(<span style=\"color: #cc3300;\">WARNING<\/span> <span style=\"color: #cc3300;\">\"!!! You are using an unsupported compiler! Compilation has only been tested with GCC &gt;= 5.0, Clang &gt;= 3.5, or MSVC &gt;= 19.10. !!!\"<\/span>)\r\n<span style=\"color: #336666;\">endif<\/span>()\r\n    \r\n\r\n<span style=\"color: #336666;\">set<\/span>(<span style=\"color: #cc3300;\">CMAKE_RUNTIME_OUTPUT_DIRECTORY<\/span> <span style=\"color: #cc3300;\">\"bin\/\"<\/span>)\r\n\r\n<span style=\"color: #336666;\">set<\/span>(<span style=\"color: #cc3300;\">CMAKE_VERBOSE_MAKEFILE<\/span> <span style=\"color: #cc3300;\">on<\/span>)\r\n\r\n\r\n<span style=\"color: #336666;\">set<\/span>(<span style=\"color: #cc3300;\">example_programs<\/span>    <span style=\"color: #cc3300;\">acquireConsume<\/span>\r\n    <span style=\"color: #cc3300;\">acquireRelease<\/span>\r\n    <span style=\"color: #cc3300;\">asyncLazyEager<\/span>\r\n    <span style=\"color: #cc3300;\">atomicCondition<\/span>\r\n    <span style=\"color: #cc3300;\">atomic<\/span>\r\n    <span style=\"color: #cc3300;\">blockingAsync<\/span>\r\n    <span style=\"color: #cc3300;\">conditionVariable<\/span>\r\n    <span style=\"color: #cc3300;\">dataRaceOnX<\/span>\r\n    <span style=\"color: #cc3300;\">dotProduct<\/span>\r\n    <span style=\"color: #cc3300;\">fetch_mult<\/span>\r\n    <span style=\"color: #cc3300;\">lockGuard<\/span>\r\n    <span style=\"color: #cc3300;\">mutex<\/span>\r\n    <span style=\"color: #cc3300;\">newAlgorithm<\/span>\r\n    <span style=\"color: #cc3300;\">packagedTask<\/span>\r\n    <span style=\"color: #cc3300;\">packagedTaskReuse<\/span>\r\n    <span style=\"color: #cc3300;\">promiseFuture<\/span>\r\n    <span style=\"color: #cc3300;\">promiseFutureSynchronize<\/span>\r\n    <span style=\"color: #cc3300;\">readerWriterLock<\/span>\r\n    <span style=\"color: #cc3300;\">relaxed<\/span>\r\n    <span style=\"color: #cc3300;\">safeInitializationCallOnce<\/span>\r\n    <span style=\"color: #cc3300;\">safeInitializationStatic<\/span>\r\n    <span style=\"color: #cc3300;\">singleton<\/span>\r\n    <span style=\"color: #cc3300;\">spinlockAcquireRelease<\/span>\r\n    <span style=\"color: #cc3300;\">spinLock<\/span>\r\n    <span style=\"color: #cc3300;\">threadArguments<\/span>\r\n    <span style=\"color: #cc3300;\">threadCreate<\/span>\r\n    <span style=\"color: #cc3300;\">threadLifetime<\/span>\r\n    <span style=\"color: #cc3300;\">threadLocal<\/span>\r\n    <span style=\"color: #cc3300;\">threadMethods<\/span>\r\n    <span style=\"color: #cc3300;\">time<\/span>\r\n    <span style=\"color: #cc3300;\">timeDuration<\/span>\r\n    <span style=\"color: #cc3300;\">transitivity<\/span>\r\n    <span style=\"color: #cc3300;\">uniqueLock<\/span>\r\n   )\r\n\r\n<span style=\"color: #336666;\">foreach<\/span>(<span style=\"color: #cc3300;\">example_program<\/span> <span style=\"color: #555555;\">${<\/span><span style=\"color: #003333;\">example_programs<\/span><span style=\"color: #555555;\">}<\/span>)\r\n  <span style=\"color: #336666;\">set<\/span>(<span style=\"color: #cc3300;\">sources<\/span> <span style=\"color: #555555;\">${<\/span><span style=\"color: #003333;\">example_program<\/span><span style=\"color: #555555;\">}<\/span><span style=\"color: #cc3300;\">.cpp<\/span>)\r\n  <span style=\"color: #336666;\">source_group<\/span>(<span style=\"color: #cc3300;\">\"Source Files\"<\/span> <span style=\"color: #cc3300;\">FILES{sources}<\/span>)\r\n  <span style=\"color: #336666;\">add_executable<\/span>(<span style=\"color: #555555;\">${<\/span><span style=\"color: #003333;\">example_program<\/span><span style=\"color: #555555;\">}<\/span> <span style=\"color: #555555;\">${<\/span><span style=\"color: #003333;\">sources<\/span><span style=\"color: #555555;\">}<\/span>)\r\n<span style=\"color: #336666;\">endforeach<\/span>()\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h3>2. Generate a Visual Studio Project from CMake<\/h3>\n<p>To make my CppDepend life more comfortable, I switch from Linux to Windows and continue with Visual Studio.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5594\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/MakeVisualProject.PNG\" alt=\"MakeVisualProject\" width=\"700\" height=\"217\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/MakeVisualProject.PNG 3612w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/MakeVisualProject-300x93.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/MakeVisualProject-1024x318.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/MakeVisualProject-768x238.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/MakeVisualProject-1536x477.png 1536w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/MakeVisualProject-2048x636.png 2048w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>This step creates a 64-bit Visual Studio Project in the directory &#8220;<span style=\"font-family: courier new, courier;\">C:\\Users\\raine\\build<\/span>&#8220;.&nbsp;<\/p>\n<h3>3. Import the Visual Studio Project project into CppDepend<\/h3>\n<p>Now, it&#8217;s time to start CppDepend and create a new project Concurrency:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5595\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/NewProject.PNG\" alt=\"NewProject\" width=\"600\" height=\"534\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/NewProject.PNG 1849w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/NewProject-300x267.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/NewProject-1024x912.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/NewProject-768x684.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/NewProject-1536x1368.png 1536w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/>Next, I add Visual Studio to my new project.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5596\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/solution.PNG\" alt=\"solution\" width=\"450\" height=\"343\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/solution.PNG 1535w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/solution-300x229.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/solution-1024x781.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/solution-768x586.png 768w\" sizes=\"auto, (max-width: 450px) 100vw, 450px\" \/><\/p>\n<p>One step is still missing. I have to press the analyse button. It took my eight cores a few second to analyse the source files.<\/p>\n<h3>4. Make the code analysis in CppDepend<\/h3>\n<p>As I already assumed it, the most checks are green:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5597\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/analysis.PNG\" alt=\"analysis\" width=\"700\" height=\"376\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/analysis.PNG 3840w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/analysis-300x161.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/analysis-1024x549.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/analysis-768x412.png 768w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/analysis-1536x824.png 1536w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/analysis-2048x1099.png 2048w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>Of course, I&#8217;m only interested in the red (Error) and yellow (Warning) ones.<\/p>\n<h4>Error:<\/h4>\n<ul>\n<li>Quality Gates:\n<ul>\n<li>This issue boils down to mainly one function: The method is too big, has too many local variables, and is poorly documented. What I liked about CppDepend was that it shows me the metric I violated.&nbsp;<\/li>\n<\/ul>\n<div>&nbsp;<\/div>\n<\/li>\n<\/ul>\n<h4><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5598\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/QualityGates.PNG\" alt=\"QualityGates\" width=\"400\" height=\"531\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/QualityGates.PNG 862w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/QualityGates-226x300.png 226w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/QualityGates-771x1024.png 771w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/QualityGates-768x1020.png 768w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/h4>\n<h4>Warnings:<\/h4>\n<ul>\n<li>Code Smells:\n<ul>\n<li>The previous break of the Quality Gates was also a Code Smell; therefore, I can ignore this warning.<\/li>\n<\/ul>\n<\/li>\n<li>Object Oriented Design:\n<ul>\n<li>Only one of the thirty rules was violated: three of my constructors taking one argument were not explicit. Honestly, this is a rule I often preach in my seminars. Shame on me.&nbsp;<\/li>\n<\/ul>\n<div>&nbsp;<\/div>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5599\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/ExplicitConstructor.PNG\" alt=\"ExplicitConstructor\" width=\"500\" height=\"93\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/ExplicitConstructor.PNG 1454w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/ExplicitConstructor-300x56.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/ExplicitConstructor-1024x189.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/ExplicitConstructor-768x142.png 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>&nbsp;Misc: \n<ul>\n<li>This is also an issue I should fix. I passed a std<span style=\"font-family: courier new, courier;\">:<\/span>:string by copy.<\/li>\n<\/ul>\n<div>&nbsp;<\/div>\n<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5600\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/passByReference.PNG\" alt=\"passByReference\" width=\"500\" height=\"72\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/passByReference.PNG 1223w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/passByReference-300x43.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/passByReference-1024x147.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/12\/passByReference-768x110.png 768w\" sizes=\"auto, (max-width: 500px) 100vw, 500px\" \/><\/p>\n<ul>\n<li>Dead Code:\n<ul>\n<li>This violation was funny. The violation was that the destructor of the singleton was never called. To my excuse, I only used a singleton to explain the thread-safe initialisation of a variable.<\/li>\n<\/ul>\n<\/li>\n<li>Naming Conventions:\n<ul>\n<li>I&#8217;m not a big fan of Hungarian notation. Therefore, I wouldn&#8217;t prefix an instance variable with a m_ or a static with a s_.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>My Resume<\/h2>\n<p>Here is my short resume. I put not too much effort into the analysis of CppDepend but more in establishing an automated process to create the Visual Studio solution as input for CppDepend. Regardless, I found immediately a few big issues which I&#8217;m going to fix. It&#8217;s quite comfortable to fix these issues because a double-click on the Error\/Warning in CppDepend opens the source file in Visual Studio.<\/p>\n<p>Although I only scratched at the surface of CppDepend, the analysis of my concurrency source files impressed me. I will, therefore, invest in the future more time to better understand the various metrics of CppDepend and apply them to my other source files. My gut feeling is that I can draw many benefits from CppDepend.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my concurrency class, I use more than 60 programs. Most of the programs consist of a single source file. I&#8217;m quite curious if the static code analysis tool CppDepend can find any issues in my sources. Let me try it out.<\/p>\n","protected":false},"author":21,"featured_media":5592,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[373],"tags":[],"class_list":["post-5601","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-review"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=5601"}],"version-history":[{"count":0,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5601\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/5592"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}