Commit Graph

109 Commits

Author SHA1 Message Date
Arjav Patel
dfb2c24d62 cmake: Enhance .config handling and comparison logic
Refactor the logic for managing the .config file to ensure it aligns with Make behavior. Introduce a mechanism to set CONFIG_BASE_DEFCONFIG correctly and streamline the comparison process between .config and .config.orig, improving accuracy in detecting changes.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
2026-02-26 09:46:02 -03:00
Arjav Patel
c172074f21 cmake/nuttx_mkconfig: Improve .config comparison logic
Refactor the process of comparing .config and .config.orig files by stripping CONFIG_BASE_DEFCONFIG lines to prevent false -dirty flags. Update .config to ensure it matches the expected Make behavior by writing the correct BASE_DEFCONFIG value.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
2026-02-26 09:46:02 -03:00
xuxin19
a5f3937ff9 cmake(bugfix):change default compile obj extension to .o
CMake uses the `system_name` parameter by default to determine the .obj file extension.
On the Nuttx platform, our `system_name` is `bare matel`,
   while CMake only uses `.o` on Linux/Unix systems  otherwise, it uses `.obj`.

Therefore, we will change it to `.o` by default.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-27 20:54:26 +08:00
xuxin19
82fc9f4151 cmake(bugfix):Separate extra flags to avoid parsing errors
cc1: note: unrecognized command-line option '-Wno-cpp -Werror' may have been intended to silence earlier diagnostics
cc1: note: unrecognized command-line option '-Wno-cpp -Werror' may have been intended to silence earlier diagnostics

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-27 20:54:26 +08:00
xuxin19
e3fcb025cb cmake(bugfix):fix common/etc confilt with src/etc in CMake genromfs
We use the rules added later to overwrite the previous rules

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-27 20:54:26 +08:00
xuxin19
4f80953ecd cmake(bugfix):do not set nuttx_add_app NAME as required
Instead, use direct return, because in non-build targets,
such as savedefconfig, menuconfig, this check is unnecessary

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-27 20:54:26 +08:00
xuxin19
d39ed19213 cmake(bugfix):elf link should depends on starupobjs crt0.o
fix the correct dependency sequence to prevent
startupobjs from not being generated before ELF linking.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
b34a221121 cmake(bugfix):unify cmake application elf link rule
separate three elf link modes:
kernel elf: kernel build link all user libs and startup obj
loadable elf: `m` build dont link user libs minimize size but link
startup obj
dynlib elf:do not link user libs and startup obj

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
00e79122af cmake(enhance):cmake support DYNLIB build
add `DYNLIB` option for nuttx_add_application for dynamic loadable lib

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
a7c6f589f9 cmake(bugfix):fix sim loadable elf build support
1.add sanity check for START_OBJS
2.make laodable -e entry setting in each arch elf.cmake
3.add sim elf.cmake

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
d676716e7a cmake(feat):separate ELF output bin and bin_debug
bin for striped elf

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
6fa3031d9b cmake(feat):define elf option and enable apps module build
1.define elf option setting function ext;
2.unify loadable elf and kernel elf build config

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
885ff780c5 cmake(bugfix):fix KERNEL mod elf target dup with lib target
Using the same name as elf may lead to duplicate errors.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
197149a297 cmake(bugfix):use apps_post to identify the stage of app completion
nuttx_post for all target done
apps_post for all apps lib done

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
70bddf61c3 cmake(bugfix):rename host tools binary dir to host_bin
we will use CMAKE_BINARY_DIR/bin for apps elf
so we need to change host tools to bin_host

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
b7582b8da1 cmake(feat):implements KERNEL mode in CMake build
1.add application link dependencies for all elf
2.add a global custom target to hold proptry in the toolchain file
3.add startup obj target
4.fix cpp lds error with kernel mod link elf lds

usage:
./build.sh qemu-armv7a:knsh --cmake
elf install in ${CMAKE_BINARY_DIR}/bin

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
xuxin19
e9e9c76a76 cmake(enhance):include-style defconfig can modified via menuconfig
1. enhanced process_config.py script: supports both preprocess and postprocess modes

