skywalkerwhack opened a new issue, #3834:
URL: https://github.com/apache/nuttx-apps/issues/3834

   ### Description / Steps to reproduce the issue
   
   The CMake build of the **dropbear** application 
(`apps/netutils/dropbear/CMakeLists.txt`) is
   broken. The Make build of the very same configuration works, which suggests 
the CMake
   glue for this app was never exercised (NuttX CI builds it with Make).
   
   Reproduced with:
   
   ```
   $ cd nuttx
   $ cmake -B build -DBOARD_CONFIG=esp32c3-devkit:dropbear -GNinja
   $ cmake --build build
   ```
   
   There are four distinct problems, each hidden behind the previous one:
   
   **1. Configure fails - raw `target_*` calls use the wrong target name**
   
   ```
   CMake Error at .../apps/netutils/dropbear/CMakeLists.txt:182 
(target_include_directories):
     Cannot specify include directories for target "dropbear" which is not 
built by this project.
   ```
   
   (same for `scp`, and for `target_compile_definitions` / 
`target_compile_options`)
   
   `nuttx_add_application()` creates the target as `apps_<NAME>`
   (see `nuttx/cmake/nuttx_add_application.cmake`), so `target_*(${PROGNAME} 
...)` and
   `target_*(scp ...)` can never match.
   
   **2. `scp` app misses include paths**
   
   After fixing the target names, compilation of the scp app fails:
   
   ```
   fatal error: tomcrypt_custom.h: No such file or directory
   ```
   
   The scp target lacks `dropbear/libtomcrypt/src/headers` (and 
`dropbear/libtommath`) on its
   include path. The Makefile adds these globally via CFLAGS.
   
   **3. Link fails - `main=` alias is clobbered for scp, and applied to the 
wrong file**
   
   ```
   apps/builtin/libapps_builtin.a(builtin_list.c.o):(.rodata.g_builtins+0x1c): 
undefined reference to scp_main
   ```
   
   `nuttx_add_application()` renames the entry point by adding 
`main=<name>_main` to the
   **first** source in `SRCS` (`set_property(SOURCE ... APPEND PROPERTY 
COMPILE_DEFINITIONS ...)`).
   For the scp app this alias is then **replaced** by
   `set_source_files_properties(dropbear/src/scp.c PROPERTIES 
COMPILE_DEFINITIONS ...)`
   (`PROPERTIES` overwrites, it does not append), so `main=scp_main` is lost.
   For the dropbear app, `dropbear_main.c` is listed **last** in `SRCS`, so the 
alias is
   applied to `dropbear_nshsession.c` instead of the file that defines `main()`.
   
   **4. Duplicate sources**
   
   `target_sources(apps PRIVATE ${DROPBEAR_SRCS})` adds the sources to the 
aggregate `apps`
   library although `nuttx_add_application()` already compiles them into 
`apps_dropbear`.
   
   ### Expected behavior
   
   `cmake --build build` succeeds and the resulting image runs Dropbear, 
