Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Set required toolchain and processor flags globally, instead of per-target #13987

Merged
merged 9 commits into from
Dec 10, 2020
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(${MBED_PATH}/tools/cmake/core.cmake)

add_library(mbed-core INTERFACE)

Expand Down Expand Up @@ -55,8 +54,6 @@ endif()

mbed_set_cpu_core_definitions(mbed-core)
if(${MBED_TOOLCHAIN_FILE_USED})
mbed_set_cpu_core_options(mbed-core ${MBED_TOOLCHAIN})
mbed_set_toolchain_options(mbed-core)
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN})
mbed_set_c_lib(mbed-core ${MBED_C_LIB})
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB})
Expand Down
14 changes: 5 additions & 9 deletions tools/cmake/app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ endif()

include(${MBED_CONFIG_PATH}/mbed_config.cmake)

# Set default toolchain file
# Load toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")

set(CMAKE_TOOLCHAIN_FILE "${MBED_PATH}/tools/cmake/toolchain.cmake" CACHE INTERNAL "")
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved

# Specify locations for toolchains and generic options
include(${MBED_PATH}/tools/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)

# Specify available build profiles and add options for the selected build profile
include(${MBED_PATH}/tools/cmake/profile.cmake)
include(${MBED_PATH}/tools/cmake/toolchain.cmake)
endif()

# Specify available build profiles and add options for the selected build profile
include(${MBED_PATH}/tools/cmake/profile.cmake)

enable_language(C CXX ASM)
4 changes: 0 additions & 4 deletions tools/cmake/core.cmake

This file was deleted.

59 changes: 20 additions & 39 deletions tools/cmake/cores/Cortex-A9.cmake
Original file line number Diff line number Diff line change
@@ -1,45 +1,26 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Sets cpu core options
function(mbed_set_cpu_core_options target mbed_toolchain)
if(${mbed_toolchain} STREQUAL "GCC_ARM")
list(APPEND common_toolchain_options
"-mthumb-interwork"
"-marm"
"-march=armv7-a"
"-mfpu=vfpv3"
"-mfloat-abi=hard"
"-mno-unaligned-access"
)

target_compile_options(${target}
INTERFACE
${common_toolchain_options}
)

target_link_options(${target}
INTERFACE
${common_toolchain_options}
)
elseif(${mbed_toolchain} STREQUAL "ARM")
list(APPEND compile_options
"-mcpu=cortex-a9"
)

target_compile_options(${target}
INTERFACE
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-A9>
)

target_link_options(${target}
INTERFACE
"--cpu=Cortex-A9"
)
endif()
endfunction()
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
list(APPEND common_options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to introduce own list for each FLAGS?

MBED_TOOLCHAIN_<LANG>_FLAGS so C/CXX/ASM/LD, and we would add these to CMake _INIT flags.

These could be cached variable, similar as _INIT flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's already how I have it set up. link_options is for linker flags, common_options is for all compilers, c_cxx_compile_options is for C and CXX compilers, and asm_compile_options is for ASM only.

Copy link
Contributor

@0xc0170 0xc0170 Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct the use is as it should. we use mbed prefix ( MBED_TOOLCHAIN or so), if these could be prefixed as well but they might not, see my comment below

Copy link
Contributor

@0xc0170 0xc0170 Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these are not global symbols, it does not need to be prefixed neither with capital letters

"-mthumb-interwork"
"-marm"
"-march=armv7-a"
"-mfpu=vfpv3"
"-mfloat-abi=hard"
"-mno-unaligned-access"
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND c_cxx_compile_options
"-mcpu=cortex-a9"
)
list(APPEND asm_compile_options
"-mcpu=Cortex-A9"
)
list(APPEND link_options
"--cpu=Cortex-A9"
)
endif()

