Skip to content

Conversation

@josuah
Copy link
Contributor

@josuah josuah commented Nov 15, 2025

The rules are interpolated from what there is on the docs:

https://docs.zephyrproject.org/latest/contribute/style/cmake.html#commands-and-syntax

# Good:
target_sources(my_target PRIVATE
  src/file1.cpp
  src/file2.cpp
)

And what seemed to be common on in-tree, in particular for if() and messages():

  • Long lines have continuation lines use 2 spaces
    if(long line ...
      continuation line...
    
    function(arg1 arg2...
      continuation line...
    
  • When the first line is filled with content, the closing parenthesis is
    at the end of the last continuation line
    if(long line filled until the end ...
      continuation line...)
    
    message(long line filled until the end...
      continuation line...)
    
  • When the first line is empty or only containing a distinct label, such
    as an UPPERCASE label) the closing parenthesis is on its own line,
    with same indentation level as the first line.
    zephyr_library_sources(
      something_a.c
      something_b.c
    )
    
    zephyr_library_sources_ifdef(CONFIG_SOMETHING
      something_a.c
      something_b.c
    )
    
  • Call to message() are converted from \ for escaping newlines to a list
    of "... " strings, with an empty space at the end if separation between
    words is needed.
    message("long line... Hello "
      "cmake! continuation line...")
    

If anything seems wrong choice, let me know of what to apply and I'd be glad to apply it again tree-wide.

If the scope of modifications is wrong (i.e. should do all CMakeLists.txt and .cmake), then let me know and I would change the scope for this PR.

I am keeping it as a draft for now to avoid triggering the bot.

@josuah josuah force-pushed the pr_cmakelists_txt_indentation branch 5 times, most recently from ec4d920 to 58840e2 Compare November 15, 2025 21:24
@josuah
Copy link
Contributor Author

josuah commented Nov 15, 2025

Since this touches to every CMakeLists.txt, a second batch of commit also adds zephyr-keep-sorted-start/end comments for both CMakeLists.txt and Kconfig, making just one PR for all the "CMake style related changes".

If this is too much for a single PR, then I can easily split it.

@josuah josuah force-pushed the pr_cmakelists_txt_indentation branch from 58840e2 to 5351b5e Compare November 15, 2025 22:52
@josuah josuah requested a review from jeremybettis November 16, 2025 00:34
@josuah josuah added the Trivial Changes that can be reviewed by anyone, i.e. doc changes, minor build system tweaks, etc. label Nov 17, 2025
nashif
nashif previously approved these changes Nov 17, 2025
jhedberg
jhedberg previously approved these changes Nov 17, 2025
tejlmand
tejlmand previously approved these changes Nov 17, 2025
Copy link
Contributor

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

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

approved.

Observations to be followed up.

Thalley
Thalley previously approved these changes Nov 17, 2025
Apply the CMake style guidelines to all CMakeList.txt files in boards/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to all CMakeList.txt files in arch/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to all CMakeList.txt files in cmake/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to CMakeList.txt files in drivers/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to CMakeList.txt files in subsys/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to CMakeList.txt files in samples/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to CMakeList.txt files in tests/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to CMakeList.txt files in soc/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to CMakeList.txt files in modules/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Apply the CMake style guidelines to CMakeList.txt files in share/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
Use the "zephyr-keep-sorted-start/stop" comment to have CI check
the alphabetical order of includes, to help reducing the chance
of conflicts while contributing drivers.

Signed-off-by: Josuah Demangeon <me@josuah.net>
@josuah josuah dismissed stale reviews from tejlmand, nordicjm, nashif, and Thalley via 40cbd53 November 17, 2025 17:59
@josuah josuah force-pushed the pr_cmakelists_txt_indentation branch from 7797c11 to 40cbd53 Compare November 17, 2025 17:59
@josuah
Copy link
Contributor Author

josuah commented Nov 17, 2025

force-push:

  • grouped by top-level dirs instead of per-area granularity
  • style: prefix
  • applied review comments from @tejlmand

@sonarqubecloud
Copy link

Please retry analysis of this Pull-Request directly on SonarQube Cloud

@josuah josuah requested a review from tejlmand November 17, 2025 18:05
@nashif
Copy link
Member

nashif commented Nov 17, 2025

@tejlmand already approved, merging this now to avoid any need to rebase again given the amount of files being changed and the fact this is considered "trivial"

@nashif nashif merged commit 30950b8 into zephyrproject-rtos:main Nov 17, 2025
47 of 53 checks passed
@josuah josuah deleted the pr_cmakelists_txt_indentation branch November 18, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Build System area: Coding Guidelines Coding guidelines and style area: Kconfig Trivial Changes that can be reviewed by anyone, i.e. doc changes, minor build system tweaks, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants