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(enhance):add NuttX CMake extensions module #14747

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

xuxin930
Copy link
Contributor

Summary

[Enhancement]

  1. Wrapped CMake native method is nuttx_cmake module,
    It can be quickly called in the build system

  2. Add sanity check for commonly called functions

This will make our build system simpler and more modern :-)

e.g:

# we are currently adding an application library like:
# apps/libfoo/CMakeLists.txt
if(CONFIG_LIB_FOO)
  set(FLAGS -Werror)
  set(INCDIR ${CMAKE_CURRENT_LIST_DIR}/include)

  file(GLOB CSRCS ${CMAKE_CURRENT_LIST_DIR}/*.c)
  set(CSRCS ${CSRCS})

  if(CONFIG_AAA)
    list(APPEND CSRCS a.c)
  endif()
 
  if(CONFIG_BBB)
    list(APPEND CSRCS b.c)
  endif()

  if(CONFIG_OPT)
    list(APPEND FLAGS -Os)
  endif()
  
  nuttx_add_library(foo STATIC)
  target_sources(foo PRIVATE ${CSRCS})
  target_compile_options(foo PRIVATE ${FLAGS})
  target_include_directories(foo PRIVATE ${INCDIR})

endif()
# after using the extension, it can be simplified to:
# apps/libfoo/CMakeLists.txt
nuttx_library_ifdef(CONFIG_LIB_FOO foo)

nuttx_wildcard_sources(./*.c)
nuttx_sources_ifdef(CONFIG_AAA a.c)
nuttx_sources_ifdef(CONFIG_BBB b.c)

nuttx_compile_options(-Werror)
nuttx_compile_options_ifdef(CONFIG_OPT -Os)

nuttx_include_directories(${CMAKE_CURRENT_LIST_DIR}/include)

Impact

Enhanced cmake module, forward compatibility, no impact on the past

Testing

I haven't made any module changes to use the new extensions,
but I've modified the tests in local apps and it's feasible.
It greatly reduces the amount of code and is elegant enough.

Wrapped CMake native method is nuttx_cmake module
It can be quickly called in the build system

Signed-off-by: xuxin19 <[email protected]>
@github-actions github-actions bot added Area: Build system Size: M The size of the change in this PR is medium labels Nov 12, 2024
@nuttxpr
Copy link

nuttxpr commented Nov 12, 2024

[Experimental Bot, please feedback here]

No, this PR does not fully meet the NuttX requirements. Here's why:

  • Insufficient Testing Information: The testing section is inadequate. Saying "modified the tests in local apps and it's feasible" isn't enough. You MUST provide:

    • Specific build hosts used (OS, CPU, Compiler version).
    • Specific target(s) (architecture, board, configuration).
    • Actual log output before the change.
    • Actual log output after the change demonstrating the improvement. This is crucial for reviewers to verify the change works as intended.
  • Vague Impact Description: While you mention forward compatibility and no backward compatibility issues, you need to be more specific. Does this change affect any existing CMakeLists.txt files? If not, explicitly state that. If so, how many and will they need modification?

  • Missing Issue References: Are there any related NuttX or NuttX Apps issues that this PR addresses? If so, link them. If not, explicitly state "N/A".

  • Clarity on "nuttx_cmake module": Is this a completely new module? Or modifications to an existing one? Be explicit. The phrasing "wrapped CMake native method" is unclear. Explain what native methods are being wrapped and why.

Here's how you can improve the PR description:

Example of Improved PR Description

Summary

[Enhancement] This PR introduces a new CMake module, nuttx_cmake, to simplify and modernize the NuttX build system. This module provides helper functions that wrap common CMake commands, reducing boilerplate code and improving readability. Specifically, it provides functions like nuttx_library_ifdef, nuttx_wildcard_sources, nuttx_sources_ifdef, nuttx_compile_options, and nuttx_compile_options_ifdef.

This simplifies the creation and configuration of libraries and applications within the NuttX build system, as demonstrated in the example below.

Example:

# Before: apps/libfoo/CMakeLists.txt
# ... (lengthy CMake code) ...

# After: apps/libfoo/CMakeLists.txt
nuttx_library_ifdef(CONFIG_LIB_FOO foo)
# ... (simplified CMake code) ...

Related NuttX Issue: N/A
Related NuttX Apps Issue/PR: N/A

Impact

  • New Feature Added: Yes, the nuttx_cmake module.
  • Impact on User: YES. Users can now leverage the simplified CMake commands in their CMakeLists.txt files. While existing CMakeLists.txt files should continue to work without modification, users are encouraged to adopt the new functions for improved maintainability. (Note: Quantify if any existing files must be modified).
  • Impact on Build: YES. The build system now includes the nuttx_cmake module.
  • Impact on Hardware: NO.
  • Impact on Documentation: YES. Documentation updates are required to explain the new CMake module and its usage. This documentation will be provided as part of this PR. (Specify where the documentation is).
  • Impact on Security: NO.
  • Impact on Compatibility: Forward compatible. Backward compatible with existing CMakeLists.txt files (Clarify this point thoroughly).
  • Anything else to consider: N/A

Testing

I confirm that changes are verified on my local setup and work as intended:

  • Build Host(s): Ubuntu 22.04, x86_64, GCC 11.3.0
  • Target(s): sim:nsh

Testing logs before change (apps/examples/hello/CMakeLists.txt):

#  (Paste actual build log output here)

Testing logs after change (apps/examples/hello/CMakeLists.txt):

# (Paste actual build log output showing the effect of the change, e.g., reduced build time or simplified log messages)

By providing concrete details and following the NuttX requirements carefully, you will increase the likelihood of your PR being accepted. Remember to replace the example details with your specific information.

@xuxin930
Copy link
Contributor Author

hi @acassis @anchao @raiden00pl please review whether we can do this.
so we can continue to enhance the extensions.
and then gradually enhance our build system, this is just the beginning.

@acassis
Copy link
Contributor

acassis commented Nov 12, 2024

@xuxin930 I think it is fine! What was your concern? Since it doesn't disturb the original build system using Makefiles, it is fine for me.

@anchao
Copy link
Contributor

anchao commented Nov 12, 2024

I am fine with similar implementations, and such syntax is also used extensively in zephyr:
https://github.com/zephyrproject-rtos/zephyr/blob/main/cmake/modules/extensions.cmake#L2045-L2049
https://github.com/zephyrproject-rtos/zephyr/blob/main/subsys/bluetooth/mesh/CMakeLists.txt
any elegant changes are welcome :)

Copy link
Contributor

@raiden00pl raiden00pl left a comment

Choose a reason for hiding this comment

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

looks good !

@Jasinsky
Copy link
Contributor

This is great :).

@acassis acassis merged commit 4f895b3 into apache:master Nov 12, 2024
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Build system Size: M The size of the change in this PR is medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants