mirror of https://github.com/ARMmbed/mbed-os.git
Write defines into a disk file instead of passing 100s of them on the command line directly. Fixes some issues with build commands on my machine, and makes it a lot easier to view the make VERBOSE=1 output.
parent
8080220a40
commit
6a99a89c26
|
|
@ -93,8 +93,6 @@ if(${CMAKE_CROSSCOMPILING})
|
|||
target_compile_definitions(mbed-core
|
||||
INTERFACE
|
||||
TARGET_NAME=${MBED_TARGET}
|
||||
${MBED_TARGET_DEFINITIONS}
|
||||
${MBED_CONFIG_DEFINITIONS}
|
||||
)
|
||||
|
||||
# Add MBED_TEST_MODE for backward compatibility with Greentea tests written for use with Mbed CLI 1
|
||||
|
|
@ -138,6 +136,10 @@ if(${CMAKE_CROSSCOMPILING})
|
|||
endif()
|
||||
endif()
|
||||
|
||||
# Generate target config header and include it in all files
|
||||
mbed_write_target_config_header(${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h MBED_TARGET_DEFINITIONS MBED_CONFIG_DEFINITIONS)
|
||||
target_compile_options(mbed-core INTERFACE -include ${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h)
|
||||
|
||||
# Include mbed.h and config from generate folder
|
||||
target_include_directories(mbed-core
|
||||
INTERFACE
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ endif()
|
|||
|
||||
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
|
||||
include(mbed_set_post_build)
|
||||
include(mbed_generate_config_header)
|
||||
|
||||
# Load toolchain file
|
||||
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2022 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Function to write all Mbed target defines into a header. This makes the build run more smoothly
|
||||
# by removing the need to pass 100s of #define flags on the command line, which makes debugging difficult
|
||||
# and can cause issues with command line length limits besides.
|
||||
function(mbed_write_target_config_header HEADER_PATH) # ARGN: Lists of defines to add to the file.
|
||||
|
||||
set(TARGET_HEADER_CONTENTS
|
||||
" /*
|
||||
Mbed OS Target Define Header.
|
||||
This contains all of the #defines specific to your target and device.
|
||||
It is prepended to every source file using the -include compiler option.
|
||||
AUTOGENERATED by cmake. DO NOT EDIT!
|
||||
*/
|
||||
")
|
||||
|
||||
foreach(DEFINE_LIST ${ARGN})
|
||||
string(APPEND TARGET_HEADER_CONTENTS "\n // Defines from ${DEFINE_LIST}:\n")
|
||||
|
||||
foreach(DEFINE_COMMAND ${${DEFINE_LIST}}) # double dereference needed to get contents of list
|
||||
|
||||
# convert defines in command-line format (VAR=value) to header format (#define VAR value)
|
||||
if("${DEFINE_COMMAND}" MATCHES "^([^=]+)=(.*)$")
|
||||
string(APPEND TARGET_HEADER_CONTENTS "#define ${CMAKE_MATCH_1} ${CMAKE_MATCH_2}\n")
|
||||
else()
|
||||
# no value given, so follow GCC command line semantics and define it to 1
|
||||
string(APPEND TARGET_HEADER_CONTENTS "#define ${DEFINE_COMMAND} 1\n")
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
# Write the file, using file(GENERATE) so that the timestamp is not updated if the contents don't change
|
||||
file(GENERATE OUTPUT ${HEADER_PATH} CONTENT ${TARGET_HEADER_CONTENTS})
|
||||
|
||||
endfunction(mbed_write_target_config_header)
|
||||
Loading…
Reference in New Issue