comejv commented on issue #16689:
URL: https://github.com/apache/nuttx/issues/16689#issuecomment-3049736926

   Regarding out of tree building I see no mentions of CMake, is CMake a recent 
addition to NuttX?
   What I chose to do was a symlink to nuttx-apps/external using a cmake file 
on which the main target depends:
   ```cmake
   # cmake/symlink_apps.cmake
   # This script creates a symbolic link for the main 'apps' directory into the 
nuttx-apps 'external' directory.
   
   # Define source and destination directories relative to the project root
   set(APPS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/nuttx-apps")
   set(NUTTX_APPS_DEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/nuttx-apps")
   
   # Define the destination for the symlink
   set(SYMLINK_DESTINATION "${NUTTX_APPS_DEST_DIR}/external")
   
   # Remove existing symlink or directory in the destination
   if(EXISTS "${SYMLINK_DESTINATION}")
       message(STATUS "Removing existing ${SYMLINK_DESTINATION}")
       file(REMOVE_RECURSE "${SYMLINK_DESTINATION}")
   endif()
   
   # Calculate the relative path for the symlink to use relative paths
   file(RELATIVE_PATH RELATIVE_APPS_PATH "${NUTTX_APPS_DEST_DIR}" 
"${APPS_SOURCE_DIR}")
   
   # Create symbolic link from nuttx-apps/external to the main apps directory
   execute_process(
       COMMAND ${CMAKE_COMMAND} -E create_symlink
               "${RELATIVE_APPS_PATH}"
               "${SYMLINK_DESTINATION}"
       RESULT_VARIABLE SYMLINK_RESULT
       OUTPUT_VARIABLE SYMLINK_OUTPUT
       ERROR_VARIABLE SYMLINK_ERROR
   )
   
   if(NOT SYMLINK_RESULT EQUAL 0)
       message(FATAL_ERROR "Failed to create symlink for apps directory: 
${SYMLINK_ERROR}")
   else()
       message(STATUS "Created symlink: ${SYMLINK_DESTINATION} -> 
${RELATIVE_APPS_PATH}")
   endif()
   ```
   
   I don't remember where I learned about nuttx-apps/external but not in the 
docs you mentioned.
   
   For anyone wondering if using cmake you do no need a Makefile or Make.defs, 
only a CMakeLists at the root of external and one in each project:
   ```cmake
   # external/CMakeLists.txt
   
   nuttx_add_subdirectory()
   nuttx_generate_kconfig(MENUDESC "*** Custom Firmware Applications ***")
   ```
   ```cmake
   # external/hello/CMakeLists.txt
   if(CONFIG_EXTERNAL_HELLO)
     nuttx_add_application(
       NAME
       hello
       SRCS
       hello_main.c
       STACKSIZE
       1024
       PRIORITY
       100
   endif()
   ```


-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to