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

@@ -396,6 +396,9 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/arch/${CONFIG_ARCH}/src/cmake)
set(CMAKE_TOOLCHAIN_FILE
"${CMAKE_SOURCE_DIR}/arch/${CONFIG_ARCH}/src/cmake/Toolchain.cmake")
# include common toolchain setting
include(nuttx_toolchain)
# Define project #############################################################
# This triggers configuration
@@ -466,15 +469,6 @@ else()
nuttx PRIVATE $<GENEX_EVAL:$<TARGET_PROPERTY:nuttx,NUTTX_COMPILE_OPTIONS>>)
endif()
# Compiler options TODO: move elsewhere
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9)
# force color for gcc > 4.9
add_compile_options(-fdiagnostics-color=always)
endif()
endif()
if(MSVC)
add_compile_options(
-W2
@@ -493,21 +487,6 @@ elseif(NOT CONFIG_ARCH_TOOLCHAIN_TASKING)
$<$<COMPILE_LANGUAGE:ASM>:-D__ASSEMBLY__>)
endif()
if(NOT CONFIG_LIBCXXTOOLCHAIN)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
else()
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-D_STDLIB_H_>)
endif()
if(NOT CONFIG_CXX_EXCEPTION)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fcheck-new>)
endif()
if(CONFIG_STACK_CANARIES)
add_compile_options(-fstack-protector-all)
endif()
if(CONFIG_NDEBUG)
add_compile_options(-DNDEBUG)
endif()
@@ -530,6 +509,8 @@ endif()
add_definitions(-D__NuttX__)
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-D__ASSEMBLY__>)
set_property(
TARGET nuttx
APPEND
@@ -593,16 +574,12 @@ endif()
get_property(ldscript GLOBAL PROPERTY LD_SCRIPT)
# Pre-compile linker script
if(DEFINED PREPROCESS)
if(NOT CONFIG_ARCH_SIM)
get_filename_component(LD_SCRIPT_NAME ${ldscript} NAME)
set(LD_SCRIPT_TMP "${CMAKE_BINARY_DIR}/${LD_SCRIPT_NAME}.tmp")
add_custom_command(
OUTPUT ${LD_SCRIPT_TMP}
DEPENDS ${ldscript}
COMMAND ${PREPROCESS} -I${CMAKE_BINARY_DIR}/include -I${NUTTX_CHIP_ABS_DIR}
${ldscript} > ${LD_SCRIPT_TMP}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
nuttx_generate_preproces_target(SOURCE_FILE ${ldscript} TARGET_FILE
${LD_SCRIPT_TMP})
add_custom_target(ldscript_tmp DEPENDS ${LD_SCRIPT_TMP})
add_dependencies(nuttx ldscript_tmp)
@@ -638,14 +615,18 @@ set(nuttx_libs ${nuttx_kernel_libs} ${nuttx_system_libs} ${nuttx_apps_libs}
${nuttx_extra_libs})
if(NOT CONFIG_ARCH_SIM)
# TODO: nostart/nodefault not applicable to nuttx toolchain
if(CONFIG_ARCH_TOOLCHAIN_TASKING)
target_link_libraries(nuttx PRIVATE --lsl-file=${ldscript} ${nuttx_libs})
else()
target_link_libraries(
nuttx PRIVATE ${NUTTX_EXTRA_FLAGS} -T${ldscript} -Wl,--start-group
${nuttx_libs} -Wl,--end-group)
nuttx
PRIVATE ${NUTTX_EXTRA_FLAGS}
-T
${ldscript}
$<$<NOT:$<BOOL:${DISABLE_LINK_GROUP}>>:-Wl,--start-group>
${nuttx_libs}
$<$<NOT:$<BOOL:${DISABLE_LINK_GROUP}>>:-Wl,--end-group>)
endif()
# generate binary outputs in different formats (.bin, .hex, etc)
@@ -750,48 +731,55 @@ if(CONFIG_BUILD_PROTECTED)
get_property(nuttx_apps_libs GLOBAL PROPERTY NUTTX_APPS_LIBRARIES)
get_property(nuttx_user_extra_libs GLOBAL PROPERTY NUTTX_USER_EXTRA_LIBRARIES)
get_property(user_ldscript GLOBAL PROPERTY LD_SCRIPT_USER)
if(DEFINED PREPROCESS)
get_filename_component(LD_SCRIPT_NAME ${user_ldscript} NAME)
set(LD_SCRIPT_TMP "${CMAKE_BINARY_DIR}/${LD_SCRIPT_NAME}.tmp")
add_custom_command(
OUTPUT ${LD_SCRIPT_TMP}
DEPENDS ${user_ldscript}
COMMAND ${PREPROCESS} -I${CMAKE_BINARY_DIR}/include
-I${NUTTX_CHIP_ABS_DIR} ${user_ldscript} > ${LD_SCRIPT_TMP}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(user_ldscript_tmp DEPENDS ${LD_SCRIPT_TMP})
add_dependencies(nuttx_user user_ldscript_tmp)
set(user_ldscript ${LD_SCRIPT_TMP})
# Pre-compile linker script
get_filename_component(LD_SCRIPT_USER_NAME ${user_ldscript} NAME)
set(LD_SCRIPT_USER_TMP "${CMAKE_BINARY_DIR}/${LD_SCRIPT_USER_NAME}.tmp")
nuttx_generate_preproces_target(SOURCE_FILE ${user_ldscript} TARGET_FILE
${LD_SCRIPT_USER_TMP})
add_custom_target(user_ldscript_tmp DEPENDS ${LD_SCRIPT_USER_TMP})
add_dependencies(nuttx_user user_ldscript_tmp)
set(user_ldscript ${LD_SCRIPT_USER_TMP})
# reset link options that don't fit userspace
get_target_property(nuttx_user_LINK_OPTIONS nuttx_user LINK_OPTIONS)
list(REMOVE_ITEM nuttx_user_LINK_OPTIONS "-Wl,--cref")
list(REMOVE_ITEM nuttx_user_LINK_OPTIONS "-Wl,-Map=nuttx.map")
if(CONFIG_ARCH_TOOLCHAIN_GHS)
list(REMOVE_ITEM nuttx_user_LINK_OPTIONS "-entry=__start")
list(REMOVE_ITEM nuttx_user_LINK_OPTIONS "-map=nuttx.map")
list(APPEND nuttx_user_LINK_OPTIONS "-map=nuttx_user.map")
else()
list(REMOVE_ITEM nuttx_user_LINK_OPTIONS "-Wl,--entry=__start")
list(APPEND nuttx_user_LINK_OPTIONS "-Wl,-Map=nuttx_user.map")
endif()
list(TRANSFORM user_ldscript PREPEND "-T")
set_target_properties(nuttx_user PROPERTIES LINK_OPTIONS
"${nuttx_user_LINK_OPTIONS}")
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${NUTTX_EXTRA_FLAGS}
--print-libgcc-file-name
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE nuttx_user_libgcc)
# reset link options for userspace to prevent sections from being accidentally
# deleted
set_target_properties(nuttx_user PROPERTIES LINK_OPTIONS "")
target_link_options(
nuttx_user PRIVATE -nostartfiles -nodefaultlibs
-Wl,--entry=${CONFIG_INIT_ENTRYPOINT}
-Wl,--undefined=${CONFIG_INIT_ENTRYPOINT})
if(CONFIG_ARCH_TOOLCHAIN_GHS)
target_link_options(nuttx_user PRIVATE -nostartfiles -minlib
-entry=${CONFIG_INIT_ENTRYPOINT})
else()
target_link_options(
nuttx_user PRIVATE -nostartfiles -nodefaultlibs
-Wl,--entry=${CONFIG_INIT_ENTRYPOINT}
-Wl,--undefined=${CONFIG_INIT_ENTRYPOINT})
endif()
target_link_libraries(
nuttx_user
PRIVATE ${user_ldscript}
$<$<NOT:$<BOOL:${APPLE}>>:-Wl,--start-group>
PRIVATE -T
${user_ldscript}
$<$<NOT:$<BOOL:${DISABLE_LINK_GROUP}>>:-Wl,--start-group>
${nuttx_system_libs}
${nuttx_apps_libs}
${nuttx_user_libgcc}
${nuttx_user_extra_libs}
$<$<BOOL:${CONFIG_HAVE_CXX}>:supc++>
$<$<NOT:$<BOOL:${APPLE}>>:-Wl,--end-group>)
$<$<NOT:$<BOOL:${DISABLE_LINK_GROUP}>>:-Wl,--end-group>)
target_include_directories(
nuttx_user SYSTEM

View File

@@ -43,188 +43,14 @@ endif()
include(${ARCH_SUBDIR})
if(CONFIG_ARCH_TOOLCHAIN_CLANG)
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_STRIP llvm-strip --strip-unneeded)
set(CMAKE_OBJCOPY llvm-objcopy)
set(CMAKE_OBJDUMP llvm-objdump)
set(CMAKE_LINKER ld.lld)
set(CMAKE_LD ld.lld)
set(CMAKE_AR llvm-ar)
set(CMAKE_NM llvm-nm)
set(CMAKE_RANLIB llvm-ranlib)
set(TOOLCHAIN_FILE)
# Since the no_builtin attribute is not fully supported on Clang disable the
# built-in functions, refer:
# https://github.com/apache/incubator-nuttx/pull/5971
add_compile_options(-fno-builtin)
add_compile_options(-Wno-atomic-alignment)
add_compile_options(-Wno-atomic-alignment)
else()
set(TOOLCHAIN_PREFIX arm-none-eabi)
set(CMAKE_LIBRARY_ARCHITECTURE ${TOOLCHAIN_PREFIX})
set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN_PREFIX})
set(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN_PREFIX})
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_C_COMPILER ${CMAKE_ASM_COMPILER})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}-strip --strip-unneeded)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy)
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump)
if(CONFIG_LTO_FULL AND CONFIG_ARCH_TOOLCHAIN_GNU)
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_LD ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}-gcc-ar)
set(CMAKE_NM ${TOOLCHAIN_PREFIX}-gcc-nm)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-gcc-ranlib)
else()
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-ld)
set(CMAKE_LD ${TOOLCHAIN_PREFIX}-ld)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}-ar)
set(CMAKE_NM ${TOOLCHAIN_PREFIX}-nm)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-ranlib)
endif()
if(CONFIG_ARCH_TOOLCHAIN_CLANG) # clang
set(TOOLCHAIN_FILE clang)
elseif(CONFIG_ARCH_TOOLCHAIN_GHS) # greenhills
set(TOOLCHAIN_FILE ghs)
else() # gcc
set(TOOLCHAIN_FILE gcc)
endif()
# override the ARCHIVE command
set(CMAKE_ARCHIVE_COMMAND "<CMAKE_AR> rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_RANLIB_COMMAND "<CMAKE_RANLIB> <TARGET>")
set(CMAKE_C_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_C_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_C_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_CXX_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_ASM_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
# Architecture flags
add_link_options(-Wl,--entry=__start)
add_link_options(-nostdlib)
add_compile_options(-fno-common)
add_compile_options(-Wall -Wshadow -Wundef)
add_compile_options(-nostdlib)
if(CONFIG_ARM_THUMB)
add_compile_options(-mthumb)
# GCC Manual: -mthumb ... If you want to force assembler files to be
# interpreted as Thumb code, either add a `.thumb' directive to the source or
# pass the -mthumb option directly to the assembler by prefixing it with -Wa.
add_compile_options(-Wa,-mthumb)
# Outputs an implicit IT block when there is a conditional instruction without
# an enclosing IT block.
add_compile_options(-Wa,-mimplicit-it=always)
endif()
if(CONFIG_UNWINDER_ARM)
add_compile_options(-funwind-tables -fasynchronous-unwind-tables)
endif()
if(CONFIG_DEBUG_CUSTOMOPT)
add_compile_options(${CONFIG_DEBUG_OPTLEVEL})
elseif(CONFIG_DEBUG_FULLOPT)
if(CONFIG_ARCH_TOOLCHAIN_CLANG)
add_compile_options(-Oz)
else()
add_compile_options(-Os)
endif()
endif()
if(NOT CONFIG_DEBUG_NOOPT)
add_compile_options(-fno-strict-aliasing)
endif()
if(CONFIG_FRAME_POINTER)
add_compile_options(-fno-omit-frame-pointer -fno-optimize-sibling-calls)
else()
add_compile_options(-fomit-frame-pointer)
endif()
if(CONFIG_STACK_CANARIES)
add_compile_options(-fstack-protector-all)
endif()
if(CONFIG_ARCH_COVERAGE)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()
# Optimization of unused sections
if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
add_link_options(-Wl,--gc-sections)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
# Debug --whole-archive
if(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE)
add_link_options(-Wl,--whole-archive)
endif()
if(CONFIG_ENDIAN_BIG)
add_compile_options(-mbig-endian)
endif()
# Link Time Optimization
if(CONFIG_LTO_THIN)
add_compile_options(-flto=thin)
elseif(CONFIG_LTO_FULL)
add_compile_options(-flto)
if(CONFIG_ARCH_TOOLCHAIN_GNU)
add_compile_options(-fno-builtin)
add_compile_options(-fuse-linker-plugin)
endif()
endif()
# Debug link map
if(CONFIG_DEBUG_LINK_MAP)
add_link_options(-Wl,--cref -Wl,-Map=nuttx.map)
endif()
if(CONFIG_DEBUG_SYMBOLS)
add_compile_options(${CONFIG_DEBUG_SYMBOLS_LEVEL})
if(CONFIG_ARM_TOOLCHAIN_ARMCLANG)
add_link_options(-Wl,--debug)
endif()
endif()
add_compile_options(-Wno-attributes -Wno-unknown-pragmas
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>)
if(CONFIG_CXX_STANDARD)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=${CONFIG_CXX_STANDARD}>)
endif()
if(NOT CONFIG_LIBCXXTOOLCHAIN)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
endif()
if(NOT CONFIG_CXX_EXCEPTION)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fcheck-new>)
endif()
if(NOT CONFIG_CXX_RTTI)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
endif()
if(CONFIG_ARCH_TOOLCHAIN_CLANG)
set(CMAKE_EXE_LINKER_FLAGS_INIT "-c")
else()
set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs")
endif()
include(${TOOLCHAIN_FILE})

