CPM.cmake icon indicating copy to clipboard operation
CPM.cmake copied to clipboard

CPM_INDENT is not inserted everywhere and no CPM_DESINDENT

Open flagarde opened this issue 3 years ago • 5 comments

Hello,

Thx for you nice tool it's wonderful. I noticed that CPM_INDENT is not used everywhere in the code? This is expected ?

I would like to add an CPM_DESINDENT or other name to be able to use CPM_INDENT to use colorization. For now I can do it but I can't desactivate the color.

It wouyld be then possible to do :

set(CPM_INDENT MyColor)
set(CPM_DESINDENT White)

Would you accept a PR to add this variable CPM_DESINDENT or a better name ?

flagarde avatar Jan 12 '22 08:01 flagarde

Hey thanks for the feedback, happy you like it!

I noticed that CPM_INDENT is not used everywhere in the code? This is expected ?

Hm I think there are some places where the indent wouldn't make sense as they are not scoped, e.g. fatal errors. For other purposes this may be an oversight.

I would like to add an CPM_DESINDENT or other name to be able to use CPM_INDENT to use colorization. For now I can do it but I can't desactivate the color.

I'm not sure if that would already be too far off from its original meaning. Maybe it would be better to introduce two new variables like CPM_LEFT_LOG, CPM_RIGHT_LOG? Probably it would also make sense to add a function for logging, for more consistency and easier customisation.

TheLartians avatar Jan 12 '22 20:01 TheLartians

Yes I agree the name is not very nice. And the ones proposed are much better..

Concerning the indent on fatal errors it's true indentation are not useful but I used CPM_INDENT as [CPM].

Addind the values you propose looks great. For a logger I wrote something like this : https://github.com/flagarde/CMakeCM/blob/main/modules/Missives.cmake but it's maybe too much code just for logging some message in cpm

flagarde avatar Jan 12 '22 20:01 flagarde

Would you allow a PR with CPM_LEFT_LOG CPM_RIGHT_LOG ?

flagarde avatar Jan 13 '22 10:01 flagarde

Sure, though if its a lot of extra code, I think I'd prefer a small helper function for logging. But I'd be happy to take a look at the PR!

TheLartians avatar Jan 13 '22 21:01 TheLartians

Well it depends a lot of what you expect from a logger.

  • Colorization : Possible but need to hack a bit as CMake doesn't provide any hint to know if the terminal or IDE accept ANSI color escape sequences. I raised an issue https://gitlab.kitware.com/cmake/cmake/-/issues/22954 for this.
  • Add level : be able to register new levels based on the default ones.

This is what can be done with around ~200 lines of code (would need more to check TERM env for colorization)

missive_mode(NAME "MY_ERROR" PARENT_MODE FATAL_ERROR STYLE "Blue" APPEND_BEGIN "#### " APPEND_END " !!!!!!!!" APPEND_STYLE_BEGIN "Green" APPEND_STYLE_END "BoldYellow")
missive_mode(NAME "PYTHON" STYLE "Green" APPEND_BEGIN "[Python]:" APPEND_END "!!" APPEND_STYLE_BEGIN "BackGreen" APPEND_STYLE_END "Yellow" )
missive_mode(NAME "SEND_ERROR" STYLE "BoldRed")

missive(SEND_ERROR "ERROR!!!")
message(STATUS "")
missive(PYTHON "I'm a python message")
message(STATUS "")
missive(MY_ERROR "OUPS")

After CMAke 3.21 :

Screenshot_20220114_153730

Before:

Screenshot_20220114_153821

flagarde avatar Jan 14 '22 07:01 flagarde