2. in preprocess mode: handles include formats and recursively records the include config tree structure to prepare for postprocess

3. In postprocess mode: compares the original file with menuconfig to identify non-#include items that should be written back

4. olddefconfig stores the original compressed include defconfig file at the very beginning

5. savedefconfig saves both the original file and the written back include defconfig

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-15 15:42:17 -03:00
xuxin19
f6db05a94f cmake(enhance):add target we can dump all CMake lib targets
`cmake --build -t dump_targets`
list all lib target current generator need to build

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-14 23:07:32 +08:00
xuxin19
bca7d17a1d cmake(enhance):make CMake extensions include path inherit PUBLIC
since we imply nuttx_link_libraries, nuttx_lib target can
inherit include path

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-14 23:07:32 +08:00
xuxin19
79d7ada455 cmake(bugfix):keep include directory order in cmake application
Adding a for loop will reverse the order of addition.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-13 13:54:12 -08:00
xuxin19
4162e01a22 cmake(bugfix):Add BEFORE the inc path of the apps and library
Because we expect private configuration to always OVERRIDE public configuration

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-13 13:54:12 -08:00
guoshichao
38e5cbead0 ghs: move the -fmacro-prefix-map compile option to compiler specific
the -fmacro-prefix-map compile option is gcc/clang/armclang specific
compile option, and greenhills do not recognize this compile option, if
we add this option is CMakeLists.txt, the following warning will be
reported when each file is being compiled:

ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/nuttx=" passed to linker
ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/apps=" passed to linker
ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/vendor/flagchip/boards/mann/dcu/fc4150f1m-labm_a1=" passed to linker
ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/vendor/flagchip/chips/fc4150=" passed to linker
ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/nuttx=" passed to linker
ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/apps=" passed to linker
ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/vendor/flagchip/boards/mann/dcu/fc4150f1m-labm_a1=" passed to linker
ccarm: Warning: Unknown option "-fmacro-prefix-map=/home/guoshichao/work_profile/vela_os/vela_car_5/vendor/flagchip/chips/fc4150=" passed to linker

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-13 21:20:21 +08:00
wangchengdong
a2773f267e cmake: Improve nuttx_generate_kconfig()
Some checks failed
Build Documentation / build-html (push) Has been cancelled
Enhance the nuttx_generate_kconfig() implementation to ensure that
both subdirectories and external directories containing a CMakeLists.txt
or a Kconfig file are properly included during Kconfig generation.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-12-02 02:45:36 +08:00
wangchengdong
c5f85f8275 CMake: Enable Kconfig generation for external directories
Currently, nuttx_generate_kconfig() can only parse subdirectories
under apps/. This patch extends its capability to also parse
external directories referenced from the apps tree.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-11-20 19:16:05 +08:00
wangchengdong
fd70e5f947 CMake: Enable both sub-Kconfig and generated menu Kconfig
Currently, nuttx_generate_kconfig() allows a subdirectory to have
either a handwritten sub-Kconfig or a generated menu Kconfig, but
not both.

This patch enables support for having both a sub-Kconfig and a
generated menu Kconfig within the same subdirectory.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-11-20 13:29:02 +08:00
Junbo Zheng
2578638d52 cmake: correct nuttx_wildcard_sources cmake usage
reference:
https://cmake.org/cmake/help/latest/command/cmake_parse_arguments.html

add debug message for test
```diff
diff --git a/cmake/nuttx_extensions.cmake b/cmake/nuttx_extensions.cmake
index 9ed430b74a..baa22cf90d 100644

--- a/cmake/nuttx_extensions.cmake
+++ b/cmake/nuttx_extensions.cmake
@@ -116,6 +116,9 @@ endfunction()
 function(nuttx_wildcard_sources)
   cmake_parse_arguments(ARGS "" "" EXCLUDE ${ARGN})

+  message(STATUS "## UNPARSED ARGUMENTS ${ARGS_UNPARSED_ARGUMENTS}")
+  message(STATUS "## ARGN ${ARGN}")
+
   file(GLOB SRCS ${ARGS_UNPARSED_ARGUMENTS})
   if(ARGS_EXCLUDE)
     file(GLOB RM_SRCS ${ARGS_EXCLUDE})
```

