nuttx
nuttx copied to clipboard
add CMake build system support (Enhance #3704)
Summary
enhance cmake build system (Enhance #3704)
- Update all CMakeLists.txt to adapt to new layout
- Fix cmake build break
- Update all new file license
- Fully compatible with current compilation environment(use configure.sh or cmake as you choose)
How to test
From within nuttx/. Configure:
$ cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
$ cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja
$ cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
This uses ninja generator (install with sudo apt install ninja-build). To build:
$ cmake --build build
menuconfig:
$ cmake --build build -t menuconfig
Compilation speed:
| lm3s6965-ek/qemu-flat:
| Orignal : $ time `./tools/configure.sh lm3s6965-ek/qemu-flat > /dev/null && make -j16 > /dev/null`
| CMake : $ time `cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat > /dev/null;cmake --build build -j16 > /dev/null`
| CMake(Ninja): $ time `cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja > /dev/null;cmake --build build -j16 > /dev/null`
|
| Orignal CMake CMake(Ninja)
| real 0m9.982s 0m4.739s 0m4.475s
| user 1m5.336s 0m41.846s 0m37.434s
| sys 0m16.428s 0m9.239s 0m7.998s
|
|
| Orignal : $ time `./tools/configure.sh sabre-6quad/smp > /dev/null && make -j16 > /dev/null`
| CMake : $ time `cmake -B build -DBOARD_CONFIG=sabre-6quad/smp > /dev/null;cmake --build build -j16 > /dev/null`
| CMake(Ninja): $ time `cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja > /dev/null;cmake --build build -j16 > /dev/null`
|
| Orignal CMake CMake(Ninja)
| real 0m10.921s 0m3.936s 0m3.616s
| user 0m51.603s 0m32.621s 0m29.102s
| sys 0m13.720s 0m8.075s 0m6.460s
Signed-off-by: chao.an [email protected]
Impact
Depends on: https://github.com/apache/incubator-nuttx-apps/pull/1236
Testing
cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja
@anchao - glad that worked out for you - The format looks really good.
there are more important features need to support at this stage,
Are there still open tasks or is that ready to come in?
@anchao - glad that worked out for you - The format looks really good.
there are more important features need to support at this stage,
Are there still open tasks or is that ready to come in?
The current PR still needs some minor improvement, but the review can be started now! I hope this PR can be merged in first since the cmake build system fully compatible with current compilation environment, so that more developers can improve it together. (kernel/protect/export build will be implement in a separate PR)
@davids5 Could you please review this PR further? the functions required for FLAT build are basically supported
Is this already complete or there's still work to be done ? I think CMake would be a great addition to NuttX!
Hi all, @acassis @davids5 @xiaoxiang781216 @pkarashchenko
I rebase this PR based on the latest dev, please review again, thanks!
I would suggest merging CMake patch to the mainline and collect the feedback from the community if no other critical objection.
Given this CMake project is meant to be built from the user project repository (as opposed to the traditional CMake workflow), IMHO instructions like the ones suggested below would be appreciated by some users: I think these instructions would fit either on the top-level
CMakeLists.txt
or the projectREADME.md
- feel free to choose any (or both) of them.
Thanks, I added this comment snippet at start of nuttx/CMakeLists.txt.
@anchao What do you think about creating some CI targets to to ensure this continues to be functional?
Hi, @davids5 , of course, I will send a separate PR later to add cmake-related functional verification on ci-flow
Let's ignore macOS CI temp broken.
@anchao
I noticed that the following error happens with the latest upstream. Does this PR work with the latest PR?
$ cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
-- Initializing NuttX
CMake Error at CMakeLists.txt:315 (message):
Failed to initialize Kconfig configuration:
-- Configuring incomplete, errors occurred!
@anchao
I noticed that the following error happens with the latest upstream. Does this PR work with the latest PR?
Hi @masayuki2009 ,
The initial version only supports kconfiglib, you can try the following command to install:
pip install kconfiglib
I will enhance further documentation/kernel/protect mode support for cmake
@anchao
The initial version only supports kconfiglib, you can try the following command to install: pip install kconfiglib
Hmm, CMake error still happens after I installed kconfiglib.
$ cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
-- Initializing NuttX
Kconfig:258: warning: the 'modules' option is not supported. Let me know if this is a problem for you, as it wouldn't be that hard to implement. Note that modules are supported -- Kconfiglib just assumes the symbol name MODULES, like older versions of the C implementation did when 'option modules' wasn't used.
-- Board: sabre-6quad
-- Config: smp
-- Appdir: /home/ishikawa/opensource/RTOS/nuttx/nuttx/../apps
-- The C compiler identification is GNU 12.2.1
-- The CXX compiler identification is GNU 12.2.1
-- The ASM compiler identification is GNU
-- Found assembler: /opt/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc
-- Check for working C compiler: /opt/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc
-- Check for working C compiler: /opt/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-g++
-- Check for working CXX compiler: /opt/arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error at cmake/nuttx_add_library.cmake:128 (add_library):
Cannot find source file:
/home/ishikawa/opensource/RTOS/nuttx/nuttx/sched/clock/clock_getres.c
Tried extensions .c .C .c++ .cc .cpp .cxx .cu .m .M .mm .h .hh .h++ .hm
.hpp .hxx .in .txx
Call Stack (most recent call first):
sched/CMakeLists.txt:22 (nuttx_add_kernel_library)
CMake Error at cmake/nuttx_add_library.cmake:128 (add_library):
No SOURCES given to target: sched
Call Stack (most recent call first):
sched/CMakeLists.txt:22 (nuttx_add_kernel_library)
CMake Generate step failed. Build files cannot be regenerated correctly.
Hmm, CMake error still happens after I installed kconfiglib.
@masayuki2009
emm... Sorry for bad experience, it seems that some files in the base of our internal code has not been updated, please try PR https://github.com/apache/nuttx/pull/9753 , also I will check further if there are similar issues, a few of configurations will add to CI today
@anchao Have you updated https://nuttx.apache.org/docs/latest/quickstart/compiling.html with a cmake how to?
@anchao Have you updated https://nuttx.apache.org/docs/latest/quickstart/compiling.html with a cmake how to?
@davids5 Yes, I will add cmake chapter later