CMake: Do not hard code target in toolchain CMake module

Provide a function in each toolchain module to set the toolchain
specific options. All the functions have the same interface
therefore the CMake source file including the module always calls
the same function regardless of which toolchain module is actually
included.
When the `mbed-os` target is broken up into multiple libraries, a
library other than `mbed-os` might need to set the toolchain options.
This will be possible by simply including the module and calling the
function with the target for which to set the options.
pull/13566/head
Hugues Kamba 2020-08-04 19:34:31 +01:00
parent c8b4822ed7
commit cb9960cb08
3 changed files with 89 additions and 79 deletions

View File

@ -19,6 +19,7 @@ include(${MBED_ROOT}/cmake/core.cmake)
mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN}) mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN})
include(${MBED_ROOT}/cmake/toolchain.cmake) include(${MBED_ROOT}/cmake/toolchain.cmake)
mbed_set_toolchain_options(mbed-os)
include(${MBED_ROOT}/cmake/profile.cmake) include(${MBED_ROOT}/cmake/profile.cmake)

View File

@ -13,6 +13,10 @@ if(MBEDIDE)
set_property(GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER "--ide=mbed") set_property(GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER "--ide=mbed")
endif() endif()
# Sets toolchain options
function(mbed_set_toolchain_options target)
get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER)
list(APPEND common_options list(APPEND common_options
"${mbed_studio_arm_compiler}" "${mbed_studio_arm_compiler}"
"-c" "-c"
@ -28,12 +32,12 @@ list(APPEND common_options
"-fshort-wchar" "-fshort-wchar"
) )
target_compile_options(mbed-os target_compile_options(${target}
PUBLIC PUBLIC
$<$<COMPILE_LANGUAGE:C>:${common_options}> $<$<COMPILE_LANGUAGE:C>:${common_options}>
) )
target_compile_options(mbed-os target_compile_options(${target}
PUBLIC PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:${common_options}> $<$<COMPILE_LANGUAGE:CXX>:${common_options}>
) )
@ -41,19 +45,20 @@ target_compile_options(mbed-os
set(asm_preproc_options set(asm_preproc_options
"--target=arm-arm-none-eabi,-D,MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED" "--target=arm-arm-none-eabi,-D,MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED"
) )
target_compile_options(mbed-os target_compile_options(${target}
PUBLIC PUBLIC
$<$<COMPILE_LANGUAGE:ASM>:${MBED_STUDIO_ARM_COMPILER}> $<$<COMPILE_LANGUAGE:ASM>:${MBED_STUDIO_ARM_COMPILER}>
$<$<COMPILE_LANGUAGE:ASM>:--cpreproc> $<$<COMPILE_LANGUAGE:ASM>:--cpreproc>
$<$<COMPILE_LANGUAGE:ASM>:--cpreproc_opts=${asm_preproc_options}> $<$<COMPILE_LANGUAGE:ASM>:--cpreproc_opts=${asm_preproc_options}>
) )
target_compile_definitions(mbed-os target_compile_definitions(${target}
PUBLIC PUBLIC
TOOLCHAIN_ARM TOOLCHAIN_ARM
) )
target_link_options(mbed-os target_link_options(${target}
PUBLIC PUBLIC
${MBED_STUDIO_ARM_COMPILER} ${MBED_STUDIO_ARM_COMPILER}
) )
endfunction()

View File

@ -7,6 +7,9 @@ set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
set(GCC_ELF2BIN "arm-none-eabi-objcopy") set(GCC_ELF2BIN "arm-none-eabi-objcopy")
set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN}) set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
# Sets toolchain options
function(mbed_set_toolchain_options target)
list(APPEND link_options list(APPEND link_options
"-Wl,--start-group" "-Wl,--start-group"
"-lstdc++" "-lstdc++"
@ -35,19 +38,20 @@ list(APPEND common_options
"-g3" "-g3"
) )
target_compile_options(mbed-os target_compile_options(${target}
PUBLIC PUBLIC
${common_options} ${common_options}
) )
target_compile_definitions(mbed-os target_compile_definitions(${target}
PUBLIC PUBLIC
TOOLCHAIN_GCC_ARM TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC TOOLCHAIN_GCC
) )
target_link_options(mbed-os target_link_options(${target}
PUBLIC PUBLIC
${common_options} ${common_options}
${link_options} ${link_options}
) )
endfunction()