View File

@@ -18,80 +18,20 @@
#
# ##############################################################################
set(PLATFORM_FLAGS)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
if(CONFIG_ARCH_CORTEXM4)
list(APPEND PLATFORM_FLAGS -mtune=cortex-m4 -march=armv7e-m)
if(CONFIG_ARCH_FPU)
list(APPEND PLATFORM_FLAGS -mfpu=fpv4-sp-d16)
endif()
elseif(CONFIG_ARCH_CORTEXM7)
list(APPEND PLATFORM_FLAGS -mtune=cortex-m7 -march=armv7e-m)
if(CONFIG_ARCH_FPU)
if(CONFIG_ARCH_DPFPU)
list(APPEND PLATFORM_FLAGS -mfpu=fpv5-d16)
else()
list(APPEND PLATFORM_FLAGS -mfpu=fpv5-sp-d16)
endif()
endif()
else()
list(APPEND PLATFORM_FLAGS -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft)
set(CMAKE_C_COMPILER_FORCED TRUE)
set(CMAKE_CXX_COMPILER_FORCED TRUE)
set(TOOLCHAIN_ARCH_FILE)
if(CONFIG_ARCH_TOOLCHAIN_CLANG) # clang
set(TOOLCHAIN_ARCH_FILE armv7-m_clang)
elseif(CONFIG_ARCH_TOOLCHAIN_GHS) # greenhills
set(TOOLCHAIN_ARCH_FILE armv7-m_ghs)
else() # gcc
set(TOOLCHAIN_ARCH_FILE armv7-m_gcc)
endif()
if(CONFIG_ARCH_FPU)
if(CONFIG_ARM_FPU_ABI_SOFT)
list(APPEND PLATFORM_FLAGS -mfloat-abi=softfp)
else()
list(APPEND PLATFORM_FLAGS -mfloat-abi=hard)
endif()
else()
list(APPEND PLATFORM_FLAGS -mfloat-abi=soft)
endif()
# Clang Configuration files
if(CONFIG_ARCH_TOOLCHAIN_CLANG)
set(ARCHFLAGS)
if(CONFIG_ARCH_CORTEXM4)
if(CONFIG_ARCH_FPU)
string(APPEND ARCHFLAGS "--config armv7em_hard_fpv4_sp_d16.cfg")
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
elseif(CONFIG_ARCH_CORTEXM7)
if(CONFIG_ARCH_FPU)
string(APPEND ARCHFLAGS "--config armv7em_hard_fpv5.cfg")
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
if(NOT "${CMAKE_C_FLAGS}" STREQUAL "" AND NOT "${ARCHFLAGS}" STREQUAL "")
string(REGEX MATCH "${ARCHFLAGS}" EXISTS_FLAGS "${CMAKE_C_FLAGS}")
endif()
if(NOT EXISTS_FLAGS)
set(CMAKE_ASM_FLAGS
"${CMAKE_ASM_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
endif()
endif()
if(CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions -ffixed-r10)
endif()
if(CONFIG_ARCH_INSTRUMENT_ALL AND NOT CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions)
endif()
add_compile_options(${PLATFORM_FLAGS})
include(${TOOLCHAIN_ARCH_FILE})

View File

@@ -0,0 +1,95 @@
# ##############################################################################
# arch/arm/src/cmake/armv7-m_clang.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.
#
# ##############################################################################
set(PLATFORM_FLAGS)
if(CONFIG_ARCH_CORTEXM4)
list(APPEND PLATFORM_FLAGS -mtune=cortex-m4 -march=armv7e-m)
if(CONFIG_ARCH_FPU)
list(APPEND PLATFORM_FLAGS -mfpu=fpv4-sp-d16)
endif()
elseif(CONFIG_ARCH_CORTEXM7)
list(APPEND PLATFORM_FLAGS -mtune=cortex-m7 -march=armv7e-m)
if(CONFIG_ARCH_FPU)
if(CONFIG_ARCH_DPFPU)
list(APPEND PLATFORM_FLAGS -mfpu=fpv5-d16)
else()
list(APPEND PLATFORM_FLAGS -mfpu=fpv5-sp-d16)
endif()
endif()
else()
list(APPEND PLATFORM_FLAGS -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft)
endif()
if(CONFIG_ARCH_FPU)
if(CONFIG_ARM_FPU_ABI_SOFT)
list(APPEND PLATFORM_FLAGS -mfloat-abi=softfp)
else()
list(APPEND PLATFORM_FLAGS -mfloat-abi=hard)
endif()
else()
list(APPEND PLATFORM_FLAGS -mfloat-abi=soft)
endif()
# Clang Configuration files
set(ARCHFLAGS)
if(CONFIG_ARCH_CORTEXM4)
if(CONFIG_ARCH_FPU)
string(APPEND ARCHFLAGS "--config armv7em_hard_fpv4_sp_d16.cfg")
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
elseif(CONFIG_ARCH_CORTEXM7)
if(CONFIG_ARCH_FPU)
string(APPEND ARCHFLAGS "--config armv7em_hard_fpv5.cfg")
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
if(NOT "${CMAKE_C_FLAGS}" STREQUAL "" AND NOT "${ARCHFLAGS}" STREQUAL "")
string(REGEX MATCH "${ARCHFLAGS}" EXISTS_FLAGS "${CMAKE_C_FLAGS}")
endif()
if(NOT EXISTS_FLAGS)
set(CMAKE_ASM_FLAGS
"${CMAKE_ASM_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
endif()
if(CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions -ffixed-r10)
endif()
if(CONFIG_ARCH_INSTRUMENT_ALL AND NOT CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions)
endif()
add_compile_options(${PLATFORM_FLAGS})

View File

@@ -0,0 +1,97 @@
# ##############################################################################
# arch/arm/src/cmake/armv7-m_gcc.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.
#
# ##############################################################################
set(PLATFORM_FLAGS)
if(CONFIG_ARCH_CORTEXM4)
list(APPEND PLATFORM_FLAGS -mtune=cortex-m4 -march=armv7e-m)
if(CONFIG_ARCH_FPU)
list(APPEND PLATFORM_FLAGS -mfpu=fpv4-sp-d16)
endif()
elseif(CONFIG_ARCH_CORTEXM7)
list(APPEND PLATFORM_FLAGS -mtune=cortex-m7 -march=armv7e-m)
if(CONFIG_ARCH_FPU)
if(CONFIG_ARCH_DPFPU)
list(APPEND PLATFORM_FLAGS -mfpu=fpv5-d16)
else()
list(APPEND PLATFORM_FLAGS -mfpu=fpv5-sp-d16)
endif()
endif()
else()
list(APPEND PLATFORM_FLAGS -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft)
endif()
if(CONFIG_ARCH_FPU)
if(CONFIG_ARM_FPU_ABI_SOFT)
list(APPEND PLATFORM_FLAGS -mfloat-abi=softfp)
else()
list(APPEND PLATFORM_FLAGS -mfloat-abi=hard)
endif()
else()
list(APPEND PLATFORM_FLAGS -mfloat-abi=soft)
endif()
# Clang Configuration files
if(CONFIG_ARCH_TOOLCHAIN_CLANG)
set(ARCHFLAGS)
if(CONFIG_ARCH_CORTEXM4)
if(CONFIG_ARCH_FPU)
string(APPEND ARCHFLAGS "--config armv7em_hard_fpv4_sp_d16.cfg")
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
elseif(CONFIG_ARCH_CORTEXM7)
if(CONFIG_ARCH_FPU)
string(APPEND ARCHFLAGS "--config armv7em_hard_fpv5.cfg")
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
else()
string(APPEND ARCHFLAGS "--config armv7em_soft_nofp.cfg")
endif()
if(NOT "${CMAKE_C_FLAGS}" STREQUAL "" AND NOT "${ARCHFLAGS}" STREQUAL "")
string(REGEX MATCH "${ARCHFLAGS}" EXISTS_FLAGS "${CMAKE_C_FLAGS}")
endif()
if(NOT EXISTS_FLAGS)
set(CMAKE_ASM_FLAGS
"${CMAKE_ASM_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
set(CMAKE_C_FLAGS
"${CMAKE_C_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${ARCHFLAGS}"
CACHE STRING "" FORCE)
endif()
endif()
if(CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions -ffixed-r10)
endif()
if(CONFIG_ARCH_INSTRUMENT_ALL AND NOT CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions)
endif()
add_compile_options(${PLATFORM_FLAGS})

View File

@@ -0,0 +1,65 @@
# ##############################################################################
# arch/arm/src/cmake/armv7-m_ghs.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.
#
# ##############################################################################
set(PLATFORM_FLAGS)
if(CONFIG_ARCH_CORTEXM4)
list(APPEND PLATFORM_FLAGS -cpu=cortexm4)
if(CONFIG_ARCH_FPU)
if(CONFIG_ARCH_DPFPU)
list(APPEND PLATFORM_FLAGS -fpu=vfpv3)
else()
list(APPEND PLATFORM_FLAGS -fpu=vfpv3_d16)
endif()
endif()
elseif(CONFIG_ARCH_CORTEXM7)
list(APPEND PLATFORM_FLAGS -cpu=cortexm7)
if(CONFIG_ARCH_FPU)
if(CONFIG_ARCH_DPFPU)
list(APPEND PLATFORM_FLAGS -fpu=vfpv3)
else()
list(APPEND PLATFORM_FLAGS -fpu=vfpv3_d16)
endif()
endif()
else()
list(APPEND PLATFORM_FLAGS -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft)
endif()
if(CONFIG_ARCH_FPU)
if(CONFIG_ARM_FPU_ABI_SOFT)
list(APPEND PLATFORM_FLAGS -fsoft)
elseif(CONFIG_ARCH_DPFPU)
list(APPEND PLATFORM_FLAGS -fhard)
else()
list(APPEND PLATFORM_FLAGS -fsingle)
endif()
else()
list(APPEND PLATFORM_FLAGS -fsoft)
endif()
if(CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions -ffixed-r10)
endif()
if(CONFIG_ARCH_INSTRUMENT_ALL AND NOT CONFIG_ARMV7M_STACKCHECK)
list(APPEND PLATFORM_FLAGS -finstrument-functions)
endif()
add_compile_options(${PLATFORM_FLAGS})

View File

@@ -0,0 +1,236 @@
# ##############################################################################
# arch/arm/src/cmake/clang.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.
#
# ##############################################################################
# Toolchain
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_PREPROCESSOR clang -E -P -x c)
set(CMAKE_STRIP llvm-strip --strip-unneeded)
set(CMAKE_OBJCOPY llvm-objcopy)
set(CMAKE_OBJDUMP llvm-objdump)
set(CMAKE_LINKER ld.lld)
set(CMAKE_LD ld.lld)
set(CMAKE_AR llvm-ar)
set(CMAKE_NM llvm-nm)
set(CMAKE_RANLIB llvm-ranlib)
# Since the no_builtin attribute is not fully supported on Clang disable the
# built-in functions, refer: https://github.com/apache/incubator-nuttx/pull/5971
add_compile_options(-fno-builtin)
if(TOOLCHAIN_CLANG_CONFIG)
execute_process(COMMAND clang --version
OUTPUT_VARIABLE clang_full_version_string)
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANGVER
${clang_full_version_string})
if(CLANGVER STREQUAL "14.0")
set(TOOLCHAIN_CLANG_CONFIG ${TOOLCHAIN_CLANG_CONFIG}_nosys)
elseif(CLANGVER STREQUAL "17.0")
set(TOOLCHAIN_CLANG_OPTION -target)
add_compile_options(--target=arm-none-eabi)
else()
set(TOOLCHAIN_CLANG_OPTION --config)
endif()
add_compile_options(${TOOLCHAIN_CLANG_OPTION} ${TOOLCHAIN_CLANG_CONFIG}.cfg)
endif()
# override the ARCHIVE command
set(CMAKE_ARCHIVE_COMMAND "<CMAKE_AR> rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_RANLIB_COMMAND "<CMAKE_RANLIB> <TARGET>")
set(CMAKE_C_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_C_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_C_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_CXX_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_ASM_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(NO_LTO "-fno-lto")
if(CONFIG_ENDIAN_BIG)
add_compile_options(-mbig-endian)
endif()
add_compile_options(-fshort-enums)
# Architecture flags
add_link_options(-Wl,--entry=__start)
add_link_options(-nostdlib)
add_compile_options(-fno-common -Wall -Wshadow -Wundef -nostdlib)
if(CONFIG_DEBUG_CUSTOMOPT)
add_compile_options(${CONFIG_DEBUG_OPTLEVEL})
elseif(CONFIG_DEBUG_FULLOPT)
add_compile_options(-Oz)
endif()
if(NOT CONFIG_DEBUG_NOOPT)
add_compile_options(-fno-strict-aliasing)
endif()
if(CONFIG_FRAME_POINTER)
add_compile_options(-fno-omit-frame-pointer -fno-optimize-sibling-calls)
else()
add_compile_options(-fomit-frame-pointer)
endif()
if(CONFIG_STACK_CANARIES)
add_compile_options(-fstack-protector-all)
endif()
if(CONFIG_STACK_USAGE)
add_compile_options(-fstack-usage)
endif()
if(CONFIG_STACK_USAGE_WARNING AND NOT "${CONFIG_STACK_USAGE_WARNING}" STREQUAL
"0")
add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING})
endif()
if(CONFIG_SCHED_GCOV)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()
if(CONFIG_SCHED_GPROF_ALL)
add_compile_options(-pg)
endif()
if(CONFIG_MM_UBSAN_ALL)
add_compile_options(${CONFIG_MM_UBSAN_OPTION})
endif()
if(CONFIG_MM_UBSAN_TRAP_ON_ERROR)
add_compile_options(-fsanitize-undefined-trap-on-error)
endif()
if(CONFIG_MM_KASAN_ALL)
add_compile_options(-fsanitize=kernel-address)
endif()
if(CONFIG_MM_KASAN_GLOBAL)
add_compile_options(--param asan-globals=1)
endif()
if(CONFIG_MM_KASAN_DISABLE_READS_CHECK)
add_compile_options(--param asan-instrument-reads=0)
endif()
if(CONFIG_MM_KASAN_DISABLE_WRITES_CHECK)
add_compile_options(--param asan-instrument-writes=0)
endif()
# Instrumentation options
if(CONFIG_ARCH_INSTRUMENT_ALL)
add_compile_options(-finstrument-functions)
endif()
if(CONFIG_UNWINDER_ARM)
add_compile_options(-funwind-tables -fasynchronous-unwind-tables)
endif()
# Link Time Optimization
if(CONFIG_LTO_THIN)
add_compile_options(-flto=thin)
elseif(CONFIG_LTO_FULL)
add_compile_options(-flto)
elseif(CONFIG_LTO_FAT)
add_compile_options(-flto -ffat-lto-objects)
endif()
if(CONFIG_ARM_THUMB)
add_compile_options(-mthumb)
# GCC Manual: -mthumb ... If you want to force assembler files to be
# interpreted as Thumb code, either add a `.thumb' directive to the source or
# pass the -mthumb option directly to the assembler by prefixing it with -Wa.
add_compile_options(-Wa,-mthumb)
# Outputs an implicit IT block when there is a conditional instruction without
# an enclosing IT block.
add_compile_options(-Wa,-mimplicit-it=always)
endif()
# Optimization of unused sections
if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
add_link_options(-Wl,--gc-sections)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
# Debug --whole-archive
if(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE)
add_link_options(-Wl,--whole-archive)
endif()
# Debug link map
if(CONFIG_DEBUG_LINK_MAP)
add_link_options(-Wl,--cref -Wl,-Map=nuttx.map)
endif()
if(CONFIG_DEBUG_SYMBOLS)
add_compile_options(${CONFIG_DEBUG_SYMBOLS_LEVEL})
endif()
add_compile_options(
-Wno-attributes -Wno-unknown-pragmas
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
$<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
# When all C++ code is built using GCC 7.1 or a higher version, we can safely
# disregard warnings of the type "parameter passing for X changed in GCC 7.1."
# Refer to :
# https://stackoverflow.com/questions/48149323/what-does-the-gcc-warning-project-parameter-passing-for-x-changed-in-gcc-7-1-m
if(CONFIG_CXX_STANDARD)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=${CONFIG_CXX_STANDARD}>)
endif()
if(NOT CONFIG_CXX_EXCEPTION)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fcheck-new>)
endif()
if(NOT CONFIG_CXX_RTTI)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
endif()
set(CMAKE_EXE_LINKER_FLAGS_INIT "-c")
set(PREPROCESS ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P -x c)