cmake build test
```
➜  /home/mi/local/mycpp [25-10-15_14:11:41] git:(master) ✗ ls demo
1.c  2.c  3.c
➜  /home/mi/local/mycpp [25-10-15_14:11:57] git:(master) ✗ cmake -S . -B build -G Ninja
>> 14:12:42.161053 INFO    [demo] Time taken: 0ms
-- ## UNPARSED ARGUMENTS aaa/*.c
-- ## ARGN aaa/*.c;EXCLUDE;aaa/3.c
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/mi/local/mycpp/build
➜  /home/mi/local/mycpp [25-10-15_14:12:47] git:(master) ✗
```

`SRCS` just collect all source files instead of EXCLUDE arguments

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2025-10-16 12:48:40 +08:00
trns1997
81e79d9a65 cmake: pass exclusion list to nuttx_add_subdirectory
Introduce support in CMake to ignore specific directories
added by `nuttx_add_subdirectory()`. This provides more
flexibility for build configuration and allows excluding
unwanted or optional components.

* Improves modularity of project configuration.

Signed-off-by: trns1997 <trns1997@gmail.com>
2025-10-03 11:34:56 +08:00
wangchengdong
46292a9529 arch/tricore: Remove tasking compiler tool specific code from
Some checks failed
Build Documentation / build-html (push) Has been cancelled
common Cmake scripts

      Remove tasking compiler tool specific code from
      common Cmake scripts

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-26 13:26:31 +02:00
simbit18
4c3dbed5b5 arm/rp2040: CMake build for Raspberry Pi RP2040 implemented
- CMake added board Raspberry Pi Pico

- Added the entry:

     CMake,raspberrypi-pico:bmp280

   to the file arm-06.dat.

- Moved the search for the Python 3 interpreter to the
  root CMakefile to avoid unnecessary repetition.

