xuxin930 opened a new pull request, #22120:
URL: https://github.com/apache/nuttx/pull/22120
## Summary
A set of independent fixes for the CMake build system:
* cmake(bugfix):fix external_library MACRO missing in PROTECT mod build
`nuttx_add_external_library(... MODE KERNEL)` only added the target to
`NUTTX_KERNEL_LIBRARIES`. In PROTECTED/KERNEL builds the target did not
get the kernel compile options, definitions and include directories
(e.g. `__KERNEL__`) that libraries added with `nuttx_add_kernel_library`
get. External kernel libraries now inherit
`NUTTX_KERNEL_COMPILE_OPTIONS`, `NUTTX_KERNEL_DEFINITIONS` and
`NUTTX_KERNEL_INCLUDE_DIRECTORIES` when `CONFIG_BUILD_FLAT` is not set.
* cmake(bugfix):fix dequote error in Kconfig parse
`nuttx_export_kconfig()` removed every `"` from a string value, so
`CONFIG_STR="my string is \"str\""` was exported to CMake as
`my string is \str\`. Now only the outer quotes are removed.
* cmake(bugfix):adjust the order of the linked libraries in the group link
The link order is now: apps libraries, then user libraries, then system
libraries, then kernel libraries, with extra libraries last, so that a
library is listed before the libraries it depends on. Libraries added
with `nuttx_add_library()` / `nuttx_add_external_library()` in user mode
are now recorded in a new `NUTTX_USER_LIBRARIES` property instead of
`NUTTX_SYSTEM_LIBRARIES`. The library types and the ordering rule are
documented at the top of `cmake/nuttx_add_library.cmake`.
* cmake(bugfix):fix romfs_img missing aligned
The Make build declares the generated romfs image as
`const unsigned char aligned_data(4)` (see boards/Board.mk), but the
CMake build only added `const`. The CMake output now matches the Make
output, and the generated source includes `<nuttx/compiler.h>` for
`aligned_data()`.
* cmake(bugfix):add UTF-8 encoding declaration for .config parsing
Without an `ENCODING` option, `file(STRINGS)` only extracts ASCII strings,
so a `.config` string value with UTF-8 characters was split and the
generated `config.h` was broken. `.config` is now read with
`ENCODING UTF-8`.
## Impact
* CMake build only. The Make build is not affected.
* Link order changes for FLAT and PROTECTED builds. Libraries registered
with `nuttx_add_library()` move from `NUTTX_SYSTEM_LIBRARIES` to the new
`NUTTX_USER_LIBRARIES`. Out-of-tree CMake code that reads
`NUTTX_SYSTEM_LIBRARIES` to collect these libraries needs to read
`NUTTX_USER_LIBRARIES` as well.
* Kconfig string values that contain escaped quotes are now exported to
CMake correctly. A CMake script that depended on the old behavior
(all quotes stripped) would see a different value.
* Generated romfs sources now include `<nuttx/compiler.h>` and the image
array is 4-byte aligned.
* No hardware, security or documentation impact.
## Testing
Host: Ubuntu 24.04.3 LTS (Linux 7.0.0, x86_64), CMake 3.23.0 / 3.28.3,
Ninja, GCC 13.3.0, Arm GNU Toolchain 13.2.rel1.
apps: apache/nuttx-apps master (6dce52b7c).
1. sim:nsh (FLAT) builds and runs. The romfs image is aligned and /etc
is mounted:
$ cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja && ninja -C build
$ head -2 build/.../romfs_etc.c
#include <nuttx/compiler.h>
const unsigned char aligned_data(4) romfs_img[] = {
$ nm build/nuttx | grep ' romfs_img$'
000000004011808c R romfs_img
$ ./build/nuttx
nsh> ls /etc/init.d
/etc/init.d:
init.rc
nsh> uname -a
NuttX 12.7.2 b726caffe36 Nov 20 2026 17:35:25 sim sim
2. UTF-8 in .config (sim:nsh with
`CONFIG_NSH_MOTD_STRING="中文 motd"`), include/nuttx/config.h:
before: #define CONFIG_NSH_MOTD_STRING "
after: #define CONFIG_NSH_MOTD_STRING "中文 motd"
3. Kconfig dequote, `nuttx_export_kconfig()` on
`CONFIG_STR="my string is \"str\""` and `CONFIG_A="abc"`:
before: STR=[my string is \str\] A=[abc]
after: STR=[my string is \"str\"] A=[abc]
4. qemu-armv7r:pnsh (PROTECTED) with the Arm toolchain: build OK. The
user blob is linked in the order apps, user libs, system libs:
--start-group apps/system/dd/libapps_dd.a ... apps/libapps.a
apps/builtin/libapps_builtin.a arch/libarch_interface.a
libs/libc/libc.a ... mm/libmm.a syscall/proxies/libproxies.a ...
Note: with the current upstream CMakeLists.txt, PROTECTED configs fail
at configure time ("No SOURCES given to target: nuttx_user") both with
and without this PR. For this test a dummy source was added to
nuttx_user locally; that change is not part of this PR.
5. mps3-an547:nsh (FLAT, Arm): build OK.
6. ./tools/checkpatch.sh -m -g HEAD~5..HEAD: All checks pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]