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: Add cMake file formatting to pre-commit #15792

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

chennes
Copy link
Member

@chennes chennes commented Aug 6, 2024

This is a proposed solution to fix #15780 -- it adds our cMake files to a pre-commit auto-formatter, and applies that format to all cMake files. Details:

  • 4 space indentation levels
  • 100 char line length
  • Spaces before parenthesis
  • Autosort lists when order doesn't matter
  • Normalize to lowercase cMake command names (recommended by cMake developers)

@github-actions github-actions bot added the Packaging/building Related to building, compiling or packaging FreeCAD label Aug 6, 2024
@maxwxyz maxwxyz added this to the 1.0 milestone Aug 6, 2024
Comment on lines 3 to 4
# COIN3D_DOC_FOUND - we have access to Coin3D doc, either locally or on the net
# COIN3D_DOC_TAGFILE - full name of the tag file COIN3D_DOC_PATH - path to html Coin3D doc
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting here is imprecise: COIN3D_DOC_PATH - path to html Coin3D doc needs to be on a newline

@chennes
Copy link
Member Author

chennes commented Aug 6, 2024

I don't love the removal of spaces from things like

if(SOMETHING)

That seems too compressed to my eye, so I'm inclined to also change that setting to enforce a space before the paren.

@chennes chennes force-pushed the cmakeFormatPreCommit branch 5 times, most recently from 5de2471 to 0f2d55c Compare August 9, 2024 15:06
@chennes
Copy link
Member Author

chennes commented Aug 12, 2024

Comments welcome, we will talk about this in the next dev meeting.

@chennes chennes requested a review from wwmayer August 17, 2024 18:00
@yorikvanhavre
Copy link
Member

Waiting for further review

@wwmayer
Copy link
Contributor

wwmayer commented Aug 22, 2024

Most of the auto-formatting is OK or acceptable but in cases like cMake/FreeCadMacros.cmake or src/Mod/Fem/CMakeLists.txt it completely breaks readability.

@chennes
Copy link
Member Author

chennes commented Aug 25, 2024

Most of the auto-formatting is OK or acceptable but in cases like cMake/FreeCadMacros.cmake or src/Mod/Fem/CMakeLists.txt it completely breaks readability.

Can you clarify which elements you are concerned about in those files? Nothing jumps out at me, so I'm not sure what to adjust in the configuration to resolve your comment.

ETA: If in the FreeCadMacros it was the argument list formatting, I've cleaned that up (the auto-formatter is very picky about what it recognizes as a list).

@chennes chennes force-pushed the cmakeFormatPreCommit branch 5 times, most recently from 068d978 to f9ef016 Compare August 25, 2024 03:08
@wwmayer
Copy link
Contributor

wwmayer commented Aug 25, 2024

If in the FreeCadMacros it was the argument list formatting, I've cleaned that up (the auto-formatter is very picky about what it recognizes as a list).

Yes, this is what I was talking about. Looks much better now. Thanks!

But the problems in Fem's CMakeLists.txt file still exist. In the handwritten form one filename per line was used while now there are two or three filenames per line which is more difficult to read.

@chennes
Copy link
Member Author

chennes commented Aug 26, 2024

But the problems in Fem's CMakeLists.txt file still exist. In the handwritten form one filename per line was used while now there are two or three filenames per line which is more difficult to read.

I did some playing around with the max_pargs_hwrap setting in the formatter (which controls how many arguments before it switches to a vertical formatting), but any setting lower than the six it defaults to makes problems elsewhere. There is not any good fine-grained control, this formatter is sort of a bludgeon. I have put # cmake-format: off tags around the relevant blocks in FEM's cMakeLists.txt file and hand-formatted the lists to match the auto-formatter's vertical style. We could also exclude the FEM file from the pre-commit entirely, if you'd prefer.

cMake/FindEigen3.cmake Outdated Show resolved Hide resolved
@yorikvanhavre
Copy link
Member

Skipping this one at today's M3 since it's not blocking the RC

@chennes chennes modified the milestones: 1.0, Post 1.0 Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Packaging/building Related to building, compiling or packaging FreeCAD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cMake: No project-level formatting standard
5 participants