diff --git a/cmake/nuttx_allsyms.cmake b/cmake/nuttx_allsyms.cmake index dbc8511824..d87d5a64ea 100644 --- a/cmake/nuttx_allsyms.cmake +++ b/cmake/nuttx_allsyms.cmake @@ -38,61 +38,55 @@ # dep_target : targets which depends on # allsyms_file : generated allsyms file name # ~~~ + +# create an empty allsyms source file for `nuttx` +set(ALLSYMS_SOURCE ${CMAKE_BINARY_DIR}/allsyms_empty.c) + +add_custom_command( + OUTPUT ${ALLSYMS_SOURCE} + COMMAND ${NUTTX_DIR}/tools/mkallsyms.py nuttx.empty ${ALLSYMS_SOURCE} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Generating allsyms_empty.c") +add_custom_target(generate_empty_allsyms DEPENDS ${ALLSYMS_SOURCE}) +add_dependencies(nuttx generate_empty_allsyms) + +target_sources(nuttx PRIVATE ${ALLSYMS_SOURCE}) +set(ALLSYMS_INCDIR ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include) +set_source_files_properties(${ALLSYMS_SOURCE} PROPERTIES INCLUDE_DIRECTORIES + "${ALLSYMS_INCDIR}") + macro(define_allsyms_link_target inter_target dep_target allsyms_file) - if(${inter_target} STREQUAL nuttx) - # create an empty allsyms source file for `nuttx` - set(ALLSYMS_SOURCE ${CMAKE_BINARY_DIR}/allsyms_empty.c) - if(NOT EXISTS ${ALLSYMS_SOURCE}) - file(WRITE ${ALLSYMS_SOURCE} "#include \n\n") - file(APPEND ${ALLSYMS_SOURCE} "#include \n") - file(APPEND ${ALLSYMS_SOURCE} "extern int g_nallsyms;\n\n") - file(APPEND ${ALLSYMS_SOURCE} "extern struct symtab_s g_allsyms[];\n\n") - file(APPEND ${ALLSYMS_SOURCE} "int g_nallsyms = 1;\n\n") - file( - APPEND ${ALLSYMS_SOURCE} - "struct symtab_s g_allsyms[1] = {{ \"Unknown\", (FAR void *)0x00000000 }};\n\n" - ) - endif() - target_sources(nuttx PRIVATE ${ALLSYMS_SOURCE}) - set(ALLSYMS_INCDIR ${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/include) - set_source_files_properties( - ${ALLSYMS_SOURCE} PROPERTIES INCLUDE_DIRECTORIES "${ALLSYMS_INCDIR}") - else() - # generate `g_allsyms` file - add_custom_command( - OUTPUT ${allsyms_file}.c POST_BUILD - COMMAND ${NUTTX_DIR}/tools/mkallsyms.py ${CMAKE_BINARY_DIR}/${dep_target} - ${allsyms_file}.c - DEPENDS ${dep_target} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - COMMAND_EXPAND_LISTS) + # generate `g_allsyms` file + add_custom_command( + OUTPUT ${allsyms_file}.c POST_BUILD + COMMAND ${NUTTX_DIR}/tools/mkallsyms.py ${CMAKE_BINARY_DIR}/${dep_target} + ${allsyms_file}.c + DEPENDS ${dep_target} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMAND_EXPAND_LISTS) - # relink target with allsysm.c which generated by the elf of the previous - # phase - add_executable( - ${inter_target} ${allsyms_file}.c - $,EXCLUDE,allsyms_empty>) + # relink target with allsysm.c which generated by the elf of the previous + # phase + add_executable( + ${inter_target} ${allsyms_file}.c + $,EXCLUDE,allsyms_empty>) - # relink target and nuttx have exactly the same configuration - target_include_directories( - ${inter_target} SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/include - ${CMAKE_BINARY_DIR}/include) - target_compile_definitions( - ${inter_target} PRIVATE $) - target_compile_options( - ${inter_target} - PRIVATE $) - target_link_options(${inter_target} PRIVATE - $) - target_link_libraries( - ${inter_target} - PRIVATE $> - ) - endif() + # relink target and nuttx have exactly the same configuration + target_include_directories( + ${inter_target} SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/include + ${CMAKE_BINARY_DIR}/include) + target_compile_definitions( + ${inter_target} PRIVATE $) + target_compile_options( + ${inter_target} + PRIVATE $) + target_link_options(${inter_target} PRIVATE + $) + target_link_libraries( + ${inter_target} + PRIVATE $>) endmacro() -# nuttx link with allsysm -define_allsyms_link_target(nuttx NULL NULL) # allsyms link phase 1 with generated allsyms source file define_allsyms_link_target(allsyms_inter nuttx allsyms_first_link) # allsyms link phase 2 since the table offset may changed