View File

@@ -0,0 +1,262 @@
# ##############################################################################
# arch/arm/src/cmake/gcc.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.
#
# ##############################################################################
# Toolchain
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(TOOLCHAIN_PREFIX arm-none-eabi)
set(CMAKE_LIBRARY_ARCHITECTURE ${TOOLCHAIN_PREFIX})
set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN_PREFIX})
set(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN_PREFIX})
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_PREPROCESSOR ${TOOLCHAIN_PREFIX}-gcc -E -P -x c)
set(CMAKE_STRIP ${TOOLCHAIN_PREFIX}-strip --strip-unneeded)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy)
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump)
if(NOT CONFIG_LTO_NONE AND CONFIG_ARM_TOOLCHAIN_GNU_EABI)
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_LD ${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}-gcc-ar)
set(CMAKE_NM ${TOOLCHAIN_PREFIX}-gcc-nm)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-gcc-ranlib)
add_compile_options(-fno-builtin)
else()
set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}-ld)
set(CMAKE_LD ${TOOLCHAIN_PREFIX}-ld)
set(CMAKE_AR ${TOOLCHAIN_PREFIX}-ar)
set(CMAKE_NM ${TOOLCHAIN_PREFIX}-nm)
set(CMAKE_RANLIB ${TOOLCHAIN_PREFIX}-ranlib)
endif()
set(NO_LTO "-fno-lto")
if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.9)
# force color for gcc > 4.9
add_compile_options(-fdiagnostics-color=always)
endif()
# Workaround to skip -Warray-bounds check due to bug of GCC-12: Wrong warning
# array subscript [0] is outside array bounds:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
execute_process(COMMAND ${CMAKE_C_COMPILER} --version
OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
string(REGEX MATCH "\\+\\+.* ([0-9]+)\\.[0-9]+" GCC_VERSION_REGEX
"${GCC_VERSION_OUTPUT}")
set(GCCVER ${CMAKE_MATCH_1})
if(GCCVER EQUAL 12)
add_compile_options(--param=min-pagesize=0)
if(CONFIG_ARCH_RAMFUNCS)
add_link_options(-Wl,--no-warn-rwx-segments)
endif()
endif()
# override the ARCHIVE command
set(CMAKE_ARCHIVE_COMMAND "<CMAKE_AR> rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_RANLIB_COMMAND "<CMAKE_RANLIB> <TARGET>")
set(CMAKE_C_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_C_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_C_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_CXX_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_ASM_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
if(CONFIG_ENDIAN_BIG)
add_compile_options(-mbig-endian)
endif()
# Architecture flags
add_link_options(-Wl,--entry=__start)
add_link_options(-nostdlib)
add_compile_options(-fno-common -Wall -Wshadow -Wundef -nostdlib)
if(CONFIG_DEBUG_CUSTOMOPT)
add_compile_options(${CONFIG_DEBUG_OPTLEVEL})
elseif(CONFIG_DEBUG_FULLOPT)
add_compile_options(-Os)
endif()
if(NOT CONFIG_DEBUG_NOOPT)
add_compile_options(-fno-strict-aliasing)
endif()
if(CONFIG_FRAME_POINTER)
add_compile_options(-fno-omit-frame-pointer -fno-optimize-sibling-calls)
else()
add_compile_options(-fomit-frame-pointer)
endif()
if(CONFIG_STACK_CANARIES)
add_compile_options(-fstack-protector-all)
endif()
if(CONFIG_STACK_USAGE)
add_compile_options(-fstack-usage)
endif()
if(CONFIG_STACK_USAGE_WARNING AND NOT "${CONFIG_STACK_USAGE_WARNING}" STREQUAL
"0")
add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING})
endif()
if(CONFIG_SCHED_GCOV)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()
if(CONFIG_SCHED_GPROF_ALL)
add_compile_options(-pg)
endif()
if(CONFIG_MM_UBSAN_ALL)
add_compile_options(${CONFIG_MM_UBSAN_OPTION})
endif()
if(CONFIG_MM_UBSAN_TRAP_ON_ERROR)
add_compile_options(-fsanitize-undefined-trap-on-error)
endif()
if(CONFIG_MM_KASAN_ALL)
add_compile_options(-fsanitize=kernel-address)
endif()
if(CONFIG_MM_KASAN_GLOBAL)
add_compile_options(--param asan-globals=1)
endif()
if(CONFIG_MM_KASAN_DISABLE_READS_CHECK)
add_compile_options(--param asan-instrument-reads=0)
endif()
if(CONFIG_MM_KASAN_DISABLE_WRITES_CHECK)
add_compile_options(--param asan-instrument-writes=0)
endif()
# Instrumentation options
if(CONFIG_ARCH_INSTRUMENT_ALL)
add_compile_options(-finstrument-functions)
endif()
if(CONFIG_UNWINDER_ARM)
add_compile_options(-funwind-tables -fasynchronous-unwind-tables)
endif()
# Link Time Optimization
if(CONFIG_LTO_THIN)
add_compile_options(-flto=thin)
elseif(CONFIG_LTO_FULL)
add_compile_options(-flto)
add_compile_options(-fuse-linker-plugin)
elseif(CONFIG_LTO_FAT)
add_compile_options(-flto -ffat-lto-objects)
endif()
# The arm clang toolchain requires to pass the linker option will gcc tool chain
# can automatically perform lto at linking time if it found any object files are
# compiled with flto
if(NOT CONFIG_LTO_NONE)
# For gcc, use the linker plugin to extract objects with GIMPLE info from the
# lib archive
add_compile_options(-fuse-linker-plugin)
endif()
if(CONFIG_ARM_THUMB)
add_compile_options(-mthumb)
# GCC Manual: -mthumb ... If you want to force assembler files to be
# interpreted as Thumb code, either add a `.thumb' directive to the source or
# pass the -mthumb option directly to the assembler by prefixing it with -Wa.
add_compile_options(-Wa,-mthumb)
# Outputs an implicit IT block when there is a conditional instruction without
# an enclosing IT block.
add_compile_options(-Wa,-mimplicit-it=always)
endif()
# Optimization of unused sections
if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
add_link_options(-Wl,--gc-sections)
add_compile_options(-ffunction-sections -fdata-sections)
endif()
# Debug --whole-archive
if(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE)
add_link_options(-Wl,--whole-archive)
endif()
# Debug link map
if(CONFIG_DEBUG_LINK_MAP)
add_link_options(-Wl,--cref -Wl,-Map=nuttx.map)
endif()
if(CONFIG_DEBUG_SYMBOLS)
add_compile_options(${CONFIG_DEBUG_SYMBOLS_LEVEL})
endif()
add_compile_options(
-Wno-attributes -Wno-unknown-pragmas
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>
$<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
# When all C++ code is built using GCC 7.1 or a higher version, we can safely
# disregard warnings of the type "parameter passing for X changed in GCC 7.1."
# Refer to :
# https://stackoverflow.com/questions/48149323/what-does-the-gcc-warning-project-parameter-passing-for-x-changed-in-gcc-7-1-m
add_compile_options(-Wno-psabi)
if(CONFIG_CXX_STANDARD)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=${CONFIG_CXX_STANDARD}>)
endif()
if(NOT CONFIG_CXX_EXCEPTION)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fcheck-new>)
endif()
if(NOT CONFIG_CXX_RTTI)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
endif()
set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs")
set(PREPROCESS ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P -x c)

