cmake(feat):define elf option and enable apps module build

1.define elf option setting function ext;
2.unify loadable elf and kernel elf build config

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
xuxin19
2025-03-19 21:11:43 +08:00
committed by GUIDINGLI
parent 885ff780c5
commit 6fa3031d9b
9 changed files with 183 additions and 30 deletions
+5
View File
@@ -463,6 +463,11 @@ if(EXISTS ${NUTTX_BOARD_ABS_DIR}/cmake
include(${NUTTX_BOARD_ABS_DIR}/cmake/Toolchain.cmake)
endif()
# Support loadable and kernel options by specific arch
if(EXISTS ${CMAKE_SOURCE_DIR}/arch/${CONFIG_ARCH}/src/cmake/elf.cmake)
include(${CMAKE_SOURCE_DIR}/arch/${CONFIG_ARCH}/src/cmake/elf.cmake)
endif()
include(platform)
if(CONFIG_ARCH_TOOLCHAIN_TASKING)
+35
View File
@@ -0,0 +1,35 @@
# ##############################################################################
# arch/arm/src/cmake/elf.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# Loadable and ELF module settings
nuttx_elf_compile_options(-fvisibility=hidden -mlong-calls)
nuttx_elf_compile_options_ifdef(CONFIG_UNWINDER_ARM -fno-unwind-tables
-fno-asynchronous-unwind-tables)
nuttx_elf_compile_options_ifdef(CONFIG_PIC --fixed-r10 -mpic-register=r10)
nuttx_elf_link_options_ifdef(
CONFIG_PIC --unresolved-symbols=ignore-in-object-files --emit-relocs)
nuttx_elf_link_options_ifdef(CONFIG_BINFMT_ELF_RELOCATABLE -r)
nuttx_elf_link_options_ifdef(CONFIG_BUILD_KERNEL -Bstatic)
+5
View File
@@ -94,3 +94,8 @@ endif()
target_sources(arch PRIVATE ${SRCS})
nuttx_add_aux_library(STARTUP_OBJS crt0.c)
target_compile_options(
STARTUP_OBJS
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_COMPILE_OPTIONS>>)
+27
View File
@@ -0,0 +1,27 @@
# ##############################################################################
# arch/arm/src/cmake/elf.cmake
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# ##############################################################################
# Loadable and ELF module settings
nuttx_elf_compile_options(-fvisibility=hidden)
nuttx_elf_link_options_ifdef(CONFIG_BINFMT_ELF_RELOCATABLE -r)
nuttx_elf_link_options_ifdef(CONFIG_BUILD_KERNEL -Bstatic)
+7
View File
@@ -136,3 +136,10 @@ if(CONFIG_ARM64_SEMIHOSTING_HOSTFS)
endif()
target_sources(arch PRIVATE ${SRCS})
nuttx_add_aux_library(STARTUP_OBJS crt0.c)
target_compile_options(
STARTUP_OBJS
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_COMPILE_OPTIONS>>)
+27 -23
View File
@@ -126,17 +126,21 @@ function(nuttx_add_application)
COMMAND
${CMAKE_LD}
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_LINK_OPTIONS>>
-e __start -Bstatic -T ${CMAKE_BINARY_DIR}/gnu-elf.ld
-e __start -T ${CMAKE_BINARY_DIR}/gnu-elf.ld
$<TARGET_OBJECTS:STARTUP_OBJS> --start-group
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_LINK_LIBRARIES>>
$<$<BOOL:${CONFIG_BUILD_KERNEL}>:$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_LINK_LIBRARIES>>>
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_LINK_EXTRA_LIBRARIES>>
$<TARGET_FILE:${TARGET}> --end-group -o
${CMAKE_BINARY_DIR}/bin/${ELF_NAME}
COMMENT "Building ELF:${ELF_NAME}"
COMMAND_EXPAND_LISTS)
else()
add_executable(${TARGET} ${SRCS})
target_link_options(
${TARGET} PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_LINK_OPTIONS>>)
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_LINK_OPTIONS>>
)
endif()
# easy access to final ELF, regardless of how it was created
@@ -148,10 +152,11 @@ function(nuttx_add_application)
# loadable build requires applying ELF flags to all applications
if(CONFIG_MODULES)
add_dependencies(nuttx_apps_mksymtab ${TARGET})
target_compile_options(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_COMPILE_OPTIONS>>
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_COMPILE_OPTIONS>>
)
endif()
@@ -165,24 +170,6 @@ function(nuttx_add_application)
set(TARGET "apps_${NAME}")
add_library(${TARGET} ${SRCS})
# Set apps global compile options & definitions hold by
# nuttx_apps_interface
target_compile_options(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_COMPILE_OPTIONS>>
)
target_compile_definitions(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_COMPILE_DEFINITIONS>>
)
target_include_directories(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_INCLUDE_DIRECTORIES>>
)
nuttx_add_library_internal(${TARGET})
# add to list of application libraries
@@ -247,6 +234,23 @@ function(nuttx_add_application)
target_include_directories(${TARGET} BEFORE
PRIVATE ${INCLUDE_DIRECTORIES})
endif()
# Set apps global compile options & definitions hold by nuttx_apps_interface
target_compile_options(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_COMPILE_OPTIONS>>
)
target_compile_definitions(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_COMPILE_DEFINITIONS>>
)
target_include_directories(
${TARGET}
PRIVATE
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_apps_interface,APPS_INCLUDE_DIRECTORIES>>
)
endif()
# add supplied dependencies
+4 -6
View File
@@ -258,12 +258,10 @@ function(nuttx_add_extra_library)
set_property(GLOBAL APPEND PROPERTY NUTTX_USER_EXTRA_LIBRARIES
${extra_target})
endif()
if(CONFIG_BUILD_KERNEL)
set_property(
TARGET nuttx_global
APPEND
PROPERTY NUTTX_ELF_LINK_LIBRARIES $<TARGET_FILE:${extra_target}>)
endif()
set_property(
TARGET nuttx_global
APPEND
PROPERTY NUTTX_ELF_LINK_EXTRA_LIBRARIES $<TARGET_FILE:${extra_target}>)
endif()
endforeach()
endfunction()
+72
View File
@@ -257,6 +257,78 @@ function(nuttx_compile_options_ifndef cond)
endif()
endfunction()
# Function: nuttx_elf_compile_options
#
# Adds compile options to elf targets
#
# Usage: nuttx_elf_compile_options("-O2" "-Wall")
function(nuttx_elf_compile_options)
set_property(
TARGET nuttx_global
APPEND
PROPERTY NUTTX_ELF_APP_COMPILE_OPTIONS ${ARGN})
endfunction()
# Function: nuttx_elf_compile_options_ifdef
#
# Conditionally adds compile options to the elf target if the given condition is
# true.
#
# Usage: nuttx_elf_compile_options_ifdef(MY_CONDITION "-O2" "-Wall")
function(nuttx_elf_compile_options_ifdef cond)
if(${cond})
nuttx_elf_compile_options(${ARGN})
endif()
endfunction()
# Function: nuttx_elf_compile_options_ifndef
#
# Conditionally adds compile options to the elf target if the given condition is
# false.
#
# Usage: nuttx_elf_compile_options_ifndef(MY_CONDITION "-O2" "-Wall")
function(nuttx_elf_compile_options_ifndef cond)
if(NOT ${cond})
nuttx_elf_compile_options(${ARGN})
endif()
endfunction()
# Function: nuttx_elf_link_options
#
# Adds link options to elf targets
#
# Usage: nuttx_elf_link_options("-r")
function(nuttx_elf_link_options)
set_property(
TARGET nuttx_global
APPEND
PROPERTY NUTTX_ELF_APP_LINK_OPTIONS ${ARGN})
endfunction()
# Function: nuttx_elf_link_options_ifdef
#
# Conditionally adds link options to the elf target if the given condition is
# true.
#
# Usage: nuttx_elf_link_options_ifdef(MY_CONDITION "-r")
function(nuttx_elf_link_options_ifdef cond)
if(${cond})
nuttx_elf_link_options(${ARGN})
endif()
endfunction()
# Function: nuttx_elf_link_options_ifndef
#
# Conditionally adds link options to the elf target if the given condition is
# false.
#
# Usage: nuttx_elf_link_options_ifndef(MY_CONDITION "-r")
function(nuttx_elf_link_options_ifndef cond)
if(NOT ${cond})
nuttx_elf_link_options(${ARGN})
endif()
endfunction()
# the visible scope is all the APPS include search path
function(nuttx_include_directories_for_all_apps)
set_property(
+1 -1
View File
@@ -57,5 +57,5 @@ if(CONFIG_LIBC_ELF)
add_custom_target(elfldscript_tmp DEPENDS ${ELF_LD_SCRIPT_TMP})
add_dependencies(nuttx elfldscript_tmp)
add_dependencies(apps_post elfldscript_tmp)
endif()