Signed-off-by: simbit18 <simbit18@gmail.com>
2025-09-24 14:42:27 +08:00
wangchengdong
34ca49b6f5 tasking/cmake: Provide better .hex and .srec gen for tasking compiler
Provide better hex and srec generation for tasking compiler, without relying
on freeware tricore-elf-objcopy.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-17 14:01:16 +08:00
wangchengdong
3eb1c21807 nuttx/cmake: add cmake disassembly support for GHS compiler
add cmake disassembly support for GHS compiler

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-09-16 02:01:36 +08:00
wangchengdong
be36d42da5 Cmake: add defconfig preprocess capability in Cmake build environment(recursively expand #include)
Add:
    cmake/nuttx_process_config.cmake
    tools/process_config.py

    Update nuttx/CMakeLists.txt to call process_config defined ini
    nuttx_process_config.cmake to process defconfig before actually using it
2025-08-25 20:30:16 +08:00
Junbo Zheng
a88eb1fc6b cmake: enhance the function of cmake nuttx_wildcard_sources
align already used cmake ifdef/ifndef nuttx_xxx functions, reference:
- https://github.com/apache/nuttx/pull/14747

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2025-07-14 20:41:12 +08:00
xuxin19
8dd49d2fac cmake(bugfix):fix VERSION genarator strip error in CMake build
fix genarate include/nuttx/version.h
define CONFIG_VERSION_STRING "12.5.1
" missing closing quote
^~~~~~~~~~~~~~~~~~~~~~
define CONFIG_VERSION_MAJOR 12

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2025-06-18 15:45:30 -04:00
Lars Kruse
3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Serg Podtynnyi
4c52f2dbeb tools: Update Unix.mk and savedefconfig.cmake for CONFIG_ARCH_BOARD_COMMON
Preserve CONFIG_ARCH_BOARD_COMMON in savedconfig

Signed-off-by: Serg Podtynnyi <serg@podtynnyi.com>
2025-05-02 09:30:34 -03:00
chao an
52482219c8 libc/elf: rename modlib to libelf
Renaming "modlib" to "libelf" is more in line with the implementation content,
which makes it easier for individual developers to understand the capabilities of this module.

CONFIG_LIBC_MODLIB -> CONFIG_LIBC_ELF

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-11 09:43:22 +08:00
simbit18
4050c79505 [cmake] savedefconfig.cmake: fix EOL changes to defconfig files on Windows
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   ../../boards/arm/stm32/nucleo-l152re/configs/nsh/defconfig

no changes added to commit (use "git add" and/or "git commit -a")
2025-01-23 02:34:50 +08:00
chao an
9f5a45340f cmake: Use EXTRAFLAGS to define customized compilation options
align them with the usage habits of makefile

cmake:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja -DEXTRAFLAGS="-DCONFIG_AAA=1 -DCONFIG_BBB=1 -Werror"

makefile:

make -j12 EXTRAFLAGS="-DCONFIG_AAA=1 -DCONFIG_BBB=1 -Werror"

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-18 14:12:49 +08:00
chao an
36b2b90bc0 cmake/mkconfig: add support of set custom command options to config.h
add support of set custom command options to config.h
Use the -D parameter to pass the config to header file.
NOTE which must begin with the CONFIG_ prefix.
eg:
  cmake -DCONFIG_AAA=1 -DCONFIG_BBB=1 -B build -DBOARD_CONFIG=sim/nsh -GNinja

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-17 22:00:07 -03:00
yaojingwei
bbd6931d61 nuttx/audio: add fake audio driver.
The fake audio driver aims to easily simulate the functions of audio driver through reading and writing files.
With it, you can conveniently customize and define various capture or playback audio drivers for debugging or automated testing.

Signed-off-by: yaojingwei <yaojingwei@xiaomi.com>
2024-12-20 11:47:08 -03:00
xuxin19
dc8bde8dd5 cmake(enhance):Enhance romfs so that RAWS files can be added in any location
1.make the generation sequence of etc romfs no longer bound to the board
2.RCRAWS RCSRCS can be added from any directory
3.enable dynamic files, files generated during the compilation process,
    and ensure the correct time order

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-12-02 19:59:02 +08:00
xuxin19
cfe78ad74e cmake(enhance):enhance NuttX cmake target dependencies and link_library modules
Enhance CMake's add_dependencies for Nuttx so that
different targets can call dependencies without errors when they are not traversed.

In addition, since we do not call link_library directly,
we increment nuttx_link_library to inherit the PUBLIC property

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-22 15:16:07 -03:00
xuxin19
6d629b3b36 cmake:bugfix kconfig menu in cmake cannot be generated recursively
the ${MENUCONFIG} file in the output directory is enough,
as invoking nuttx_generate_kconfig() will generate this
file in the output directory.
Since we are collecting these files recursively,
the nuttx_generate_kconfig() function of the parent directory
will be called after all the subdirectories' nuttx_generate_kconfig()
functions have been invoked.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-18 17:01:43 +08:00
xuxin19
3ae822c098 cmake:remove no need target_link_library in static target
the link_library of the static target will cause PRIVATE to be inherited to nuttx,
resulting in duplicate linking and definition problems.
because all target static libraries will eventually be linked, there is no need to specify it explicitly.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-14 01:26:38 +08:00
xuxin19
00dd223601 cmake(bugfix):no need to deleted products gen in binary dir
keeping intermediate products in the binary directory helps debugging

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-13 02:36:18 +08:00
xuxin19
4f895b3300 cmake(enhance):add NuttX CMake extensions module
Wrapped CMake native method is nuttx_cmake module
It can be quickly called in the build system

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-12 15:30:21 -03:00
xuxin19
acb5058428 cmake(bugfix):fix directory not being successfully added when adding romfs
board content should overwrite common content

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-10 00:49:23 +08:00
xuxin19
ba56c6c102 cmake(bugfix):make sure the extra_lib only added once
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-04 18:19:15 +08:00
chao an
e3689cbb2f CMake/preprocess: fix typo PREPROCES -> PREPROCESS
correct the marco define from PREPROCES to PREPROCESS

Signed-off-by: chao an <anchao@lixiang.com>
2024-10-29 17:41:01 +08:00