View File

@@ -0,0 +1,257 @@
# ##############################################################################
# arch/arm/src/cmake/ghs.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.
#
# ##############################################################################
# Toolchain
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_ASM_COMPILER ccarm)
set(CMAKE_C_COMPILER ccarm)
set(CMAKE_CXX_COMPILER ccarm)
set(CMAKE_STRIP gstrip)
set(CMAKE_OBJCOPY objcopy)
set(CMAKE_OBJDUMP gdump)
set(CMAKE_LINKER cxarm)
set(CMAKE_LD cxarm)
set(CMAKE_AR cxarm)
set(CMAKE_GMEMFILE gmemfile)
set(CMAKE_NM gnm)
set(CMAKE_RANLIB echo)
set(CMAKE_PREPROCESSOR ccarm -E -P)
# override the ARCHIVE command
set(CMAKE_ARCHIVE_COMMAND
"<CMAKE_AR> <LINK_FLAGS> -archive <OBJECTS> -o <TARGET>")
set(CMAKE_C_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_CREATE ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_C_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_CXX_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(CMAKE_ASM_ARCHIVE_APPEND ${CMAKE_ARCHIVE_COMMAND})
set(NO_LTO "-Onolink")
if(CONFIG_ENDIAN_BIG)
add_compile_options(-mbig-endian)
endif()
# Architecture flags
add_link_options(-entry=__start)
add_compile_options(--no_commons -Wall -Wshadow -Wundef -nostdlib)
if(CONFIG_DEBUG_CUSTOMOPT)
add_compile_options(${CONFIG_DEBUG_OPTLEVEL})
elseif(CONFIG_DEBUG_FULLOPT)
add_compile_options(-Osize)
endif()
if(NOT CONFIG_DEBUG_NOOPT)
add_compile_options(-fno-strict-aliasing)
endif()
if(CONFIG_FRAME_POINTER)
add_compile_options(-fno-omit-frame-pointer -fno-optimize-sibling-calls)
else()
add_compile_options(-noga)
endif()
if(CONFIG_STACK_CANARIES)
add_compile_options(-fstack-protector-all)
endif()
if(CONFIG_STACK_USAGE)
add_compile_options(-fstack-usage)
endif()
if(CONFIG_STACK_USAGE_WARNING AND NOT "${CONFIG_STACK_USAGE_WARNING}" STREQUAL
"0")
add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING})
endif()
if(CONFIG_SCHED_GCOV)
add_compile_options(-fprofile-generate -ftest-coverage)
endif()
if(CONFIG_SCHED_GPROF_ALL)
add_compile_options(-pg)
endif()
if(CONFIG_MM_UBSAN_ALL)
add_compile_options(${CONFIG_MM_UBSAN_OPTION})
endif()
if(CONFIG_MM_UBSAN_TRAP_ON_ERROR)
add_compile_options(-fsanitize-undefined-trap-on-error)
endif()
if(CONFIG_MM_KASAN_ALL)
add_compile_options(-fsanitize=kernel-address)
endif()
if(CONFIG_MM_KASAN_GLOBAL)
add_compile_options(--param asan-globals=1)
endif()
if(CONFIG_MM_KASAN_DISABLE_READS_CHECK)
add_compile_options(--param asan-instrument-reads=0)
endif()
if(CONFIG_MM_KASAN_DISABLE_WRITES_CHECK)
add_compile_options(--param asan-instrument-writes=0)
endif()
# Instrumentation options
if(CONFIG_ARCH_INSTRUMENT_ALL)
add_compile_options(-finstrument-functions)
endif()
if(CONFIG_UNWINDER_ARM)
add_compile_options(-funwind-tables -fasynchronous-unwind-tables)
endif()
# Link Time Optimization
if(CONFIG_LTO_THIN)
add_compile_options(-Olink -Ogeneral)
elseif(CONFIG_LTO_FULL)
add_compile_options(-Olink -Osize)
elseif(CONFIG_LTO_FAT)
add_compile_options(-Olink -Ospeed)
endif()
if(CONFIG_ARM_THUMB)
add_compile_options(-thumb)
endif()
# Debug --whole-archive
if(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE)
add_link_options(-Wl,--whole-archive)
endif()
# Debug link map
if(CONFIG_DEBUG_LINK_MAP)
add_link_options(-map=nuttx.map)
endif()
if(CONFIG_DEBUG_SYMBOLS)
add_compile_options(-G -gdwarf-2)
endif()
add_compile_options(
$<$<COMPILE_LANGUAGE:ASM>:-preprocess_assembly_files>
$<$<COMPILE_LANGUAGE:ASM>:--gnu_asm>
$<$<COMPILE_LANGUAGE:C>:-gcc>
$<$<COMPILE_LANGUAGE:C>:-gnu99>
$<$<COMPILE_LANGUAGE:C>:-preprocess_assembly_files>
$<$<COMPILE_LANGUAGE:C>:--diag_suppress=68,111,174,222,236,257,826,1143,1721>
$<$<COMPILE_LANGUAGE:CXX>:--gnu_asm>
$<$<COMPILE_LANGUAGE:CXX>:--diag_suppress=826>)
if(CONFIG_CXX_STANDARD)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-std=${CONFIG_CXX_STANDARD}>)
endif()
if(NOT CONFIG_CXX_EXCEPTION)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fcheck-new>)
endif()
if(CONFIG_CXX_STANDARD)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:--${CONFIG_CXX_STANDARD}>)
endif()
if(NOT CONFIG_CXX_EXCEPTION)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:--no_exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-check=alloc>)
endif()
if(NOT CONFIG_CXX_RTTI)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>)
endif()
set(PREPROCESS ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P)
# override nuttx_generate_preproces_target
set(NUTTX_TOOLCHAIN_PREPROCES_DEFINED true)
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 -filetype.cpp
${SOURCE_FILE} -o ${TARGET_FILE}
DEPENDS ${SOURCE_FILE} ${DEPENDS})
endfunction()
# override nuttx_find_toolchain_lib
set(NUTTX_FIND_TOOLCHAIN_LIB_DEFINED true)
function(nuttx_find_toolchain_lib)
execute_process(
COMMAND bash -c "which ${CMAKE_C_COMPILER} | awk -F '/[^/]*$' '{print $1}'"
OUTPUT_VARIABLE GHS_ROOT_PATH)
string(STRIP "${GHS_ROOT_PATH}" GHS_ROOT_PATH)
if(NOT ARGN)
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libarch.a)
if(CONFIG_ARCH_FPU)
if(CONFIG_ARM_FPU_ABI_SOFT)
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libind_sf.a)
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libmath_sf.a)
elseif(CONFIG_ARCH_DPFPU)
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libind_fp.a)
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libmath_fp.a)
else()
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libind_sd.a)
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libmath_sd.a)
endif()
else()
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libind_sf.a)
nuttx_add_extra_library(${GHS_ROOT_PATH}/lib/thumb2/libmath_sf.a)
endif()
endif()
endfunction()
# disable nuttx cmake link group otption
set(DISABLE_LINK_GROUP true)

