mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
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:
@@ -463,6 +463,11 @@ if(EXISTS ${NUTTX_BOARD_ABS_DIR}/cmake
|
|||||||
include(${NUTTX_BOARD_ABS_DIR}/cmake/Toolchain.cmake)
|
include(${NUTTX_BOARD_ABS_DIR}/cmake/Toolchain.cmake)
|
||||||
endif()
|
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)
|
include(platform)
|
||||||
|
|
||||||
if(CONFIG_ARCH_TOOLCHAIN_TASKING)
|
if(CONFIG_ARCH_TOOLCHAIN_TASKING)
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -94,3 +94,8 @@ endif()
|
|||||||
target_sources(arch PRIVATE ${SRCS})
|
target_sources(arch PRIVATE ${SRCS})
|
||||||
|
|
||||||
nuttx_add_aux_library(STARTUP_OBJS crt0.c)
|
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>>)
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -136,3 +136,10 @@ if(CONFIG_ARM64_SEMIHOSTING_HOSTFS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_sources(arch PRIVATE ${SRCS})
|
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>>)
|
||||||
|
|||||||
@@ -126,17 +126,21 @@ function(nuttx_add_application)
|
|||||||
COMMAND
|
COMMAND
|
||||||
${CMAKE_LD}
|
${CMAKE_LD}
|
||||||
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_LINK_OPTIONS>>
|
$<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
|
$<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
|
$<TARGET_FILE:${TARGET}> --end-group -o
|
||||||
${CMAKE_BINARY_DIR}/bin/${ELF_NAME}
|
${CMAKE_BINARY_DIR}/bin/${ELF_NAME}
|
||||||
|
COMMENT "Building ELF:${ELF_NAME}"
|
||||||
COMMAND_EXPAND_LISTS)
|
COMMAND_EXPAND_LISTS)
|
||||||
else()
|
else()
|
||||||
add_executable(${TARGET} ${SRCS})
|
add_executable(${TARGET} ${SRCS})
|
||||||
target_link_options(
|
target_link_options(
|
||||||
${TARGET} PRIVATE
|
${TARGET}
|
||||||
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_LINK_OPTIONS>>)
|
PRIVATE
|
||||||
|
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_LINK_OPTIONS>>
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# easy access to final ELF, regardless of how it was created
|
# 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
|
# loadable build requires applying ELF flags to all applications
|
||||||
|
|
||||||
if(CONFIG_MODULES)
|
if(CONFIG_MODULES)
|
||||||
|
add_dependencies(nuttx_apps_mksymtab ${TARGET})
|
||||||
target_compile_options(
|
target_compile_options(
|
||||||
${TARGET}
|
${TARGET}
|
||||||
PRIVATE
|
PRIVATE
|
||||||
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_ELF_APP_COMPILE_OPTIONS>>
|
$<GENEX_EVAL:$<TARGET_PROPERTY:nuttx_global,NUTTX_ELF_APP_COMPILE_OPTIONS>>
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -165,24 +170,6 @@ function(nuttx_add_application)
|
|||||||
set(TARGET "apps_${NAME}")
|
set(TARGET "apps_${NAME}")
|
||||||
add_library(${TARGET} ${SRCS})
|
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})
|
nuttx_add_library_internal(${TARGET})
|
||||||
# add to list of application libraries
|
# add to list of application libraries
|
||||||
|
|
||||||
@@ -247,6 +234,23 @@ function(nuttx_add_application)
|
|||||||
target_include_directories(${TARGET} BEFORE
|
target_include_directories(${TARGET} BEFORE
|
||||||
PRIVATE ${INCLUDE_DIRECTORIES})
|
PRIVATE ${INCLUDE_DIRECTORIES})
|
||||||
endif()
|
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()
|
endif()
|
||||||
|
|
||||||
# add supplied dependencies
|
# add supplied dependencies
|
||||||
|
|||||||
@@ -258,12 +258,10 @@ 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(
|
||||||
set_property(
|
TARGET nuttx_global
|
||||||
TARGET nuttx_global
|
APPEND
|
||||||
APPEND
|
PROPERTY NUTTX_ELF_LINK_EXTRA_LIBRARIES $<TARGET_FILE:${extra_target}>)
|
||||||
PROPERTY NUTTX_ELF_LINK_LIBRARIES $<TARGET_FILE:${extra_target}>)
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
@@ -257,6 +257,78 @@ function(nuttx_compile_options_ifndef cond)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
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
|
# the visible scope is all the APPS include search path
|
||||||
function(nuttx_include_directories_for_all_apps)
|
function(nuttx_include_directories_for_all_apps)
|
||||||
set_property(
|
set_property(
|
||||||
|
|||||||
@@ -57,5 +57,5 @@ if(CONFIG_LIBC_ELF)
|
|||||||
|
|
||||||
add_custom_target(elfldscript_tmp DEPENDS ${ELF_LD_SCRIPT_TMP})
|
add_custom_target(elfldscript_tmp DEPENDS ${ELF_LD_SCRIPT_TMP})
|
||||||
add_dependencies(nuttx elfldscript_tmp)
|
add_dependencies(nuttx elfldscript_tmp)
|
||||||
|
add_dependencies(apps_post elfldscript_tmp)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user