diff options
author | Gerald Combs <gerald@wireshark.org> | 2021-04-12 12:13:02 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2021-04-14 12:42:00 -0700 |
commit | 1dc50f7433e21f1dbb7145c290d7d40ec96ec070 (patch) | |
tree | a927199d61b104ad9e5c505c1505a259ef7ce19a | |
parent | cf46f0d74765ef4f49934a83de1c7eb70b73dbd9 (diff) |
CMake+CI: Colorize our compiler output.
As described at
https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949
both Clang and gcc generate colorized output when they detect a
terminal, but not for piped output, which is the case when using Ninja.
Add an ENABLE_COMPILER_COLOR_DIAGNOSTICS CMake option, and set it to
"ON" when we're using Ninja.
In the merge-req:ubuntu-gcc-ctest and merge-req:ubuntu-clang-other-tests
GitLab CI jobs, generate colorized HTML report artifacts using
ansi2html.
-rw-r--r-- | .gitlab-ci.yml | 14 | ||||
-rw-r--r-- | CMakeLists.txt | 12 | ||||
-rw-r--r-- | CMakeOptions.txt | 6 |
3 files changed, 29 insertions, 3 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b279103db9..0f53faa95a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,6 +18,8 @@ variables: GIT_DEPTH: "1" GIT_FETCH_EXTRA_FLAGS: "--depth=5000" CCACHE_DIR: "${CI_PROJECT_DIR}/ccache" + # Enable color output in CMake, Ninja, and other tools. https://bixense.com/clicolors/ + CLICOLOR_FORCE: 1 .build: stage: build @@ -342,10 +344,14 @@ merge-req:ubuntu-gcc-ctest: script: # build-ubuntu puts us in `build`. - CC=gcc CXX=g++ cmake -DENABLE_EXTRA_COMPILER_WARNINGS=on -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DENABLE_CCACHE=ON -G Ninja .. - - ninja + - script --command ninja --flush --quiet --return ../gcc_report.txt + - ansi2html < ../gcc_report.txt > ../gcc_report.html - ninja test-programs - chown -R user . - su user -c "ctest --parallel $(getconf _NPROCESSORS_ONLN) --force-new-ctest-process --verbose" + artifacts: + paths: + - gcc_report.html merge-req:ubuntu-clang-other-tests: extends: clang-11 @@ -363,14 +369,16 @@ merge-req:ubuntu-clang-other-tests: - if [[ -s "cppcheck_report.xml" ]]; then cppcheck-htmlreport --file cppcheck_report.xml --report-dir . ; fi - cd build - cmake -DENABLE_EXTRA_COMPILER_WARNINGS=on -DENABLE_CHECKHF_CONFLICT=on -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DENABLE_CCACHE=ON -G Ninja .. - - ninja + - script --command ninja --flush --quiet --return ../clang_report.txt + - ansi2html < ../clang_report.txt > ../clang_report.html - ./run/tshark -v - sh -c '[ ! -e ../tools/validate-clang-check.sh ] || ../tools/validate-clang-check.sh' - ninja checkAPI artifacts: paths: - - cppcheck_report.xml + - clang_report.html - cppcheck_report.html + - cppcheck_report.xml - item_calls_check.txt - tfs_check.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index a330d9bf68..bdd8130545 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -796,6 +796,18 @@ else() # ! MSVC ) endif() + if(ENABLE_COMPILER_COLOR_DIAGNOSTICS) + if(CMAKE_C_COMPILER_ID MATCHES "Clang") + set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS} + -fcolor-diagnostics + ) + elseif(CMAKE_C_COMPILER_ID MATCHES "GNU") + set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS} + -fdiagnostics-color=always + ) + endif() + endif() + add_definitions( -DG_DISABLE_DEPRECATED -DG_DISABLE_SINGLE_INCLUDES diff --git a/CMakeOptions.txt b/CMakeOptions.txt index a651c2ebb6..4c42664645 100644 --- a/CMakeOptions.txt +++ b/CMakeOptions.txt @@ -55,6 +55,12 @@ option(ENABLE_FUZZER "Enable libFuzzer instrumentation for use with fuzzshark" O option(ENABLE_CHECKHF_CONFLICT "Enable hf conflict check for debugging (start-up may be slower)" OFF) option(ENABLE_CCACHE "Speed up compiling and linking using ccache if possible" OFF) +if(CMAKE_GENERATOR STREQUAL "Ninja") + option(ENABLE_COMPILER_COLOR_DIAGNOSTICS "Always enable the compiler's color diagnostic output" ON) +else() + option(ENABLE_COMPILER_COLOR_DIAGNOSTICS "Always enable the compiler's color diagnostic output" OFF) +endif() + if (WIN32) option(ENABLE_LTO "Improves performance using Link time Optimization" ON) else() |