exactly as the Make
   flow does.
   
   ### Minimal fix (verified on hardware)
   
   ```diff
   --- a/netutils/dropbear/CMakeLists.txt
   +++ b/netutils/dropbear/CMakeLists.txt
   $ -156,8 +156,8 $ if(CONFIG_NETUTILS_DROPBEAR)
        NAME
        ${PROGNAME}
        SRCS
   -    ${DROPBEAR_SRCS}
        dropbear_main.c
   +    ${DROPBEAR_SRCS}
        STACKSIZE
        ${CONFIG_NETUTILS_DROPBEAR_STACKSIZE}
        PRIORITY
   $ -180,7 +180,7 $ if(CONFIG_NETUTILS_DROPBEAR)
      endif()
    
      target_include_directories(
   -    ${PROGNAME}
   +    apps_${PROGNAME}
        PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
                ${CMAKE_CURRENT_SOURCE_DIR}/port
                ${CMAKE_CURRENT_SOURCE_DIR}/dropbear
   $ -191,19 +191,21 $ if(CONFIG_NETUTILS_DROPBEAR)
    
      if(CONFIG_NETUTILS_DROPBEAR_SCP)
        target_include_directories(
   -      scp
   +      apps_scp
          PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/port
                  ${CMAKE_CURRENT_SOURCE_DIR}/dropbear
   -              ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/src)
   +              ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/src
   +              ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtomcrypt/src/headers
   +              ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtommath)
      endif()
    
      if(CONFIG_NETUTILS_DROPBEAR_COMPRESSION)
        target_include_directories(
   -      ${PROGNAME} PRIVATE 
${CMAKE_CURRENT_SOURCE_DIR}/../../system/zlib/zlib)
   +      apps_${PROGNAME} PRIVATE 
${CMAKE_CURRENT_SOURCE_DIR}/../../system/zlib/zlib)
      endif()
    
      target_compile_definitions(
   -    ${PROGNAME}
   +    apps_${PROGNAME}
        PRIVATE LOCALOPTIONS_H_EXISTS=1
                DROPBEAR_NUTTX=1
                DROPBEAR_NUTTX_PASSWD=1
   $ -213,8 +215,11 $ if(CONFIG_NETUTILS_DROPBEAR)
    
      if(CONFIG_NETUTILS_DROPBEAR_SCP)
        target_compile_definitions(
   -      scp PRIVATE LOCALOPTIONS_H_EXISTS=1 DROPBEAR_NUTTX=1
   -                  DROPBEAR_NUTTX_PASSWD=1)
   +      apps_scp PRIVATE LOCALOPTIONS_H_EXISTS=1 DROPBEAR_NUTTX=1
   +                    DROPBEAR_NUTTX_PASSWD=1
   +                    base64_encode=dropbear_ltc_base64_encode
   +                    base64_decode=dropbear_ltc_base64_decode
   +                    ecc_make_key=dropbear_ltc_ecc_make_key)
      endif()
    
      set_source_files_properties(
   $ -223,10 +228,10 $ if(CONFIG_NETUTILS_DROPBEAR)
                   "Channel=dropbear_channel;ChanType=dropbear_chantype")
    
      if(CONFIG_NETUTILS_DROPBEAR_SCP)
   -    set_source_files_properties(
   -      dropbear/src/scp.c
   -      PROPERTIES
   -        COMPILE_DEFINITIONS
   +    set_property(
   +      SOURCE dropbear/src/scp.c
   +      APPEND
   +      PROPERTY COMPILE_DEFINITIONS
            
"xmalloc=dropbear_scp_xmalloc;xrealloc=dropbear_scp_xrealloc;xfree=dropbear_scp_xfree;execvp=dropbear_scp_execvp"
        )
        set_source_files_properties(
   $ -241,16 +246,14 $ if(CONFIG_NETUTILS_DROPBEAR)
      set_source_files_properties(${LIBTOMCRYPT_SRCS} PROPERTIES 
COMPILE_DEFINITIONS
                                                                 LTC_SOURCE=1)
    
   -  target_compile_options(${PROGNAME} PRIVATE -Wno-pointer-sign -Wno-format)
   +  target_compile_options(apps_${PROGNAME} PRIVATE -Wno-pointer-sign 
-Wno-format)
    
      if(CONFIG_NETUTILS_DROPBEAR_SCP)
        target_compile_options(
   -      scp
   +      apps_scp
          PRIVATE -Wno-pointer-sign -Wno-format -include
                  ${CMAKE_CURRENT_SOURCE_DIR}/port/nuttx_scp.h
                  -Wno-strict-prototypes)
      endif()
    
   -  target_sources(apps PRIVATE ${DROPBEAR_SRCS})
   -
    endif()
   ```
   
   Note: the idiomatic fix would be to pass `INCLUDE_DIRECTORIES`, 
`DEFINITIONS` and
   `COMPILE_FLAGS` to `nuttx_add_application()` (those arguments are applied to 
the correct
   target internally) instead of using raw `target_*` calls. The per-source
   `COMPILE_DEFINITIONS` for `scp.c`/`scpmisc.c`/libtomcrypt still need
   `set_source_files_properties`, but for the entry-point source it must be 
`APPEND` so the
   `main=` alias survives.
   
   ### On which OS does this issue occur?
   
   [OS: Linux]
   
   ### What is the version of your OS?
   
   Arch Linux (rolling; kernel 7.2.9-arch1-1)
   
   ### NuttX Version
   
   master (nuttx 284d4d4ea4d427ff533735f94418023c003d7f1e, nuttx-apps 
27ecdd789f3e985f68610ea39c0aa3dcd6000d93); cmake 4.4.4, ninja 1.13.2, xPack 
riscv-none-elf-gcc 14.2.0
   
   ### Issue Architecture
   
   [Arch: risc-v]
   
   ### Issue Area
   
   [Area: Networking]
   
   ### Host information
   
   n/a - this is a CMake build (`make host_info` requires a Make-configured 
tree).
   
   ### Verification
   
   - [X] I have verified before submitting the report.
   
   ### Additional verification
   
   After applying the patch above, `esp32c3-devkit:dropbear` builds with CMake 
and runs on an
   ESP32-C3-DevKitM-1: the board joins Wi-Fi, obtains an address over DHCP and 
Dropbear listens
   on port 2222; `ssh -p 2222` and `scp -O -P 2222` both work.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to