function(mbed_set_cpu_core_definitions target)
target_compile_definitions(${target}
Expand Down
50 changes: 16 additions & 34 deletions tools/cmake/cores/Cortex-M0+.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,22 @@
# SPDX-License-Identifier: Apache-2.0

# Sets cpu core options
function(mbed_set_cpu_core_options target mbed_toolchain)
if(${mbed_toolchain} STREQUAL "GCC_ARM")
list(APPEND common_toolchain_options
"-mthumb"
"-mcpu=cortex-m0plus"
)

target_compile_options(${target}
INTERFACE
${common_toolchain_options}
)

target_link_options(${target}
INTERFACE
${common_toolchain_options}
)
elseif(${mbed_toolchain} STREQUAL "ARM")
list(APPEND compile_options
"-mcpu=cortex-m0plus"
)

target_compile_options(${target}
INTERFACE
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M0plus>
)

target_link_options(${target}
INTERFACE
"--cpu=Cortex-M0plus"
)
endif()
endfunction()
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
list(APPEND common_options
"-mthumb"
"-mcpu=cortex-m0plus"
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND c_cxx_compile_options
"-mcpu=cortex-m0plus"
)
list(APPEND asm_compile_options
"-mcpu=Cortex-M0plus"
)
list(APPEND link_options
"--cpu=Cortex-M0plus"
)
endif()

function(mbed_set_cpu_core_definitions target)
target_compile_definitions(${target}
Expand Down
48 changes: 15 additions & 33 deletions tools/cmake/cores/Cortex-M0.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,21 @@
# SPDX-License-Identifier: Apache-2.0

# Sets cpu core options
function(mbed_set_cpu_core_options target mbed_toolchain)
if(${mbed_toolchain} STREQUAL "GCC_ARM")
list(APPEND common_toolchain_options
"-mthumb"
)

target_compile_options(${target}
INTERFACE
${common_toolchain_options}
)

target_link_options(${target}
INTERFACE
${common_toolchain_options}
)
elseif(${mbed_toolchain} STREQUAL "ARM")
list(APPEND options
"-mcpu=cortex-m0"
)

target_compile_options(${target}
INTERFACE
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M0>
)

target_link_options(${target}
INTERFACE
"-cpu=Cortex-M0"
)
endif()
endfunction()
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
list(APPEND common_options
"-mthumb"
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND c_cxx_compile_options
"-mcpu=cortex-m0"
)
list(APPEND asm_compile_options
"-mcpu=Cortex-M0"
)
list(APPEND link_options
"--cpu=Cortex-M0"
)
endif()

function(mbed_set_cpu_core_definitions target)
target_compile_definitions(${target}
Expand Down
48 changes: 15 additions & 33 deletions tools/cmake/cores/Cortex-M1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,21 @@
# SPDX-License-Identifier: Apache-2.0

# Sets cpu core options
function(mbed_set_cpu_core_options target mbed_toolchain)
if(${mbed_toolchain} STREQUAL "GCC_ARM")
list(APPEND common_toolchain_options
"-mthumb"
)

target_compile_options(${target}
INTERFACE
${common_toolchain_options}
)

target_link_options(${target}
INTERFACE
${common_toolchain_options}
)
elseif(${mbed_toolchain} STREQUAL "ARM")
list(APPEND options
"-mcpu=cortex-m1"
)

target_compile_options(${target}
INTERFACE
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M1>
)

target_link_options(${target}
INTERFACE
"--cpu=Cortex-M1"
)
endif()
endfunction()
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
list(APPEND common_options
"-mthumb"
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND c_cxx_compile_options
"-mcpu=cortex-m1"
)
list(APPEND asm_compile_options
"-mcpu=Cortex-M1"
)
list(APPEND link_options
"--cpu=Cortex-M1"
)
endif()

function(mbed_set_cpu_core_definitions target)
target_compile_definitions(${target}
Expand Down
47 changes: 15 additions & 32 deletions tools/cmake/cores/Cortex-M23-NS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,22 @@
# SPDX-License-Identifier: Apache-2.0

# Sets cpu core options
function(mbed_set_cpu_core_options target mbed_toolchain)
if(${mbed_toolchain} STREQUAL "GCC_ARM")
list(APPEND common_toolchain_options
"-mthumb"
)

target_compile_options(${target}
INTERFACE
${common_toolchain_options}
)

target_link_options(${target}
INTERFACE
${common_toolchain_options}
)
elseif(${mbed_toolchain} STREQUAL "ARM")
list(APPEND compile_options
"-mcpu=cortex-m23"
)

target_compile_options(${target}
INTERFACE
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M23>
)
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
list(APPEND common_options
"-mthumb"
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND c_cxx_compile_options
"-mcpu=cortex-m23"
)
list(APPEND asm_compile_options
"-mcpu=Cortex-M23"
)
list(APPEND link_options
"--cpu=Cortex-M23"
)
endif()

target_link_options(${target}
INTERFACE
"--cpu=Cortex-M23"
)
endif()
endfunction()

function(mbed_set_cpu_core_definitions target)
target_compile_definitions(${target}
Expand Down
47 changes: 15 additions & 32 deletions tools/cmake/cores/Cortex-M23.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,22 @@
# SPDX-License-Identifier: Apache-2.0

# Sets cpu core options
function(mbed_set_cpu_core_options target mbed_toolchain)
if(${mbed_toolchain} STREQUAL "GCC_ARM")
list(APPEND common_toolchain_options
"-mthumb"
)

target_compile_options(${target}
INTERFACE
${common_toolchain_options}
)

target_link_options(${target}
INTERFACE
${common_toolchain_options}
)
elseif(${mbed_toolchain} STREQUAL "ARM")
list(APPEND compile_options
"-mcpu=cortex-m23"
)

target_compile_options(${target}
INTERFACE
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M23>
)
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
list(APPEND common_options
"-mthumb"
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
list(APPEND c_cxx_compile_options
"-mcpu=cortex-m23"
)
list(APPEND asm_compile_options
"-mcpu=Cortex-M23"
)
list(APPEND link_options
"--cpu=Cortex-M23"
)
endif()

target_link_options(${target}
INTERFACE
"--cpu=Cortex-M23"
)
endif()
endfunction()

function(mbed_set_cpu_core_definitions target)
target_compile_definitions(${target}
Expand Down
Loading