Skip to content

cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR) - #19755

Merged
acassis merged 1 commit into
apache:masterfrom
acassis:cmake_issue
Aug 9, 2026
Merged

cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR)#19755
acassis merged 1 commit into
apache:masterfrom
acassis:cmake_issue

Conversation

@acassis

@acassis acassis commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This change fixes NuttX’s CMake support when NuttX is embedded in another project via add_subdirectory(). CMake’s CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR refer to the outermost project, causing NuttX to access its .config, generated files, host tools, and build artifacts in the parent project’s directories. The fix introduces NUTTX_DIR and NUTTX_BINARY_DIR, based on CMAKE_CURRENT_SOURCE_DIR and CMAKE_CURRENT_BINARY_DIR, and consistently uses them for NuttX self-references while preserving existing standalone builds. It fixes the Kconfig initialization failure reported in #19697 and allows an embedded sim:nsh build to configure, build, and boot successfully. The change affects only the CMake build system (not Make or Kconfig defaults), requires the corresponding nuttx-apps change, and does not extend add_subdirectory() support to cross-compiled non-sim boards due to CMake’s toolchain-file limitation.

Depends-on: apache/nuttx-apps#3711

Impact

Fixes #19697

Testing

  Test performed

  Reproduced the reported scenario end-to-end: a parent project pulling NuttX in
  as a git submodule/third-party dependency via add_subdirectory(), configured
  from the top level.

  Setup (parent_proj/CMakeLists.txt):
  cmake_minimum_required(VERSION 3.20)
  project(ParentProj)
  add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/nuttx nuttx_build)
  with third_party/nuttx and third_party/nuttx-apps as the vendored trees
  (analogous to the reporter's ~/dev/proj/third_party/nuttx).

  Steps
  $ cd parent_proj
  $ cmake -B build
  $ cmake --build build -j$(nproc)
  nuttx_build/CMakeFiles/nuttx.dir/arch/sim/src/sim/posix/sim_hostsmp.c.o
  [100%] Linking C executable nuttx
  [100%] Built target nuttx
  [100%] Generating System.map
  [100%] Built target systemmap
  [100%] Built target nuttx_post
  [100%] Pac SIM with dynamic libs in nuttx.tgz
  [100%] Built target nuttx_post_build
  [100%] Built target post_build

Complete log: apache/nuttx-apps#3711

@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: simulator Issues related to the SIMulator Arch: tricore Issues related to the TriCore architecture from Infineon Arch: x86_64 Issues related to the x86_64 architecture Arch: xtensa Issues related to the Xtensa architecture Size: L The size of the change in this PR is large Area: BINFMT Board: arm Board: risc-v Board: simulator Board: x86_64 labels Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis

acassis commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Please ignore Check issue, "siz" is the file extension:

# instruct the gsize to generate a "*.siz" file that contains the detailed

This change fixes NuttX’s CMake support when NuttX is embedded
in another project via add_subdirectory(). CMake’s CMAKE_SOURCE_DIR
and CMAKE_BINARY_DIR refer to the outermost project, causing NuttX
to access its .config, generated files, host tools, and build artifacts
in the parent project’s directories. The fix introduces NUTTX_DIR and
NUTTX_BINARY_DIR, based on CMAKE_CURRENT_SOURCE_DIR and
CMAKE_CURRENT_BINARY_DIR, and consistently uses them for NuttX
self-references while preserving existing standalone builds. It fixes
the Kconfig initialization failure reported in apache#19697 and allows an
embedded sim:nsh build to configure, build, and boot successfully.
The change affects only the CMake build system (not Make or Kconfig
defaults), requires the corresponding nuttx-apps change, and does not
extend add_subdirectory() support to cross-compiled non-sim boards due
to CMake’s toolchain-file limitation.

Fixes apache#19697.

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Alan Carvalho de Assis <[email protected]>
@acassis acassis changed the title cmake: Use NUTTX_DIR/NUTTX_BINARY_DIR instead of CMAKE_SOURCE_DIR/CMA… cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR) Aug 8, 2026
@acassis

acassis commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@simbit18 I think if the Check fails because typos we need to continue the next steps, because it is producing false positives. The only way to make it passing it modifying a legit text to make it wrong just to satisfy the CI

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx/actions/runs/31277642253

@raiden00pl

Copy link
Copy Markdown
Member

What problem exactly does this PR solve? support for add_subdirectory is not possible with current cmake support in nuttx and supporting this may require a complete rebuild of cmake build

@acassis

acassis commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

What problem exactly does this PR solve? support for add_subdirectory is not possible with current cmake support in nuttx and supporting this may require a complete rebuild of cmake build

@raiden00pl with this simple modification we can run the NuttX sim as external project:

$ cat CMakeLists.txt 
cmake_minimum_required(VERSION 3.20)
project(NuttXExternal)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../nuttx nuttx_build)

This is just the initial step, more modifications will be necessary to support cross-compiling too. As you said it will be a redesign of CMake build system. So I want to do it in baby steps

@acassis

acassis commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi @simbit18 what is necessary to make the Depends-on Check to reflect here in the official CI Check list?

image

@raiden00pl

Copy link
Copy Markdown
Member

@acassis add_subdirectory works for host compiler just by coincidence. Cmake design in nuttx is not ready for this. But either way, this change makes sense for other reasons.

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @acassis :-)

@acassis
acassis merged commit 8726049 into apache:master Aug 9, 2026
64 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: simulator Issues related to the SIMulator Arch: tricore Issues related to the TriCore architecture from Infineon Arch: x86_64 Issues related to the x86_64 architecture Arch: xtensa Issues related to the Xtensa architecture Area: BINFMT Board: arm Board: risc-v Board: simulator Board: x86_64 Size: L The size of the change in this PR is large

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] error in building add_subdirectory for nuttx

3 participants