View File

@@ -73,50 +73,16 @@ endforeach()
separate_arguments(CMAKE_C_FLAG_ARGS NATIVE_COMMAND ${CMAKE_C_FLAGS})
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-libgcc-file-name
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE extra_library)
if(NOT EXISTS ${extra_library} AND CONFIG_ARCH_TOOLCHAIN_CLANG)
get_filename_component(COMPILER_RT_LIB ${extra_library} NAME)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name ${COMPILER_RT_LIB}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE extra_library)
endif()
list(APPEND EXTRA_LIB ${extra_library})
nuttx_find_toolchain_lib()
if(NOT CONFIG_LIBM)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name=libm.a
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE extra_library)
list(APPEND EXTRA_LIB ${extra_library})
nuttx_find_toolchain_lib(libm.a)
endif()
if(CONFIG_LIBSUPCXX)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name=libsupc++.a
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE extra_library)
list(APPEND EXTRA_LIB ${extra_library})
nuttx_find_toolchain_lib(libsupc++.a)
endif()
if(CONFIG_ARCH_COVERAGE)
execute_process(
COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} ${NUTTX_EXTRA_FLAGS}
--print-file-name=libgcov.a
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE extra_library)
list(APPEND EXTRA_LIB ${extra_library})
if(CONFIG_SCHED_GCOV)
nuttx_find_toolchain_lib(libgcov.a)
endif()
nuttx_add_extra_library(${EXTRA_LIB})
set(PREPROCESS ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P -x c)

