cmake:bugfix fix cmake CPP options get NULL in add_romfs

CMake Error at cmake/nuttx_add_romfs.cmake:60 (string):
  string sub-command REPLACE requires at least four arguments.
Call Stack (most recent call first):
  boards/sim/sim/sim/src/CMakeLists.txt:68 (nuttx_add_romfs)

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
xuxin19 2024-06-14 14:39:49 +08:00 committed by archer
parent 35c8c80a00
commit 49bdd62aa3

View file

@ -59,14 +59,28 @@ function(nuttx_add_romfs)
message(FATAL_ERROR "Either PATH or FILES must be specified")
endif()
get_directory_property(TOOLCHAIN_DIR_FLAGS DIRECTORY ${CMAKE_SOURCE_DIR}
COMPILE_OPTIONS)
set(ROMFS_CMAKE_C_FLAGS "")
foreach(FLAG ${TOOLCHAIN_DIR_FLAGS})
if(NOT FLAG MATCHES "^\\$<.*>$")
list(APPEND ROMFS_CMAKE_C_FLAGS ${FLAG})
else()
string(REGEX MATCH "\\$<\\$<COMPILE_LANGUAGE:C>:(.*)>" matched ${FLAG})
if(matched)
list(APPEND ROMFS_CMAKE_C_FLAGS ${CMAKE_MATCH_1})
endif()
endif()
endforeach()
foreach(rcsrc ${RCSRCS})
get_filename_component(rcpath ${rcsrc} DIRECTORY)
separate_arguments(CMAKE_C_FLAG_ARGS NATIVE_COMMAND ${CMAKE_C_FLAGS})
add_custom_command(
OUTPUT ${rcsrc}
COMMAND ${CMAKE_COMMAND} -E make_directory ${rcpath}
COMMAND
${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P -x c
${CMAKE_C_COMPILER} ${ROMFS_CMAKE_C_FLAGS} -E -P -x c
-I${CMAKE_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/${rcsrc} >
${rcsrc}
DEPENDS nuttx_context ${CMAKE_CURRENT_SOURCE_DIR}/${rcsrc})