greenhills: add cmake support

1. refactor the ghs/gcc/clang/armclang toolchain management in CMake
2. unify the cmake toolchain naming style
3. support greenhills build procedure with CMake
4. add protect build for greenhills and gnu toolchain with CMake

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
This commit is contained in:
guoshichao
2024-08-16 20:43:38 +08:00
committed by Xiang Xiao
parent 17b31d2037
commit ff4ad07576
20 changed files with 1218 additions and 375 deletions

View File

@@ -201,9 +201,11 @@ function(nuttx_add_extra_library)
# define the target name of the extra library
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" extra_target "${extra_lib}")
# set the absolute path of the library for the import target
if(NOT TARGET ${extra_target})
nuttx_library_import(${extra_target} ${extra_lib})
set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES ${extra_target})
nuttx_library_import(${extra_target} ${extra_lib})
set_property(GLOBAL APPEND PROPERTY NUTTX_EXTRA_LIBRARIES ${extra_target})
if(CONFIG_BUILD_PROTECTED)
set_property(GLOBAL APPEND PROPERTY NUTTX_USER_EXTRA_LIBRARIES
${extra_target})
endif()
endforeach()
endfunction()

View File

@@ -113,14 +113,12 @@ function(nuttx_add_romfs)
endif()
get_filename_component(rcpath ${SOURCE_ETC_SUFFIX} DIRECTORY)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_ETC_SUFFIX}
COMMAND ${CMAKE_COMMAND} -E make_directory ${rcpath}
COMMAND
${CMAKE_C_COMPILER} ${ROMFS_CMAKE_C_FLAGS} -E -P -x c
-I${CMAKE_BINARY_DIR}/include ${SOURCE_ETC_PREFIX}/${SOURCE_ETC_SUFFIX}
> ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_ETC_SUFFIX}
DEPENDS nuttx_context ${SOURCE_ETC_PREFIX}/${SOURCE_ETC_SUFFIX})
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${rcpath})
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${rcpath})
endif()
nuttx_generate_preproces_target(
SOURCE_FILE ${SOURCE_ETC_PREFIX}/${SOURCE_ETC_SUFFIX} TARGET_FILE
${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_ETC_SUFFIX} DEPENDS nuttx_context)
list(APPEND DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${SOURCE_ETC_SUFFIX})
endforeach()

View File

@@ -84,8 +84,10 @@ macro(define_allsyms_link_target inter_target dep_target allsyms_file)
PRIVATE $<TARGET_PROPERTY:nuttx,NUTTX_KERNEL_COMPILE_OPTIONS>)
target_link_options(${inter_target} PRIVATE
$<TARGET_PROPERTY:nuttx,LINK_OPTIONS>)
target_link_libraries(${inter_target}
PRIVATE $<TARGET_PROPERTY:nuttx,LINK_LIBRARIES>)
target_link_libraries(
${inter_target}
PRIVATE $<TARGET_GENEX_EVAL:nuttx,$<TARGET_PROPERTY:nuttx,LINK_LIBRARIES>>
)
endif()
endmacro()

View File

@@ -0,0 +1,99 @@
# ##############################################################################
# cmake/nuttx_toolchain.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.
#
# ##############################################################################
# This file is used to set the parts that need common settings in the Toolchain
# file. Such as preprocessing process, link command, toolchain library method
# search. If the manual of the newly supported toolchain is different, you can
# override these methods in the toolchain
# ~~~
# nuttx_generate_preproces_target
#
# Description:
# because different toolchains have different preprocessing instructions,
# we define the COMMON preprocessing target here.
#
# Prototype:
# nuttx_generate_preproces_target(
# SOURCE_FILE
# ${single_source_file}
# TARGET_FILE
# ${single_target_output}
# DEPENDS
# ${option_depned_target})
# ~~~
#
if(NOT NUTTX_TOOLCHAIN_PREPROCES_DEFINED)
function(nuttx_generate_preproces_target)
# parse arguments into variables
nuttx_parse_function_args(
FUNC
nuttx_generate_preproces_target
ONE_VALUE
SOURCE_FILE
TARGET_FILE
MULTI_VALUE
DEPENDS
REQUIRED
SOURCE_FILE
TARGET_FILE
ARGN
${ARGN})
add_custom_command(
OUTPUT ${TARGET_FILE}
COMMAND ${PREPROCESS} -I${CMAKE_BINARY_DIR}/include
-I${NUTTX_CHIP_ABS_DIR} ${SOURCE_FILE} > ${TARGET_FILE}
DEPENDS ${SOURCE_FILE} ${DEPENDS})
endfunction()
endif()
# ~~~
# nuttx_find_toolchain_lib
#
# Description:
# this is general function for finding toolchain libraries.
#
# Prototype:
# nuttx_find_toolchain_lib(${single_toolchain_lib})
# ~~~
if(NOT NUTTX_FIND_TOOLCHAIN_LIB_DEFINED)
function(nuttx_find_toolchain_lib)
if(NOT ARGN)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-libgcc-file-name
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE extra_lib_path)
else()
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name=${ARGN}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE extra_lib_path)
endif()
nuttx_add_extra_library(${extra_lib_path})
endfunction()
endif()