Skip to content

Commit

Permalink
CMake: Default color diagnostics to force-on with ccache/ninja
Browse files Browse the repository at this point in the history
Reading diagnostics with ANSI color codes in between is unnecessarily
hard. We now make use of the cmake documented switch to control color
output. And we only force color on if the tooling suggest it might be
necessary.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
  • Loading branch information
mattkretz committed Sep 24, 2024
1 parent 6d85d74 commit 1b0c2c6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ else ()
message(STATUS "ccache will not be used")
endif ()

# Prefer forced colored compiler output if there's a chance we'd otherwise get none at all.
# Ninja and ccache "consume" the compiler output, breaking the terminal detection of compilers.
# ccache tries to solve the problem, but can only do so if it determines that it's calling GCC or Clang. It uses a very lightweight heuristic, which breaks easily.
if ((CMAKE_GENERATOR STREQUAL "Ninja" OR (CCACHE_PROGRAM AND USE_CCACHE)) AND NOT DEFINED CMAKE_COLOR_DIAGNOSTICS)
message(STATUS "Forcing compiler color output due to the use of Ninja and/or ccache. Use -DCMAKE_COLOR_DIAGNOSTICS=OFF to turn it off.")
set(CMAKE_COLOR_DIAGNOSTICS ON)
endif()

set(CMAKE_EXT_DEP_WARNING_GUARD "")
if (DISABLE_EXTERNAL_DEPS_WARNINGS) # enable warnings for external dependencies
set(CMAKE_EXT_DEP_WARNING_GUARD SYSTEM)
Expand Down Expand Up @@ -100,15 +108,14 @@ endif ()
string(REPLACE ";" " " ALL_COMPILER_FLAGS "${ALL_COMPILER_FLAGS}")

if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") # set default C++ STL to Clang's libc++ when using Clang
add_compile_options(-stdlib=libc++ -fcolor-diagnostics)
add_compile_options(-stdlib=libc++)
if (TIMETRACE)
add_compile_options(-ftime-trace)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ftime-trace")
message(STATUS "Enable TIMETRACE: ${TIMETRACE}")
endif ()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
if (ENABLE_TBB)
find_package(TBB REQUIRED)
target_link_libraries(gnuradio-options INTERFACE TBB::tbb)
Expand Down

0 comments on commit 1b0c2c6

Please sign in to comment.