mirror of
https://github.com/apache/nuttx.git
synced 2026-05-21 13:13:08 +08:00
arm64/cmake: support clang compile
enable CONFIG_ARM64_TOOLCHAIN_CLANG can use clang compiler Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
This commit is contained in:
committed by
Xiang Xiao
parent
86762145de
commit
3314201f64
@@ -25,52 +25,6 @@ set(CMAKE_SYSTEM_VERSION 1)
|
||||
set(CMAKE_C_COMPILER_FORCED TRUE)
|
||||
set(CMAKE_CXX_COMPILER_FORCED TRUE)
|
||||
|
||||
# Default toolchain
|
||||
set(TOOLCHAIN_PREFIX aarch64-none-elf)
|
||||
|
||||
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_STRIP ${TOOLCHAIN_PREFIX}-strip --strl dunneeded)
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy)
|
||||
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump)
|
||||
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}-gcc-ranlib)
|
||||
if(CONFIG_LTO_FULL)
|
||||
add_compile_options(-flto)
|
||||
if(CONFIG_ARM64_TOOLCHAIN_GNU_EABI)
|
||||
set(CMAKE_LD ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_AR ${TOOLCHAIN_PREFIX}-gcc-ar)
|
||||
set(CMAKE_NM ${TOOLCHAIN_PREFIX}-gcc-nm)
|
||||
add_compile_options(-fuse-linker-plugin)
|
||||
add_compile_options(-fno-builtin)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_link_options(--entry=__start)
|
||||
# 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_ARCH_ARMV8A)
|
||||
add_compile_options(-march=armv8-a)
|
||||
elseif(CONFIG_ARCH_ARMV8R)
|
||||
@@ -89,155 +43,10 @@ elseif(CONFIG_ARCH_CORTEX_R82)
|
||||
add_compile_options(-mcpu=cortex-r82)
|
||||
endif()
|
||||
|
||||
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)
|
||||
add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING})
|
||||
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_INSTRUMENT_ALL)
|
||||
add_compile_options(-fsanitize=kernel-address)
|
||||
set(KASAN_PARAM "")
|
||||
list(APPEND KASAN_PARAM "asan-stack=0")
|
||||
list(APPEND KASAN_PARAM "asan-instrumentation-with-call-threshold=0")
|
||||
|
||||
if(CONFIG_MM_KASAN_GLOBAL)
|
||||
list(APPEND KASAN_PARAM "asan-globals=1")
|
||||
else()
|
||||
list(APPEND KASAN_PARAM "asan-globals=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_MM_KASAN_DISABLE_READS_CHECK)
|
||||
list(APPEND KASAN_PARAM "asan-instrument-reads=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_MM_KASAN_DISABLE_WRITES_CHECK)
|
||||
list(APPEND KASAN_PARAM "asan-instrument-writes=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARM_TOOLCHAIN_CLANG)
|
||||
foreach(param IN LISTS KASAN_PARAM)
|
||||
add_compile_options("-mllvm=${param}")
|
||||
endforeach()
|
||||
else()
|
||||
foreach(param IN LISTS KASAN_PARAM)
|
||||
add_compile_options("--param=${param}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_INSTRUMENT_ALL)
|
||||
add_compile_options(-finstrument-functions)
|
||||
endif()
|
||||
|
||||
if(CONFIG_COVERAGE_ALL)
|
||||
if(CONFIG_ARCH_TOOLCHAIN_GCC)
|
||||
add_compile_options(-fprofile-arcs -ftest-coverage -fno-inline)
|
||||
elseif(CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CONFIG_PROFILE_ALL)
|
||||
add_compile_options(-pg)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_FPU)
|
||||
add_compile_options(-D_LDBL_EQ_DBL)
|
||||
endif()
|
||||
|
||||
add_compile_options(
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wshadow
|
||||
-Wundef
|
||||
-Wno-attributes
|
||||
-Wno-unknown-pragmas
|
||||
$<$<COMPILE_LANGUAGE:C>:-Werror>
|
||||
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>)
|
||||
|
||||
if(NOT CONFIG_LIBCXXTOOLCHAIN)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
add_compile_options(-Wno-psabi)
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
add_link_options(-nostdlib)
|
||||
|
||||
if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
|
||||
add_link_options(-Wl,--gc-sections)
|
||||
add_compile_options(-ffunction-sections -fdata-sections)
|
||||
endif()
|
||||
|
||||
if(CONFIG_DEBUG_LINK_MAP)
|
||||
add_link_options(-Wl,-cref,-Map=nuttx.map)
|
||||
endif()
|
||||
|
||||
if(CONFIG_DEBUG_SYMBOLS)
|
||||
add_compile_options(${CONFIG_DEBUG_SYMBOLS_LEVEL})
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_ARCH_USE_MMU)
|
||||
add_compile_options(-fno-builtin)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_TOOLCHAIN_GNU AND NOT CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
if(NOT GCCVER)
|
||||
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})
|
||||
endif()
|
||||
if(GCCVER GREATER_EQUAL 12)
|
||||
add_link_options(-Wl,--print-memory-usage)
|
||||
add_link_options(-Wl,--no-warn-rwx-segments)
|
||||
endif()
|
||||
|
||||
# include the toolchain specific cmake file
|
||||
|
||||
if(CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
include(clang)
|
||||
elseif(CONFIG_ARCH_TOOLCHAIN_GCC) # gcc
|
||||
include(gcc)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
# ##############################################################################
|
||||
# arch/arm64/src/cmake/clang.cmake
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# 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(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)
|
||||
|
||||
add_link_options(-Wl,--entry=__start)
|
||||
add_link_options(-nostdlib)
|
||||
|
||||
set(NO_LTO "-fno-lto")
|
||||
|
||||
add_compile_options(--target=aarch64-none-elf)
|
||||
|
||||
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)
|
||||
add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING})
|
||||
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_INSTRUMENT_ALL)
|
||||
add_compile_options(-fsanitize=kernel-address)
|
||||
set(KASAN_PARAM "")
|
||||
list(APPEND KASAN_PARAM "asan-stack=0")
|
||||
list(APPEND KASAN_PARAM "asan-instrumentation-with-call-threshold=0")
|
||||
|
||||
if(CONFIG_MM_KASAN_GLOBAL)
|
||||
list(APPEND KASAN_PARAM "asan-globals=1")
|
||||
else()
|
||||
list(APPEND KASAN_PARAM "asan-globals=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_MM_KASAN_DISABLE_READS_CHECK)
|
||||
list(APPEND KASAN_PARAM "asan-instrument-reads=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_MM_KASAN_DISABLE_WRITES_CHECK)
|
||||
list(APPEND KASAN_PARAM "asan-instrument-writes=0")
|
||||
endif()
|
||||
|
||||
foreach(param IN LISTS KASAN_PARAM)
|
||||
add_compile_options("-mllvm=${param}")
|
||||
endforeach()
|
||||
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_INSTRUMENT_ALL)
|
||||
add_compile_options(-finstrument-functions)
|
||||
endif()
|
||||
|
||||
if(CONFIG_COVERAGE_ALL)
|
||||
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
||||
endif()
|
||||
|
||||
if(CONFIG_PROFILE_ALL)
|
||||
add_compile_options(-pg)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_FPU)
|
||||
add_compile_options(-D_LDBL_EQ_DBL)
|
||||
endif()
|
||||
|
||||
add_compile_options(
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wshadow
|
||||
-Wundef
|
||||
-Wno-attributes
|
||||
-Wno-unknown-pragmas
|
||||
$<$<COMPILE_LANGUAGE:C>:-Werror>
|
||||
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>)
|
||||
|
||||
if(NOT CONFIG_LIBCXXTOOLCHAIN)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
add_compile_options(-Wno-psabi)
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
add_link_options(-nostdlib)
|
||||
|
||||
if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
|
||||
add_link_options(-Wl,--gc-sections)
|
||||
add_compile_options(-ffunction-sections -fdata-sections)
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
if(NOT CONFIG_ARCH_USE_MMU)
|
||||
add_compile_options(-fno-builtin)
|
||||
endif()
|
||||
|
||||
add_link_options(-no-pie)
|
||||
@@ -0,0 +1,220 @@
|
||||
# ##############################################################################
|
||||
# arch/arm64/src/cmake/gcc.cmake
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# ##############################################################################
|
||||
|
||||
# Default toolchain
|
||||
set(TOOLCHAIN_PREFIX aarch64-none-elf)
|
||||
|
||||
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_STRIP ${TOOLCHAIN_PREFIX}-strip --strl dunneeded)
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}-objcopy)
|
||||
set(CMAKE_OBJDUMP ${TOOLCHAIN_PREFIX}-objdump)
|
||||
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}-gcc-ranlib)
|
||||
if(CONFIG_LTO_FULL)
|
||||
add_compile_options(-flto)
|
||||
if(CONFIG_ARM64_TOOLCHAIN_GNU_EABI)
|
||||
set(CMAKE_LD ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_AR ${TOOLCHAIN_PREFIX}-gcc-ar)
|
||||
set(CMAKE_NM ${TOOLCHAIN_PREFIX}-gcc-nm)
|
||||
add_compile_options(-fuse-linker-plugin)
|
||||
add_compile_options(-fno-builtin)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_link_options(--entry=__start)
|
||||
# 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_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)
|
||||
add_compile_options(-Wstack-usage=${CONFIG_STACK_USAGE_WARNING})
|
||||
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_INSTRUMENT_ALL)
|
||||
add_compile_options(-fsanitize=kernel-address)
|
||||
set(KASAN_PARAM "")
|
||||
list(APPEND KASAN_PARAM "asan-stack=0")
|
||||
list(APPEND KASAN_PARAM "asan-instrumentation-with-call-threshold=0")
|
||||
|
||||
if(CONFIG_MM_KASAN_GLOBAL)
|
||||
list(APPEND KASAN_PARAM "asan-globals=1")
|
||||
else()
|
||||
list(APPEND KASAN_PARAM "asan-globals=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_MM_KASAN_DISABLE_READS_CHECK)
|
||||
list(APPEND KASAN_PARAM "asan-instrument-reads=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_MM_KASAN_DISABLE_WRITES_CHECK)
|
||||
list(APPEND KASAN_PARAM "asan-instrument-writes=0")
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARM_TOOLCHAIN_CLANG)
|
||||
foreach(param IN LISTS KASAN_PARAM)
|
||||
add_compile_options("-mllvm=${param}")
|
||||
endforeach()
|
||||
else()
|
||||
foreach(param IN LISTS KASAN_PARAM)
|
||||
add_compile_options("--param=${param}")
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_INSTRUMENT_ALL)
|
||||
add_compile_options(-finstrument-functions)
|
||||
endif()
|
||||
|
||||
if(CONFIG_COVERAGE_ALL)
|
||||
if(CONFIG_ARCH_TOOLCHAIN_GCC)
|
||||
add_compile_options(-fprofile-arcs -ftest-coverage -fno-inline)
|
||||
elseif(CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
add_compile_options(-fprofile-instr-generate -fcoverage-mapping)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CONFIG_PROFILE_ALL)
|
||||
add_compile_options(-pg)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_FPU)
|
||||
add_compile_options(-D_LDBL_EQ_DBL)
|
||||
endif()
|
||||
|
||||
add_compile_options(
|
||||
-fno-common
|
||||
-Wall
|
||||
-Wshadow
|
||||
-Wundef
|
||||
-Wno-attributes
|
||||
-Wno-unknown-pragmas
|
||||
$<$<COMPILE_LANGUAGE:C>:-Werror>
|
||||
$<$<COMPILE_LANGUAGE:C>:-Wstrict-prototypes>)
|
||||
|
||||
if(NOT CONFIG_LIBCXXTOOLCHAIN)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-nostdinc++>)
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
add_compile_options(-Wno-psabi)
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
add_link_options(-nostdlib)
|
||||
|
||||
if(CONFIG_DEBUG_OPT_UNUSED_SECTIONS)
|
||||
add_link_options(-Wl,--gc-sections)
|
||||
add_compile_options(-ffunction-sections -fdata-sections)
|
||||
endif()
|
||||
|
||||
if(CONFIG_DEBUG_LINK_MAP)
|
||||
add_link_options(-Wl,-cref,-Map=nuttx.map)
|
||||
endif()
|
||||
|
||||
if(CONFIG_DEBUG_SYMBOLS)
|
||||
add_compile_options(${CONFIG_DEBUG_SYMBOLS_LEVEL})
|
||||
endif()
|
||||
|
||||
if(NOT CONFIG_ARCH_USE_MMU)
|
||||
add_compile_options(-fno-builtin)
|
||||
endif()
|
||||
|
||||
if(CONFIG_ARCH_TOOLCHAIN_GNU AND NOT CONFIG_ARCH_TOOLCHAIN_CLANG)
|
||||
if(NOT GCCVER)
|
||||
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})
|
||||
endif()
|
||||
if(GCCVER GREATER_EQUAL 12)
|
||||
add_link_options(-Wl,--print-memory-usage)
|
||||
add_link_options(-Wl,--no-warn-rwx-segments)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
@@ -22,20 +22,18 @@
|
||||
get_directory_property(TOOLCHAIN_DIR_FLAGS DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMPILE_OPTIONS)
|
||||
|
||||
set(NUTTX_EXTRA_FLAGS "")
|
||||
set(CMAKE_C_FLAG_ARGS)
|
||||
foreach(FLAG ${TOOLCHAIN_DIR_FLAGS})
|
||||
if(NOT FLAG MATCHES "^\\$<.*>$")
|
||||
list(APPEND NUTTX_EXTRA_FLAGS ${FLAG})
|
||||
list(APPEND CMAKE_C_FLAG_ARGS ${FLAG})
|
||||
else()
|
||||
string(REGEX MATCH "\\$<\\$<COMPILE_LANGUAGE:C>:(.*)>" matched ${FLAG})
|
||||
if(matched)
|
||||
list(APPEND NUTTX_EXTRA_FLAGS ${CMAKE_MATCH_1})
|
||||
list(APPEND CMAKE_C_FLAG_ARGS ${CMAKE_MATCH_1})
|
||||
endif()
|
||||
endif()
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user