Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Force GCC/Clang color diagnostics for Ninja (#1596) #1597

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

maxrdz
Copy link
Contributor

@maxrdz maxrdz commented Jan 18, 2024

Issue description

Linux users are recommended to use Ninja when generating the build files through CMake. Ninja buffers output, so tools are writing to a pipe, not directly to the terminal, so auto-detection may turn ANSI colored output off conservatively.

Solution description

This PR forces color diagnostics by setting CMAKE_COLOR_DIAGNOSTICS to ON on CMake versions 3.24 and above. For older CMake versions, compiler flags are invoked manually for GCC and Clang.

Checklist

I have done my best to ensure that…

  • …I have familiarized myself with the CONTRIBUTING.md file
  • …this change follows the coding style and design patterns of the codebase
  • …I own the intellectual property rights to this code
  • …the intent of this change is clearly explained
  • …existing uses of the Panda3D API are not broken
  • …the changed code is adequately covered by the test suite, where possible.

Linux users are recommended to use Ninja when generating the build files
through CMake. Ninja buffers output, so tools are writing to a pipe, not
directly to the terminal, so auto-detection may turn ANSI colored output
off conservatively. This forces color diagnostics.
@maxrdz
Copy link
Contributor Author

maxrdz commented Jan 18, 2024

This resolves #1596.

Copy link
Collaborator

@Moguri Moguri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of a new flag and trying to support older versions of Cmake, should we just change the default for CMAKE_COLOR_DIAGNOSTICS for relevant generators and CMake versions?

CMakeLists.txt Outdated Show resolved Hide resolved
@maxrdz
Copy link
Contributor Author

maxrdz commented Jan 18, 2024

Maybe instead of a new flag and trying to support older versions of Cmake, should we just change the default for CMAKE_COLOR_DIAGNOSTICS for relevant generators and CMake versions?

The CMAKE_COLOR_DIAGNOSTICS option is relatively new to CMake (version 3.24.x) so I think it would be a safe route to take if we first verify the version of CMake being used.

@maxrdz
Copy link
Contributor Author

maxrdz commented Jan 18, 2024

I do agree that we can just always apply it for Ninja gen builds and remove the new CMake option, since it should not affect anything with the build unless someone doesn't want the compiler to print ANSI colors.

@maxrdz maxrdz requested a review from Moguri January 18, 2024 23:40
Copy link
Member

@rdb rdb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with this, but can we make it a cache variable, so that users can disable it? And if people turn it off, we shouldn't add the compiler option.

@rdb rdb linked an issue Jan 23, 2024 that may be closed by this pull request
@maxrdz maxrdz requested a review from rdb February 5, 2024 17:51
@maxrdz
Copy link
Contributor Author

maxrdz commented Feb 5, 2024

Sorry for the late update, was busy for a few weeks. :)

Copy link
Collaborator

@Moguri Moguri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am okay with this as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CMake: No ANSI colored output when using CMake + Ninja
3 participants