Skip to content

Commit

Permalink
refactor: enable ninja colorful output as macro of rocbuild.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
zchrissirhcz committed Nov 22, 2024
1 parent a8e40e2 commit 737adfc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
12 changes: 0 additions & 12 deletions ninja_colorful_output.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,3 @@
# Last update: 2024-05-26 23:30:00
cmake_minimum_required(VERSION 3.15)
include_guard()

# When building a CMake-based project, Ninja may speedup the building speed, comparing to Make.
# However, with `-GNinja` specified, compile errors are with no obvious colors.
# This cmake plugin just solve this mentioned problem, giving colorful output for Ninja.
## References: https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949

add_compile_options(
"$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-fdiagnostics-color=always>"
"$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-fcolor-diagnostics>"
"$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>"
"$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-fcolor-diagnostics>"
)
17 changes: 16 additions & 1 deletion rocbuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ macro(rocbuild_set_artifacts_path)
endmacro()


rocbuild_set_artifacts_path()
macro(rocbuild_enable_ninja_colorful_output)
# When building a CMake-based project, Ninja may speedup the building speed, comparing to Make.
# However, with `-GNinja` specified, compile errors are with no obvious colors.
# This cmake plugin just solve this mentioned problem, giving colorful output for Ninja.
## References: https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949
add_compile_options(
"$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-fdiagnostics-color=always>"
"$<$<COMPILE_LANG_AND_ID:CXX,Clang,AppleClang>:-fcolor-diagnostics>"
"$<$<COMPILE_LANG_AND_ID:C,GNU>:-fdiagnostics-color=always>"
"$<$<COMPILE_LANG_AND_ID:C,Clang,AppleClang>:-fcolor-diagnostics>"
)
endmacro()


rocbuild_set_artifacts_path()
rocbuild_enable_ninja_colorful_output()
4 changes: 0 additions & 4 deletions test/ninja_colorful_output/CMakeLists.txt

This file was deleted.

7 changes: 0 additions & 7 deletions test/ninja_colorful_output/test.cpp

This file was deleted.

0 comments on commit 737adfc

Please sign in to comment.