View File

@@ -67,6 +67,8 @@ set(CMAKE_C_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_CXX_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_ASM_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(NO_LTO "-fno-lto")
if(CONFIG_ARCH_ARMV8A)
add_compile_options(-march=armv8-a)
endif()

View File

@@ -107,6 +107,8 @@ elseif(CONFIG_LTO_FULL)
endif()
endif()
set(NO_LTO "-fno-lto")
# override the ARCHIVE command
set(CMAKE_ARCHIVE_COMMAND "<CMAKE_AR> rcs <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_RANLIB_COMMAND "<CMAKE_RANLIB> <TARGET>")

View File

@@ -29,6 +29,8 @@ endif()
add_compile_options(-fno-common)
set(NO_LTO "-fno-lto")
if(CONFIG_DEBUG_SYMBOLS)
add_compile_options(${CONFIG_DEBUG_SYMBOLS_LEVEL})
endif()

View File

@@ -17,3 +17,5 @@
# the License.
#
# ##############################################################################
set(PREPROCESS ${CMAKE_C_COMPILER} ${CMAKE_C_FLAG_ARGS} -E -P -x c)

View File

@@ -40,6 +40,8 @@ set(CMAKE_C_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_CXX_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(CMAKE_ASM_ARCHIVE_FINISH ${CMAKE_RANLIB_COMMAND})
set(NO_LTO "-fno-lto")
if(CONFIG_DEBUG_CUSTOMOPT)
add_compile_options(${CONFIG_DEBUG_OPTLEVEL})
elseif(CONFIG_DEBUG_FULLOPT)

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()

View File

@@ -22,8 +22,8 @@ set(SRCS lib_assert.c lib_stackchk.c)
if(CONFIG_ARCH_TOOLCHAIN_GNU AND NOT CONFIG_LTO_NONE)
set_source_files_properties(lib_assert.c DIRECTORY .. PROPERTIES COMPILE_FLAGS
-fno-lto)
${NO_LTO})
set_source_files_properties(lib_stackchk.c DIRECTORY ..
PROPERTIES COMPILE_FLAGS -fno-lto)
PROPERTIES COMPILE_FLAGS ${NO_LTO})
endif()
target_sources(c PRIVATE ${SRCS})