From 5bce99742c6f93d2521af8ce4850872b383968cb 2017-05-23 08:58:21 From: mperrinel Date: 2017-05-23 08:58:21 Subject: [PATCH] Initialisation de la configuration Linux --- diff --git a/.gitignore b/.gitignore index bba0294..237993e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ -CMakeLists.txt.user \ No newline at end of file +CMakeLists.txt.user +/.project diff --git a/analyzer/cmake/FindClangAnalyzer.cmake b/analyzer/cmake/FindClangAnalyzer.cmake new file mode 100644 index 0000000..b13c0a7 --- /dev/null +++ b/analyzer/cmake/FindClangAnalyzer.cmake @@ -0,0 +1,42 @@ +# - try to find scan-build tool +# +# Cache Variables: +# CLANGANALYZER_ROOT_DIR +# CLANGANALYZER_EXECUTABLE +# +# Non-cache variables you might use in your CMakeLists.txt: +# CLANGANALYZER_FOUND +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) + +file(TO_CMAKE_PATH "${CLANGANALYZER_ROOT_DIR}" CLANGANALYZER_ROOT_DIR) +set(CLANGANALYZER_ROOT_DIR + "${CLANGANALYZER_ROOT_DIR}" + CACHE + PATH + "Path to search for scan-build") + +if(CLANGANALYZER_EXECUTABLE AND NOT EXISTS "${CLANGANALYZER_EXECUTABLE}") + set(CLANGANALYZER_EXECUTABLE "notfound" CACHE PATH FORCE "") +endif() + +# If we have a custom path, look there first. +if(CLANGANALYZER_ROOT_DIR) + find_program(CLANGANALYZER_EXECUTABLE + NAMES + scan-build + PATHS + "${CLANGANALYZER_ROOT_DIR}" + PATH_SUFFIXES + bin + NO_DEFAULT_PATH) +endif() + +find_program(CLANGANALYZER_EXECUTABLE NAMES scan-build) + +IF(NOT("${CLANGANALYZER_EXECUTABLE}" STREQUAL "")) + set(CLANGANALYZER_FOUND TRUE) +endif() + +mark_as_advanced(CLANGANALYZER_EXECUTABLE) diff --git a/cmake/CMakeModules/Findcppcheck.cmake b/analyzer/cmake/Findcppcheck.cmake similarity index 100% rename from cmake/CMakeModules/Findcppcheck.cmake rename to analyzer/cmake/Findcppcheck.cmake diff --git a/cmake/CMakeModules/Findcppcheck.cpp b/analyzer/cmake/Findcppcheck.cpp similarity index 100% rename from cmake/CMakeModules/Findcppcheck.cpp rename to analyzer/cmake/Findcppcheck.cpp diff --git a/analyzer/launch-clang-analyzer-linux.sh b/analyzer/launch-clang-analyzer-linux.sh new file mode 100644 index 0000000..8cc659e --- /dev/null +++ b/analyzer/launch-clang-analyzer-linux.sh @@ -0,0 +1,20 @@ + +QT_PATH=".../Qt/5.8/gcc_64/lib/cmake/" + +export CC=/usr/libexec/ccc-analyzer +export CXX=/usr/libexec/c++-analyzer +export CCC_CC=clang +export CCC_CXX=clang++ +export LD=clang++ +export CCC_ANALYZER_VERBOSE=1 + +LD_LIBRARY_PATH=/usr/local/lib64 +export LD_LIBRARY_PATH + +rm -rf build_clang-analyzer +mkdir build_clang-analyzer +cd build_clang-analyzer + +scan-build cmake -DCMAKE_PREFIX_PATH=$QT_PATH -DCMAKE_CXX_COMPILER=clazy -DENABLE_ANALYSIS=false -DENABLE_CPPCHECK=false -DENABLE_FORMATTING=false -DENABLE_CHECKSTYLE=false -BUILD_DOCUMENTATION=false -BUILD_TESTS=false -DCMAKE_BUILD_TYPE=Debug ../../SCIQLOP-Initialisation/ + +scan-build -o clang-analyzer-output make -j2 diff --git a/cmake/compiler/compiler.cmake b/cmake/compiler/compiler.cmake index 4511cb0..7bdfa24 100644 --- a/cmake/compiler/compiler.cmake +++ b/cmake/compiler/compiler.cmake @@ -2,8 +2,11 @@ # compiler.cmake : configure the compilation flags # +message("Compiler id: ${CMAKE_CXX_COMPILER_ID}") IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") INCLUDE("cmake/compiler/compiler_gnu.cmake") +ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + INCLUDE("cmake/compiler/compiler_gnu.cmake") ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") INCLUDE("cmake/compiler/compiler_msvc.cmake") ELSE() diff --git a/cmake/find_libs.cmake b/cmake/find_libs.cmake index 4bb40c2..f797685 100644 --- a/cmake/find_libs.cmake +++ b/cmake/find_libs.cmake @@ -18,9 +18,11 @@ FIND_PACKAGE(Qt5Gui REQUIRED) FIND_PACKAGE(Doxygen) # -# Cppcheck tool +# Analyzer tools # +LIST( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/analyzer/cmake") FIND_PACKAGE(cppcheck) +FIND_PACKAGE(ClangAnalyzer) # # Formatting tools diff --git a/cmake/sciqlop_applications.cmake b/cmake/sciqlop_applications.cmake index 4774b94..6486641 100644 --- a/cmake/sciqlop_applications.cmake +++ b/cmake/sciqlop_applications.cmake @@ -36,3 +36,4 @@ INCLUDE ("cmake/sciqlop_doxygen.cmake") # Source code analysis # INCLUDE ("cmake/sciqlop_code_analysis.cmake") +INCLUDE ("cmake/sciqlop_code_cppcheck.cmake") diff --git a/cmake/sciqlop_code_analysis.cmake b/cmake/sciqlop_code_analysis.cmake index 5a77a08..45418dc 100644 --- a/cmake/sciqlop_code_analysis.cmake +++ b/cmake/sciqlop_code_analysis.cmake @@ -1,12 +1,12 @@ # # sciqlop_code_analysis.cmake -# Launch code source analysis with cppcheck. Can be activated with the -# ANALYZE_CODE option. +# Launch code source analysis with CLANGANALYZER. Can be activated with the +# ENABLE_ANALYSIS option. # # The following CACHE variables are available: -# * CPPCHECK_EXTRA_ARGS: extra arguments for cppcheck; -# * CPPCHECK_OUTPUT: path to the xml report of cppcheck. +# * CLANGANALYZER_EXTRA_ARGS: extra arguments for CLANGANALYZER; +# * CLANGANALYZER_OUTPUT: path to the xml report of CLANGANALYZER. # # The following variables are used (must be set by the cmake file calling this # one): @@ -15,38 +15,30 @@ # # -# Analyze the source code with cppcheck +# Analyze the source code with CLANGANALYZER # -OPTION (ANALYZE_CODE "Analyze the source code with cppcheck" ON) -IF (ANALYZE_CODE) +OPTION (ENABLE_ANALYSIS "Analyze the source code with clang_analyze" ON) +IF (ENABLE_ANALYSIS) - # Make sure cppcheck has been found, otherwise the source code can't be + # Make sure CLANGANALYZER has been found, otherwise the source code can't be # analyzed - IF (CPPCHECK_FOUND) - SET (CPPCHECK_EXTRA_ARGS --inline-suppr --xml --xml-version=2 --enable="warning,style" --force -v - CACHE STRING "Extra arguments for cppcheck") - MARK_AS_ADVANCED (CPPCHECK_EXTRA_ARGS) + IF (CLANGANALYZER_FOUND) - SET (CPPCHECK_OUTPUT "${CMAKE_BINARY_DIR}/cppcheck-report.xml" - CACHE STRING "Output file for the cppcheck report") - MARK_AS_ADVANCED (CPPCHECK_OUTPUT) + SET (CLANGANALYZER_OUTPUT "${CMAKE_BINARY_DIR}/clang-analyzer-ouput" + CACHE STRING "Output file for the CLANGANALYZER report") + MARK_AS_ADVANCED (CLANGANALYZER_OUTPUT) - SET (CPPCHECK_EXCLUDE_DIRS) - FOREACH (dir ${ANALYSIS_EXCLUDE_DIRS}) - LIST (APPEND CPPCHECK_EXCLUDE_DIRS "-i${dir}") - ENDFOREACH () + SET (CLANGANALYZER_EXTRA_ARGS -o ${CLANGANALYZER_OUTPUT} + CACHE STRING "Extra arguments for CLANGANALYZER") + MARK_AS_ADVANCED (CLANGANALYZER_EXTRA_ARGS) - # Add the analyze target to launch cppcheck + # Add the analyze target to launch CLANGANALYZER ADD_CUSTOM_TARGET (analyze COMMAND - ${CPPCHECK_EXECUTABLE} - ${CPPCHECK_EXTRA_ARGS} - ${ANALYSIS_INPUT_DIRS} - ${CPPCHECK_EXCLUDE_DIRS} - 2> ${CPPCHECK_OUTPUT} + sh ${CMAKE_CURRENT_SOURCE_DIR}/analyzer/launch-clang-analyzer-linux.sh ) - ELSE (CPPCHECK_FOUND) - MESSAGE (STATUS "The source code won't be analyzed - Cppcheck not found") - ENDIF (CPPCHECK_FOUND) -ENDIF (ANALYZE_CODE) + ELSE (CLANGANALYZER_FOUND) + MESSAGE (STATUS "The source code won't be analyzed - CLANGANALYZER not found") + ENDIF (CLANGANALYZER_FOUND) +ENDIF (ENABLE_ANALYSIS) diff --git a/cmake/sciqlop_code_cppcheck.cmake b/cmake/sciqlop_code_cppcheck.cmake new file mode 100644 index 0000000..772d0eb --- /dev/null +++ b/cmake/sciqlop_code_cppcheck.cmake @@ -0,0 +1,52 @@ +# +# sciqlop_code_analysis.cmake + +# Launch code source analysis with cppcheck. Can be activated with the +# ENABLE_CPPCHECK option. +# +# The following CACHE variables are available: +# * CPPCHECK_EXTRA_ARGS: extra arguments for cppcheck; +# * CPPCHECK_OUTPUT: path to the xml report of cppcheck. +# +# The following variables are used (must be set by the cmake file calling this +# one): +# * ANALYSIS_INPUT_DIRS: directories to analyze; +# * ANALYSIS_EXCLUDE_DIRS: directories to exclude from the analysis. +# + +# +# Analyze the source code with cppcheck +# +OPTION (ENABLE_CPPCHECK "Analyze the source code with cppcheck" ON) +IF (ENABLE_CPPCHECK) + + # Make sure cppcheck has been found, otherwise the source code can't be + # analyzed + IF (CPPCHECK_FOUND) + SET (CPPCHECK_EXTRA_ARGS --inline-suppr --xml --xml-version=2 --enable="warning,style" --force -v + CACHE STRING "Extra arguments for cppcheck") + MARK_AS_ADVANCED (CPPCHECK_EXTRA_ARGS) + + SET (CPPCHECK_OUTPUT "${CMAKE_BINARY_DIR}/cppcheck-report.xml" + CACHE STRING "Output file for the cppcheck report") + MARK_AS_ADVANCED (CPPCHECK_OUTPUT) + + SET (CPPCHECK_EXCLUDE_DIRS) + FOREACH (dir ${ANALYSIS_EXCLUDE_DIRS}) + LIST (APPEND CPPCHECK_EXCLUDE_DIRS "-i${dir}") + ENDFOREACH () + + # Add the analyze target to launch cppcheck + ADD_CUSTOM_TARGET (cppcheck + COMMAND + ${CPPCHECK_EXECUTABLE} + ${CPPCHECK_EXTRA_ARGS} + ${ANALYSIS_INPUT_DIRS} + ${CPPCHECK_EXCLUDE_DIRS} + 2> ${CPPCHECK_OUTPUT} + ) + + ELSE (CPPCHECK_FOUND) + MESSAGE (STATUS "The source code won't be analyzed - Cppcheck not found") + ENDIF (CPPCHECK_FOUND) +ENDIF (ENABLE_CPPCHECK) diff --git a/formatting/clangAnalyser/launch-clang-analyzer.sh b/formatting/clangAnalyser/launch-clang-analyzer.sh deleted file mode 100644 index 1c0aec3..0000000 --- a/formatting/clangAnalyser/launch-clang-analyzer.sh +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/bash - -function usage { - echo " usage: $0 [ninja|make]" - echo " Launch clang-analyzer on the sources with ninja or make." - exit -} - -function execAndTest { - "$@" - local status=$? - if [ $status -ne 0 ]; then - echo "" >&2 - echo " ERROR with $1" >&2 - exit $status - fi - return $status -} - -# Défaut : Ninja -generator="Ninja" -builder="ninja" - -if [[ $# -gt 1 ]]; then - echo " ERROR: illegal number of arguments." >&2 - echo " provided: $#" >&2 - echo " expected: 0 or 1" >&2 - echo "" >&2 - usage -elif [[ $# -eq 1 ]]; then - if [[ "$1" == "ninja" ]]; then - echo "=> Using multiple jobs" - generator="Ninja" - builder="ninja" - elif [[ "$1" == "make" ]]; then - echo "=> Using single job" - generator="Ninja" - builder="ninja -j 1" - elif [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then - usage - else - echo " ERREUR:" >&2 - echo " L'option doit être 'ninja' ou 'make'" >&2 - echo "" >&2 - exit -1 - fi -fi - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -# On se place à la racine du projet SciQlop -execAndTest cd $DIR -if ! [ -e CMakeLists.txt -a -e README.md ]; then - echo " ERREUR:" >&2 - echo " CMakeLists.txt ou README.md n'existent pas." >&2 - echo " Verifier que le script est bien execute a partir" >&2 - echo " du sous-dossier 'scripts' de SciQlop" >&2 - echo "" - exit 1 -fi - -# Vérification de l'existence de scan-build, ccc-analyzer, ccc-analyzer.bat -# et c++-analyzer.bat -export SCAN_BUILD_DIR="C:/Dev/CNRS-DEV/cfe/tools/scan-build" -export CLANG_BUILD_DIR="C:/Appli/LLVM/bin" -if ! [ -e $SCAN_BUILD_DIR/bin/scan-build \ - -a -e $SCAN_BUILD_DIR/libexec/ccc-analyzer \ - -a -e $SCAN_BUILD_DIR/libexec/ccc-analyzer.bat \ - -a -e $SCAN_BUILD_DIR/libexec/c++-analyzer.bat ]; then - echo " ERREUR:" - echo " Les fichiers scan-build, ccc-analyzer, ccc-analyzer.bat" - echo " et c++-analyzer.bat ne sont pas présents dans le dossier :" - echo " $SCAN_BUILD_DIR." - echo " Assurez-vous d'avoir installé clang-analyzer en relançant le" - echo " script d'installation d'environnement de SciQlop." - echo "" - exit 2 -fi - -# Création d'un dossier build/debug_clanganalyzer et cd dedans -execAndTest mkdir -p build/debug_clanganalyzer -execAndTest cd build/debug_clanganalyzer - -# Création d'un dossier clang-analyzer-output pour recevoir les -# rapports -execAndTest mkdir -p clang-analyzer-output - -# Export des compilateurs pour clang-analyzer -export CCC_CC=gcc -export CCC_CXX=g++ - -# Exécution de cmake avec scan-build pour initialiser clang-analyzer -execAndTest $SCAN_BUILD_DIR/bin/scan-build \ - -o clang-analyzer-output \ - --use-analyzer $CLANG_BUILD_DIR/clang.exe \ - cmake -G "$generator" \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_CXX_COMPILER=C:/Appli/LLVM/libexec/c++-analyzer.bat \ - -DCMAKE_C_COMPILER=C:/Appli/LLVM/libexec/ccc-analyzer.bat \ - -DCMAKE_CXX_COMPILER_ID=GNU \ - -DBUILD_TESTS=NONE \ - -DENABLE_CHECKSTYLE=OFF \ - -DENABLE_CODE_ANALYSIS=OFF \ - -DENABLE_FORMATTING=OFF \ - ../.. - -# Clean de la construction pour avoir tous les bugs tout le temps -execAndTest $builder clean - -# Exécution de ninja avec scan-build pour lancer clang-analyzer -execAndTest $SCAN_BUILD_DIR/scan-build \ - -o clang-analyzer-output \ - --use-analyzer $CLANG_BUILD_DIR/clang.exe \ - $builder diff --git a/sqpapp/src/main.cpp b/sqpapp/src/main.cpp index 6f07a2e..5b8c8ca 100644 --- a/sqpapp/src/main.cpp +++ b/sqpapp/src/main.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +//#include #include int main(int argc, char *argv[])