CMake: replace usage of the mbed_add_cmake_directory_if_labels() function (#13754)

Directories that start with special prefixes (TARGET_, FEATURE_, COMPONENT_)  are added to the build based on Mbed target configuration from targets.json instead of calling utility function mbed_add_cmake_directory_if_labels().
pull/13566/head
Rajkumar Kanagaraj 2020-10-13 13:52:06 +01:00 committed by Hugues Kamba
parent fa98689639
commit 8016a53400
22 changed files with 98 additions and 56 deletions

View File

@ -22,7 +22,6 @@ include(${MBED_ROOT}/tools/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
enable_language(C CXX ASM) enable_language(C CXX ASM)
include(${MBED_ROOT}/tools/cmake/core.cmake) include(${MBED_ROOT}/tools/cmake/core.cmake)
include(${MBED_ROOT}/tools/cmake/util.cmake)
include(${MBED_ROOT}/tools/cmake/profile.cmake) include(${MBED_ROOT}/tools/cmake/profile.cmake)
add_library(mbed-os OBJECT) add_library(mbed-os OBJECT)

View File

@ -1,6 +1,10 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
mbed_add_cmake_directory_if_labels("TARGET") if("CORTEX_A" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_CORTEX_A)
elseif("CORTEX_M" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_CORTEX_M)
endif()
add_subdirectory(RTOS2) add_subdirectory(RTOS2)

View File

@ -11,18 +11,21 @@ Two steps approach:
Definitions and configurations would be defined in CMake files, an Mbed app configuration file (`/path/to/app/mbed_app.json`) and Mbed library configuration files (`/path/to/mbed-os/<LIBRARY_NAME>/mbed_lib.json`). `mbed-tools` would parse the Mbed library and app configuration files and generate an `mbed_config.cmake` file. Definitions and configurations would be defined in CMake files, an Mbed app configuration file (`/path/to/app/mbed_app.json`) and Mbed library configuration files (`/path/to/mbed-os/<LIBRARY_NAME>/mbed_lib.json`). `mbed-tools` would parse the Mbed library and app configuration files and generate an `mbed_config.cmake` file.
The following rules must be respected for backward compatibility. The following rules must be respected to include special prefix directories (TARGET_, COMPONENT_ and FEATURE_).
Target labels, components, and features defined in `/path/to/mbed-os/targets/targets.json` are used to help the build system determine which directories contain sources/include files to use in the build process. This is accomplished through a custom CMake function (`mbed_add_cmake_directory_if_labels`) to append a prefix (TARGET_, COMPONENT_ and FEATURE_) and add matching directories to the list of directories to process. Target labels, components, and features defined in `/path/to/mbed-os/targets/targets.json` are used to help the build system determine which directories contain sources/include files to use in the build process.
An example, to add `TARGET_STM` in the folder `targets` where we have folders like TARGET_NXP, TARGET_STM, etc: This is a problem as labels, components and features directories will most likely be renamed and will not necessarily use the special prefixes TARGET_, COMPONENT_ and FEATURE_ respectively. Whenever such directories are encountered, check the directory name without the special prefix in the CMake list `MBED_TARGET_LABELS` generated by `mbed-tools` then include the subdirectory to the build process if found.
For example when the user builds for the `NUCLEO_F411RE` Mbed target, `mbed-tools` includes the `STM` label to the `MBED_TARGET_LABELS` list. `TARGET_STM` can only be added to the list of build directories as shown below:
``` ```
mbed_add_cmake_directory_if_labels("TARGET") # CMake input source file: mbed-os/targets/CMakeList.txt
if("STM" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM)
endif()
``` ```
If a user selects for example target `NUCLEO_F411RE`, the target defines the label `STM`. As result, the target folder STM is included.
The same could be applied to other labels like features or components. The same could be applied to other labels like features or components.
## Mbed OS Core (Mbed OS repository) ## Mbed OS Core (Mbed OS repository)
@ -36,7 +39,6 @@ A number of CMake scripts are contained in the `mbed-os/tools/cmake` directory:
* `core.cmake` - selects the core script from the `cmake/cores` directory, based on the value of the `MBED_CPU_CORE` variable * `core.cmake` - selects the core script from the `cmake/cores` directory, based on the value of the `MBED_CPU_CORE` variable
* `profile.cmake` - selects the profile script from the `cmake/profiles` directory, based on the value of the `MBED_PROFILE` variable * `profile.cmake` - selects the profile script from the `cmake/profiles` directory, based on the value of the `MBED_PROFILE` variable
* `toolchain.cmake` - selects the toolchain script from the `cmake/toolchains` directory, based on the value of the `MBED_TOOLCHAIN` variable * `toolchain.cmake` - selects the toolchain script from the `cmake/toolchains` directory, based on the value of the `MBED_TOOLCHAIN` variable
* `util.cmake` - custom CMake helper functions and macros
The next sections will describe static CMake files within Mbed OS Core repository. The next sections will describe static CMake files within Mbed OS Core repository.
@ -64,7 +66,7 @@ Custom functions/macros used within Mbed OS.
### 7. Component `CMakeLists.txt` Entry Point ### 7. Component `CMakeLists.txt` Entry Point
This file statically defines the build specification of an Mbed OS component. It contains conditional statements that depend on the configuration parameters generated by `mbed-tools`. The component entry points make use of functions/macros defined in `util.cmake` to conditionally include or exclude directories. This file statically defines the build specification of an Mbed OS component. It contains conditional statements that depend on the configuration parameters generated by `mbed-tools`.
The rule of thumb is to not expose header files that are internal. We would like to avoid having everything in the include paths as we do now. The rule of thumb is to not expose header files that are internal. We would like to avoid having everything in the include paths as we do now.
## Building an Application ## Building an Application

View File

@ -1,7 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
mbed_add_cmake_directory_if_labels("TARGET") if("FLASH_CMSIS_ALGO" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_FLASH_CMSIS_ALGO)
endif()
add_subdirectory(usb) add_subdirectory(usb)

View File

@ -1,8 +1,6 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
mbed_add_cmake_directory_if_labels("TARGET")
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC
include include

View File

@ -1,4 +1,10 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
mbed_add_cmake_directory_if_labels("TARGET") if("Freescale" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_Freescale)
elseif("NORDIC" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_NORDIC)
elseif("STM" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM)
endif()

View File

@ -1,7 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
mbed_add_cmake_directory_if_labels("TARGET") if("MCUXpresso_MCUS" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_MCUXpresso_MCUS)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC

View File

@ -1,6 +1,12 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("K66F" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_K66F)
elseif("MCU_K64F" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_MCU_K64F)
endif()
target_sources(mbed-os target_sources(mbed-os
PRIVATE PRIVATE
fsl_common.c fsl_common.c
@ -24,5 +30,3 @@ target_include_directories(mbed-os
PUBLIC PUBLIC
api api
) )
mbed_add_cmake_directory_if_labels("TARGET")

View File

@ -1,7 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
mbed_add_cmake_directory_if_labels("TARGET") if("FRDM" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_FRDM)
endif()
add_subdirectory(device) add_subdirectory(device)

View File

@ -2,7 +2,13 @@
add_subdirectory(device) add_subdirectory(device)
mbed_add_cmake_directory_if_labels("TARGET") if("FRDM" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_FRDM)
elseif("HEXIWEAR" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_HEXIWEAR)
elseif("SDT64B" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_SDT64B)
endif()
target_sources(mbed-os target_sources(mbed-os
PRIVATE PRIVATE

View File

@ -1,9 +1,11 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("NRF5x" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_NRF5x)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
) )
mbed_add_cmake_directory_if_labels("TARGET")

View File

@ -1,6 +1,16 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("NRF52" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_NRF52)
endif()
if("SDK_11" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_SDK_11)
elseif("SDK_15_0" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_SDK_15_0)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
@ -14,5 +24,3 @@ target_sources(mbed-os
qspi_api.c qspi_api.c
rtc_api.c rtc_api.c
) )
mbed_add_cmake_directory_if_labels("TARGET")

View File

@ -1,6 +1,10 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("MCU_NRF52840" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_MCU_NRF52840)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
@ -27,5 +31,3 @@ target_sources(mbed-os
us_ticker.c us_ticker.c
watchdog_api.c watchdog_api.c
) )
mbed_add_cmake_directory_if_labels("TARGET")

View File

@ -1,6 +1,10 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("NRF52840_DK" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_NRF52840_DK)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
@ -13,5 +17,4 @@ target_sources(mbed-os
USBPhy_Nordic.cpp USBPhy_Nordic.cpp
) )
mbed_add_cmake_directory_if_labels("TARGET")
add_subdirectory(device) add_subdirectory(device)

