You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] error in building add_subdirectory for nuttx #19697
For the convenience of project expansion, I placed nuttx in a third-party library and set it in the following directory ~/dev/proj/third_party/nuttx. When I imported nuttx into the main project's CMakeLists.txt through add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/third_party/nuttx") to build, I found an error. The command is cd ~/dev/proj && cmake -B build -DBOARD_CONFIG=/home/ubuntu/dev/proj/third_party/nuttx/boards/sim/sim/sim/configs/nsh. It may be a problem with your path handling, such as fixed writing, etc. For example, your build directory is ~/dev/proj/build, and the 375th line of your CMakeLists.txt is written as set(ENV{KCONFIG_CONFIG} ${CMAKE_BINARY_DIR}/.config), which should be CMAKE_CURRENT_BINARY_DIR. Most projects can be built through add_subdirectory, I hope you can fix it. Thank you.
This is just an initial fix to prove that "nuttx sim" can work as external project. For real boards more modifications will be necessary by CMake experts (@simbit18)
This is just an initial fix to prove that "nuttx sim" can work as external project. For real boards more modifications will be necessary by CMake experts (@simbit18)
Very good, thank you very much. Because third-party libraries are usually added using add_subdirectory, which is also a community style, such as GitHub projects like Google Test and UORB. Here is the instruction manual for another project. Using add_subdirectory is also a category of out-of-tree building advocated in your document. If not, it's just a bit troublesome for oneself, but it can still be used.
In addition, the reason why nuttx is placed in the third-party folder is also due to considerations for cross platform development of projects such as Linux, otherwise the directory tree would be very ugly. In addition, defining the path of the board with an explicit path may also be a good choice, while reducing ambiguity and your construction judgment.
CMAKE_SOURCE_DIR: Refers to the top-level source code directory (i.e. the directory specified when executing cmake initially, usually containing the root CMakeLists.txt). CMAKE_CURRENT_SOURCE_DIR: Refers to the directory where the current processing location is located, named after the CMakeLists.txt file. When using add_subdirectory() to enter a subdirectories, its value will change to the path of that subdirectories.
Similarly, there are corresponding variables for building directories: CMAKE_BINARY_DIR: Refers to the top-level build directory (i.e. the build directory specified when executing cmake, which corresponds to the root CMakeLists.txt). CMAKE_CURRENT_BINARY_DIR: Refers to the build directory corresponding to the current source code directory. In subdirectories, it is usually CMAKE_BINARY_DIR relative path of subdirectories.
Simply put:
Variables without CURRENT always point to the root position of the project.
The variable with CURRENT points to the current location of CMakeLists.txt.
I have submitted a PR to fix cross-compilation support in add_subdirectory() mode for non-sim architectures: #20874
It fixes inverted add_subdirectory() syntax, relative includes in Toolchain.cmake, subproject toolchain evaluation, and exports configuration variables to PARENT_SCOPE. Please take a look when you have a chance
Activity
zyy37 commentedon Aug 8, 2026
@acassis Are you a PM? Could you check it, please? Thank you.
acassis commentedon Aug 8, 2026
@zyy37 please take a look at #19755
This is just an initial fix to prove that "nuttx sim" can work as external project. For real boards more modifications will be necessary by CMake experts (@simbit18)
raiden00pl commentedon Aug 9, 2026
cmake in nuttx was never designed with add_subdirectory support in mind. How would this even work with the current nuttx build flow?
zyy37 commentedon Aug 9, 2026
Very good, thank you very much. Because third-party libraries are usually added using
add_subdirectory, which is also a community style, such as GitHub projects like Google Test and UORB. Here is the instruction manual for another project. Usingadd_subdirectoryis also a category ofout-of-tree buildingadvocated in your document. If not, it's just a bit troublesome for oneself, but it can still be used.In addition, the reason why nuttx is placed in the third-party folder is also due to considerations for cross platform development of projects such as Linux, otherwise the directory tree would be very ugly. In addition, defining the path of the board with an explicit path may also be a good choice, while reducing ambiguity and your construction judgment.
zyy37 commentedon Aug 9, 2026
CMAKE_SOURCE_DIR: Refers to the top-level source code directory (i.e. the directory specified when executing cmake initially, usually containing the root CMakeLists.txt).CMAKE_CURRENT_SOURCE_DIR: Refers to the directory where the current processing location is located, named after the CMakeLists.txt file. When usingadd_subdirectory()to enter a subdirectories, its value will change to the path of that subdirectories.Similarly, there are corresponding variables for building directories:
CMAKE_BINARY_DIR: Refers to the top-level build directory (i.e. the build directory specified when executing cmake, which corresponds to the root CMakeLists.txt).CMAKE_CURRENT_BINARY_DIR: Refers to the build directory corresponding to the current source code directory. In subdirectories, it is usuallyCMAKE_BINARY_DIRrelative path of subdirectories.Simply put:
Variables without CURRENT always point to the root position of the project.
The variable with CURRENT points to the current location of CMakeLists.txt.
cmake: Use NUTTX(_DIR/_BIN_DIR) instead CMAKE(_SRC_DIR/_BIN_DIR)
acassis commentedon Aug 9, 2026
Let's reopen it, since the PR only fixes external building of sim, it doesn't support cross-compiling
Swatantra-66 commentedon Oct 21, 2026
Hi @acassis,
I have submitted a PR to fix cross-compilation support in
add_subdirectory()mode for non-sim architectures: #20874It fixes inverted
add_subdirectory()syntax, relative includes inToolchain.cmake, subproject toolchain evaluation, and exports configuration variables toPARENT_SCOPE. Please take a look when you have a chancecmake: Fix cross-compilation support in add_subdirectory mode
cmake: Fix cross-compilation support in add_subdirectory mode
cmake: Fix cross-compilation support in add_subdirectory mode