mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 06:18:40 +08:00
cmake:enhance compile options for custom toolchain,implement the REVERSE
opt of `add_compile_options()` add global moudle `nuttx_remove_compile_options()`. define custom board toolchain introduction. Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
parent
e01d6b26cc
commit
8efe6cb235
2 changed files with 77 additions and 0 deletions
|
@ -365,6 +365,7 @@ include(nuttx_add_symtab)
|
||||||
include(nuttx_add_module)
|
include(nuttx_add_module)
|
||||||
include(nuttx_add_dependencies)
|
include(nuttx_add_dependencies)
|
||||||
include(nuttx_export_header)
|
include(nuttx_export_header)
|
||||||
|
include(nuttx_remove_compile_options)
|
||||||
include(nuttx_source_file_properties)
|
include(nuttx_source_file_properties)
|
||||||
include(menuconfig)
|
include(menuconfig)
|
||||||
|
|
||||||
|
@ -405,6 +406,15 @@ endif()
|
||||||
# Setup platform options (this needs to happen after project(), once the
|
# Setup platform options (this needs to happen after project(), once the
|
||||||
# toolchain file has been processed)
|
# toolchain file has been processed)
|
||||||
|
|
||||||
|
# Support custom Toolchain options by custom Boards
|
||||||
|
if(CONFIG_ARCH_BOARD_CUSTOM)
|
||||||
|
if(EXISTS ${NUTTX_BOARD_ABS_DIR}/cmake
|
||||||
|
AND EXISTS ${NUTTX_BOARD_ABS_DIR}/cmake/Toolchain.cmake)
|
||||||
|
# must be added AFTER ToolchainFile and BEFORE platform
|
||||||
|
include(${NUTTX_BOARD_ABS_DIR}/cmake/Toolchain.cmake)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
include(platform)
|
include(platform)
|
||||||
|
|
||||||
# Setup main nuttx target ####################################################
|
# Setup main nuttx target ####################################################
|
||||||
|
|
67
cmake/nuttx_remove_compile_options.cmake
Normal file
67
cmake/nuttx_remove_compile_options.cmake
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
# ##############################################################################
|
||||||
|
# cmake/nuttx_remove_compile_options.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.
|
||||||
|
#
|
||||||
|
# ##############################################################################
|
||||||
|
|
||||||
|
# ~~~
|
||||||
|
# nuttx_remove_compile_options
|
||||||
|
#
|
||||||
|
# Description:
|
||||||
|
# Customize to remove certain options
|
||||||
|
# in the default Arch ToolchainFile.
|
||||||
|
#
|
||||||
|
# For example, a customized chip board uses a customized tool chain, which has compilation configuration conflicts with default.
|
||||||
|
# You can use this macro to remove it in the global compile options.
|
||||||
|
# This function is similar to the reverse operation of `add_compile_options()`
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# nuttx_remove_compile_options(ARGNS)
|
||||||
|
#
|
||||||
|
# Parameters:
|
||||||
|
# ARGNS : options regex that needs to be deleted
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
# nuttx_remove_compile_options(-march -mabi)
|
||||||
|
#
|
||||||
|
# befor: CFLAGS = -O2 -g -march=rv32if -mabi=ilp32f -mcpu=e907fp
|
||||||
|
# after: CFLAGS = -O2 -g -mcpu=e907fp
|
||||||
|
#
|
||||||
|
# ~~~
|
||||||
|
|
||||||
|
function(nuttx_remove_compile_options)
|
||||||
|
get_property(
|
||||||
|
CURRENT_OPTIONS
|
||||||
|
DIRECTORY
|
||||||
|
PROPERTY COMPILE_OPTIONS)
|
||||||
|
|
||||||
|
set_property(DIRECTORY PROPERTY COMPILE_OPTIONS)
|
||||||
|
|
||||||
|
# Remove flags starting with regex
|
||||||
|
foreach(CURRENT_OPTION_VARIABLE ${CURRENT_OPTIONS})
|
||||||
|
set(MATCHED_FLAG)
|
||||||
|
foreach(regex ${ARGN})
|
||||||
|
string(REGEX MATCH "^${regex}" MATCHED ${CURRENT_OPTION_VARIABLE})
|
||||||
|
if(MATCHED)
|
||||||
|
string(CONCAT MATCHED_FLAG ${MATCHED_FLAG}${MATCHED})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
if(NOT MATCHED_FLAG)
|
||||||
|
add_compile_options(${CURRENT_OPTION_VARIABLE})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
Loading…
Reference in a new issue