View File

@ -1,7 +1,9 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
mbed_add_cmake_directory_if_labels("TARGET") if("SOFTDEVICE_NONE" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_SOFTDEVICE_NONE)
endif()
add_subdirectory(components) add_subdirectory(components)
add_subdirectory(integration) add_subdirectory(integration)

View File

@ -1,6 +1,12 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("STM32F4" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM32F4)
elseif("STM32L4" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM32L4)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
@ -32,5 +38,3 @@ target_sources(mbed-os
us_ticker.c us_ticker.c
watchdog_api.c watchdog_api.c
) )
mbed_add_cmake_directory_if_labels("TARGET")

View File

@ -1,6 +1,12 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("STM32F401xE" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM32F401xE)
elseif("STM32F439xI" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM32F439xI)
endif()
target_sources(mbed-os target_sources(mbed-os
PRIVATE PRIVATE
analogin_device.c analogin_device.c
@ -15,7 +21,6 @@ target_sources(mbed-os
) )
add_subdirectory(STM32Cube_FW) add_subdirectory(STM32Cube_FW)
mbed_add_cmake_directory_if_labels("TARGET")
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC

View File

@ -26,7 +26,9 @@ endfunction()
_mbed_get_assembly_stm32f401xe() _mbed_get_assembly_stm32f401xe()
_mbed_set_linker_file() _mbed_set_linker_file()
mbed_add_cmake_directory_if_labels("TARGET") if("NUCLEO_F401RE" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_NUCLEO_F401RE)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC

View File

@ -26,7 +26,11 @@ endfunction()
_mbed_get_assembly_stm32f439xi() _mbed_get_assembly_stm32f439xi()
_mbed_set_linker_file() _mbed_set_linker_file()
mbed_add_cmake_directory_if_labels("TARGET") if("NUCLEO_F439ZI" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_NUCLEO_F439ZI)
elseif("WIO_3G" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_WIO_3G)
endif()
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC

View File

@ -1,6 +1,10 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
if("STM32L475xG" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_STM32L475xG)
endif()
add_subdirectory(device) add_subdirectory(device)
target_sources(mbed-os target_sources(mbed-os
@ -14,8 +18,6 @@ target_sources(mbed-os
spi_api.c spi_api.c
) )
mbed_add_cmake_directory_if_labels("TARGET")
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}

View File

@ -1,9 +1,11 @@
# Copyright (c) 2020 ARM Limited. All rights reserved. # Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
add_subdirectory(device) if("DISCO_L475VG_IOT01A" IN_LIST MBED_TARGET_LABELS)
add_subdirectory(TARGET_DISCO_L475VG_IOT01A)
endif()
mbed_add_cmake_directory_if_labels("TARGET") add_subdirectory(device)
target_include_directories(mbed-os target_include_directories(mbed-os
PUBLIC PUBLIC

View File

@ -1,19 +0,0 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# PREFIX - TARGET or similar (can be empty string)
# KEYWORD_LIST - list of labels that are used to include directories
function(mbed_add_cmake_directory_if_labels PREFIX)
foreach(key ${MBED_TARGET_LABELS})
if(NOT "${PREFIX}" STREQUAL "")
string(PREPEND key ${PREFIX} "_")
endif()
# assumption: relative path, no need to check for absolute here
set(path ${CMAKE_CURRENT_SOURCE_DIR}/${key})
if (EXISTS ${path})
if (EXISTS "${path}/CMakeLists.txt")
add_subdirectory(${path})
endif()
endif()
endforeach()
endfunction()