mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 13:27:01 +08:00
cmake(feat):implements KERNEL mode in CMake build
1.add application link dependencies for all elf
2.add a global custom target to hold proptry in the toolchain file
3.add startup obj target
4.fix cpp lds error with kernel mod link elf lds
usage:
./build.sh qemu-armv7a:knsh --cmake
elf install in ${CMAKE_BINARY_DIR}/bin
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
+11
-9
@@ -378,6 +378,12 @@ if(NOT EXISTS ${CMAKE_BINARY_DIR}/.config OR NOT "${NUTTX_DEFCONFIG}" STREQUAL
|
|||||||
message(STATUS " Appdir: ${NUTTX_APPS_DIR}")
|
message(STATUS " Appdir: ${NUTTX_APPS_DIR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# declare global custom targets at very beginning `nuttx_global` is used to hold
|
||||||
|
# global target properties to solve that cmake GLOBAL property can not use
|
||||||
|
# generator expression this is needed to make sure added before project() create
|
||||||
|
# before Toolchain file added before all cmake modules are loaded
|
||||||
|
add_custom_target(nuttx_global)
|
||||||
|
|
||||||
# Include .cmake files #######################################################
|
# Include .cmake files #######################################################
|
||||||
|
|
||||||
# this exposes all Kconfig vars to CMake
|
# this exposes all Kconfig vars to CMake
|
||||||
@@ -598,15 +604,11 @@ endif()
|
|||||||
|
|
||||||
# Add apps/ to the build (if present)
|
# Add apps/ to the build (if present)
|
||||||
|
|
||||||
if(NOT CONFIG_BUILD_KERNEL)
|
if(EXISTS ${NUTTX_APPS_DIR}/CMakeLists.txt)
|
||||||
|
add_subdirectory(${NUTTX_APPS_DIR} apps)
|
||||||
if(EXISTS ${NUTTX_APPS_DIR}/CMakeLists.txt)
|
else()
|
||||||
add_subdirectory(${NUTTX_APPS_DIR} apps)
|
message(
|
||||||
else()
|
STATUS "Application directory not found at ${NUTTX_APPS_DIR}, skipping")
|
||||||
message(
|
|
||||||
STATUS "Application directory not found at ${NUTTX_APPS_DIR}, skipping")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# after we traverse all build directories unify all target dependencies and all
|
# after we traverse all build directories unify all target dependencies and all
|
||||||
|
|||||||
@@ -92,3 +92,5 @@ if(CONFIG_ARCH_HAVE_FETCHADD)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_sources(arch PRIVATE ${SRCS})
|
target_sources(arch PRIVATE ${SRCS})
|
||||||
|
|
||||||
|
nuttx_add_aux_library(STARTUP_OBJS crt0.c)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
set(SRCS qemu_boot.c qemu_serial.c qemu_irq.c qemu_timer.c)
|
set(SRCS qemu_boot.c qemu_serial.c qemu_irq.c qemu_timer.c)
|
||||||
|
|
||||||
if(CONFIG_ARCH_ARMV7A)
|
if(CONFIG_ARCH_ARMV7A)
|
||||||
list(APPEND SRCS qemu_memorymap.c)
|
list(APPEND SRCS qemu_pgalloc.c qemu_memorymap.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CONFIG_SMP)
|
if(CONFIG_SMP)
|
||||||
|
|||||||
@@ -112,14 +112,18 @@ function(nuttx_add_application)
|
|||||||
# non-elf output
|
# non-elf output
|
||||||
if(NOT CMAKE_C_ELF_COMPILER)
|
if(NOT CMAKE_C_ELF_COMPILER)
|
||||||
add_library(${TARGET} ${SRCS})
|
add_library(${TARGET} ${SRCS})
|
||||||
|
add_dependencies(${TARGET} nuttx_post)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ${TARGET}
|
TARGET ${TARGET}
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND
|
COMMAND
|
||||||
${CMAKE_C_COMPILER}
|
${CMAKE_LD}
|
||||||
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_LINK_OPTIONS>>
|
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_LINK_OPTIONS>>
|
||||||
$<TARGET_FILE:${TARGET}> -o ${TARGET}
|
-e __start -Bstatic -T ${CMAKE_BINARY_DIR}/gnu-elf.ld
|
||||||
|
$<TARGET_OBJECTS:STARTUP_OBJS> --start-group
|
||||||
|
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_LINK_LIBRARIES>>
|
||||||
|
$<TARGET_FILE:${TARGET}> --end-group -o
|
||||||
|
${CMAKE_BINARY_DIR}/bin/${TARGET}
|
||||||
COMMAND_EXPAND_LISTS)
|
COMMAND_EXPAND_LISTS)
|
||||||
else()
|
else()
|
||||||
add_executable(${TARGET} ${SRCS})
|
add_executable(${TARGET} ${SRCS})
|
||||||
|
|||||||
@@ -118,6 +118,13 @@ function(nuttx_add_system_library target)
|
|||||||
|
|
||||||
# add to list of libraries to link to final nuttx binary
|
# add to list of libraries to link to final nuttx binary
|
||||||
set_property(GLOBAL APPEND PROPERTY NUTTX_SYSTEM_LIBRARIES ${target})
|
set_property(GLOBAL APPEND PROPERTY NUTTX_SYSTEM_LIBRARIES ${target})
|
||||||
|
|
||||||
|
set_property(
|
||||||
|
TARGET nuttx_global
|
||||||
|
APPEND
|
||||||
|
PROPERTY NUTTX_ELF_LINK_LIBRARIES $<TARGET_FILE:${target}>)
|
||||||
|
|
||||||
|
add_dependencies(nuttx_post ${target})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
# Kernel Libraries
|
# Kernel Libraries
|
||||||
@@ -196,6 +203,14 @@ function(nuttx_add_library target)
|
|||||||
add_library(${target} ${ARGN})
|
add_library(${target} ${ARGN})
|
||||||
add_dependencies(${target} apps_context)
|
add_dependencies(${target} apps_context)
|
||||||
set_property(GLOBAL APPEND PROPERTY NUTTX_SYSTEM_LIBRARIES ${target})
|
set_property(GLOBAL APPEND PROPERTY NUTTX_SYSTEM_LIBRARIES ${target})
|
||||||
|
|
||||||
|
set_property(
|
||||||
|
TARGET nuttx_global
|
||||||
|
APPEND
|
||||||
|
PROPERTY NUTTX_ELF_LINK_LIBRARIES $<TARGET_FILE:${target}>)
|
||||||
|
|
||||||
|
add_dependencies(nuttx_post ${target})
|
||||||
|
|
||||||
# Set apps global compile options & definitions hold by nuttx_apps_interface
|
# Set apps global compile options & definitions hold by nuttx_apps_interface
|
||||||
target_compile_options(
|
target_compile_options(
|
||||||
${target}
|
${target}
|
||||||
@@ -236,6 +251,12 @@ function(nuttx_add_extra_library)
|
|||||||
set_property(GLOBAL APPEND PROPERTY NUTTX_USER_EXTRA_LIBRARIES
|
set_property(GLOBAL APPEND PROPERTY NUTTX_USER_EXTRA_LIBRARIES
|
||||||
${extra_target})
|
${extra_target})
|
||||||
endif()
|
endif()
|
||||||
|
if(CONFIG_BUILD_KERNEL)
|
||||||
|
set_property(
|
||||||
|
TARGET nuttx_global
|
||||||
|
APPEND
|
||||||
|
PROPERTY NUTTX_ELF_LINK_LIBRARIES $<TARGET_FILE:${extra_target}>)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
@@ -259,6 +280,11 @@ function(nuttx_add_external_library target)
|
|||||||
cmake_parse_arguments(ARGS "" MODE "" ${ARGN})
|
cmake_parse_arguments(ARGS "" MODE "" ${ARGN})
|
||||||
if(NOT ARGS_MODE)
|
if(NOT ARGS_MODE)
|
||||||
set_property(GLOBAL APPEND PROPERTY NUTTX_SYSTEM_LIBRARIES ${target})
|
set_property(GLOBAL APPEND PROPERTY NUTTX_SYSTEM_LIBRARIES ${target})
|
||||||
|
set_property(
|
||||||
|
TARGET nuttx_global
|
||||||
|
APPEND
|
||||||
|
PROPERTY NUTTX_ELF_LINK_LIBRARIES $<TARGET_FILE:${target}>)
|
||||||
|
add_dependencies(nuttx_post ${target})
|
||||||
elseif("${ARGS_MODE}" STREQUAL "APPS")
|
elseif("${ARGS_MODE}" STREQUAL "APPS")
|
||||||
set_property(GLOBAL APPEND PROPERTY NUTTX_APPS_LIBRARIES ${target})
|
set_property(GLOBAL APPEND PROPERTY NUTTX_APPS_LIBRARIES ${target})
|
||||||
elseif("${ARGS_MODE}" STREQUAL "KERNEL")
|
elseif("${ARGS_MODE}" STREQUAL "KERNEL")
|
||||||
|
|||||||
@@ -281,6 +281,14 @@ function(nuttx_compile_definitions_for_all_apps)
|
|||||||
PROPERTY APPS_COMPILE_DEFINITIONS ${ARGN})
|
PROPERTY APPS_COMPILE_DEFINITIONS ${ARGN})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# all elf link options
|
||||||
|
function(nuttx_add_elf_link_options)
|
||||||
|
set_property(
|
||||||
|
TARGET nuttx_global
|
||||||
|
APPEND
|
||||||
|
PROPERTY NUTTX_ELF_APP_LINK_OPTIONS ${ARGN})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
# since we dont call `target_link_libraries` directly, we only inherit their
|
# since we dont call `target_link_libraries` directly, we only inherit their
|
||||||
# compilation configuration
|
# compilation configuration
|
||||||
function(nuttx_link_libraries)
|
function(nuttx_link_libraries)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ if(NOT NUTTX_TOOLCHAIN_PREPROCESS_DEFINED)
|
|||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${TARGET_FILE}
|
OUTPUT ${TARGET_FILE}
|
||||||
COMMAND ${PREPROCESS} -I${CMAKE_BINARY_DIR}/include
|
COMMAND ${PREPROCESS} -I${CMAKE_BINARY_DIR}/include -I${NUTTX_DIR}/include
|
||||||
-I${NUTTX_CHIP_ABS_DIR} ${SOURCE_FILE} > ${TARGET_FILE}
|
-I${NUTTX_CHIP_ABS_DIR} ${SOURCE_FILE} > ${TARGET_FILE}
|
||||||
DEPENDS ${SOURCE_FILE} ${DEPENDS})
|
DEPENDS ${SOURCE_FILE} ${DEPENDS})
|
||||||
|
|
||||||
|
|||||||
@@ -49,4 +49,13 @@ if(CONFIG_LIBC_ELF)
|
|||||||
|
|
||||||
target_sources(c PRIVATE ${SRCS})
|
target_sources(c PRIVATE ${SRCS})
|
||||||
|
|
||||||
|
set(ELF_LD_SCRIPT_TMP "${CMAKE_BINARY_DIR}/gnu-elf.ld")
|
||||||
|
|
||||||
|
nuttx_generate_preprocess_target(
|
||||||
|
SOURCE_FILE ${NUTTX_DIR}/libs/libc/elf/gnu-elf.ld.in TARGET_FILE
|
||||||
|
${ELF_LD_SCRIPT_TMP})
|
||||||
|
|
||||||
|
add_custom_target(elfldscript_tmp DEPENDS ${ELF_LD_SCRIPT_TMP})
|
||||||
|
add_dependencies(nuttx elfldscript_tmp)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user