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: Don't force users to build specific library type #15526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
endif()
endif()

add_library(mbed-core INTERFACE)
add_library(mbed-core ${CMAKE_LIBRARY_TYPE})

add_library(mbed-os INTERFACE)
add_library(mbed-os ${CMAKE_LIBRARY_TYPE})

target_link_libraries(mbed-os
INTERFACE
${CMAKE_LIBRARY_TYPE}
mbed-rtos
mbed-core
)

add_library(mbed-baremetal INTERFACE)
add_library(mbed-baremetal ${CMAKE_LIBRARY_TYPE})

target_link_libraries(mbed-baremetal
INTERFACE
${CMAKE_LIBRARY_TYPE}
mbed-core
)
# Validate selected C library type
Expand Down Expand Up @@ -92,15 +92,15 @@ if(${CMAKE_CROSSCOMPILING})
mbed_set_printf_lib(mbed-core ${MBED_PRINTF_LIB})

target_compile_features(mbed-core
INTERFACE
${CMAKE_LIBRARY_TYPE}
c_std_11
cxx_std_14
)

endif()

target_compile_definitions(mbed-core
INTERFACE
${CMAKE_LIBRARY_TYPE}
TARGET_NAME=${MBED_TARGET}
${MBED_TARGET_DEFINITIONS}
${MBED_CONFIG_DEFINITIONS}
Expand All @@ -110,7 +110,7 @@ if(${CMAKE_CROSSCOMPILING})
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
if(NOT BUILD_GREENTEA_TESTS)
target_compile_definitions(${PROJECT_NAME}
INTERFACE
${CMAKE_LIBRARY_TYPE}
MBED_TEST_MODE
)
endif()
Expand All @@ -135,30 +135,30 @@ if(${CMAKE_CROSSCOMPILING})
# for the GCC_ARM and ARM toolchains respectively.
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_compile_definitions(mbed-core
INTERFACE
${CMAKE_LIBRARY_TYPE}
TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_compile_definitions(mbed-core
INTERFACE
${CMAKE_LIBRARY_TYPE}
TOOLCHAIN_ARM
)
endif()
endif()

# Include mbed.h and config from generate folder
target_include_directories(mbed-core
INTERFACE
${CMAKE_LIBRARY_TYPE}
${CMAKE_CURRENT_SOURCE_DIR}
)

# These targets are made visible here so their source files which
# are spread in different directories can be referenced and can be linked against
# by libraries that depend on them.
# TODO CMake: Should the source files be moved?
add_library(mbed-device_key INTERFACE)
add_library(mbed-rtos INTERFACE)
add_library(mbed-device_key ${CMAKE_LIBRARY_TYPE})
add_library(mbed-rtos ${CMAKE_LIBRARY_TYPE})

# Include targets/ first, because any post-build hook needs to be defined
# before other parts of Mbed OS can add greentea tests which require
Expand Down Expand Up @@ -188,7 +188,7 @@ if(${CMAKE_CROSSCOMPILING})
string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED})
string(PREPEND MBED_TARGET_CONVERTED "mbed-")

target_link_libraries(mbed-core INTERFACE ${MBED_TARGET_CONVERTED})
target_link_libraries(mbed-core ${CMAKE_LIBRARY_TYPE} ${MBED_TARGET_CONVERTED})
endif()

# Ninja requires to be forced for response files
Expand Down
6 changes: 3 additions & 3 deletions cmsis/CMSIS_5/CMSIS/TARGET_CORTEX_A/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_library(mbed-cmsis-cortex-a INTERFACE)
add_library(mbed-cmsis-cortex-a ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-cmsis-cortex-a
INTERFACE
${CMAKE_LIBRARY_TYPE}
Include
)

target_sources(mbed-cmsis-cortex-a
INTERFACE
${CMAKE_LIBRARY_TYPE}
Source/irq_ctrl_gic.c
)
6 changes: 3 additions & 3 deletions cmsis/CMSIS_5/CMSIS/TARGET_CORTEX_M/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Copyright (c) 2020-2021 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

add_library(mbed-cmsis-cortex-m INTERFACE)
add_library(mbed-cmsis-cortex-m ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-cmsis-cortex-m
INTERFACE
${CMAKE_LIBRARY_TYPE}
Include
)

target_sources(mbed-cmsis-cortex-m
INTERFACE
${CMAKE_LIBRARY_TYPE}
Source/mbed_tz_context.c
)
42 changes: 21 additions & 21 deletions connectivity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
# SPDX-License-Identifier: Apache-2.0

# List of all connectivity libraries available.
add_library(mbed-802.15.4-rf INTERFACE)
add_library(mbed-ble INTERFACE)
add_library(mbed-ble-cordio INTERFACE)
add_library(mbed-ble-cordio_ll INTERFACE)
add_library(mbed-cellular INTERFACE)
add_library(mbed-coap INTERFACE)
add_library(mbed-emac INTERFACE)
add_library(mbed-lorawan INTERFACE)
add_library(mbed-lwipstack INTERFACE)
add_library(mbed-mbedtls INTERFACE)
add_library(mbed-nanostack INTERFACE)
add_library(mbed-nanostack-coap_service INTERFACE)
add_library(mbed-nanostack-mbed_mesh_api INTERFACE)
add_library(mbed-nanostack-hal_mbed_cmsis_rtos INTERFACE)
add_library(mbed-nanostack-sal_stack INTERFACE)
add_library(mbed-nanostack-sal_stack-event_loop INTERFACE)
add_library(mbed-nanostack-libservice INTERFACE)
add_library(mbed-netsocket INTERFACE)
add_library(mbed-nfc INTERFACE)
add_library(mbed-ppp INTERFACE)
add_library(mbed-wifi INTERFACE)
add_library(mbed-802.15.4-rf ${CMAKE_LIBRARY_TYPE})
add_library(mbed-ble ${CMAKE_LIBRARY_TYPE})
add_library(mbed-ble-cordio ${CMAKE_LIBRARY_TYPE})
add_library(mbed-ble-cordio_ll ${CMAKE_LIBRARY_TYPE})
add_library(mbed-cellular ${CMAKE_LIBRARY_TYPE})
add_library(mbed-coap ${CMAKE_LIBRARY_TYPE})
add_library(mbed-emac ${CMAKE_LIBRARY_TYPE})
add_library(mbed-lorawan ${CMAKE_LIBRARY_TYPE})
add_library(mbed-lwipstack ${CMAKE_LIBRARY_TYPE})
add_library(mbed-mbedtls ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nanostack ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nanostack-coap_service ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nanostack-mbed_mesh_api ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nanostack-hal_mbed_cmsis_rtos ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nanostack-sal_stack ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nanostack-sal_stack-event_loop ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nanostack-libservice ${CMAKE_LIBRARY_TYPE})
add_library(mbed-netsocket ${CMAKE_LIBRARY_TYPE})
add_library(mbed-nfc ${CMAKE_LIBRARY_TYPE})
add_library(mbed-ppp ${CMAKE_LIBRARY_TYPE})
add_library(mbed-wifi ${CMAKE_LIBRARY_TYPE})

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING)
# Add these subdirectories for tests
Expand Down
8 changes: 4 additions & 4 deletions targets/TARGET_STM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ add_subdirectory(TARGET_STM32U5 EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_STM32WB EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_STM32WL EXCLUDE_FROM_ALL)

add_library(mbed-stm INTERFACE)
add_library(mbed-stm ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-stm
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
)

target_sources(mbed-stm
INTERFACE
${CMAKE_LIBRARY_TYPE}
USBPhy_STM32.cpp
analogin_api.c
analogout_api.c
Expand All @@ -53,4 +53,4 @@ target_sources(mbed-stm
watchdog_api.c
)

target_link_libraries(mbed-stm INTERFACE mbed-cmsis-cortex-m)
target_link_libraries(mbed-stm ${CMAKE_LIBRARY_TYPE} mbed-cmsis-cortex-m)
8 changes: 4 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ add_subdirectory(TARGET_STM32F070xB EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_STM32F030x8 EXCLUDE_FROM_ALL)
add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)

add_library(mbed-stm32f0 INTERFACE)
add_library(mbed-stm32f0 ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-stm32f0
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
)

target_sources(mbed-stm32f0
INTERFACE
${CMAKE_LIBRARY_TYPE}
analogin_device.c
analogout_device.c
cmsis_nvic.c
Expand All @@ -27,4 +27,4 @@ target_sources(mbed-stm32f0
spi_api.c
)

target_link_libraries(mbed-stm32f0 INTERFACE mbed-stm mbed-stm32f0cube-fw)
target_link_libraries(mbed-stm32f0 ${CMAKE_LIBRARY_TYPE} mbed-stm mbed-stm32f0cube-fw)
8 changes: 4 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ add_subdirectory(TARGET_STM32F103xE EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_STM32F103xG EXCLUDE_FROM_ALL)
add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)

add_library(mbed-stm32f1 INTERFACE)
add_library(mbed-stm32f1 ${CMAKE_LIBRARY_TYPE})

target_sources(mbed-stm32f1
INTERFACE
${CMAKE_LIBRARY_TYPE}
analogin_device.c
analogout_device.c
flash_api.c
Expand All @@ -23,8 +23,8 @@ target_sources(mbed-stm32f1
)

target_include_directories(mbed-stm32f1
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
)

target_link_libraries(mbed-stm32f1 INTERFACE mbed-stm mbed-stm32f1cube-fw)
target_link_libraries(mbed-stm32f1 ${CMAKE_LIBRARY_TYPE} mbed-stm mbed-stm32f1cube-fw)
8 changes: 4 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
add_subdirectory(TARGET_STM32F207xG EXCLUDE_FROM_ALL)
add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)

add_library(mbed-stm32f2 INTERFACE)
add_library(mbed-stm32f2 ${CMAKE_LIBRARY_TYPE})

target_sources(mbed-stm32f2
INTERFACE
${CMAKE_LIBRARY_TYPE}
analogin_device.c
analogout_device.c
flash_api.c
Expand All @@ -18,12 +18,12 @@ target_sources(mbed-stm32f2
)

target_include_directories(mbed-stm32f2
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
./STM32Cube_FW
./STM32Cube_FW/CMSIS
./STM32Cube_FW/STM32F2xx_HAL_Driver
./STM32Cube_FW/STM32F2xx_HAL_Driver/Legacy
)

target_link_libraries(mbed-stm32f2 INTERFACE mbed-stm mbed-stm32f2cube-fw)
target_link_libraries(mbed-stm32f2 ${CMAKE_LIBRARY_TYPE} mbed-stm mbed-stm32f2cube-fw)
8 changes: 4 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ add_subdirectory(TARGET_STM32F303xE EXCLUDE_FROM_ALL)
add_subdirectory(TARGET_STM32F334x8 EXCLUDE_FROM_ALL)
add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)

add_library(mbed-stm32f3 INTERFACE)
add_library(mbed-stm32f3 ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-stm32f3
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
)

target_sources(mbed-stm32f3
INTERFACE
${CMAKE_LIBRARY_TYPE}
analogin_device.c
analogout_device.c
flash_api.c
Expand All @@ -27,4 +27,4 @@ target_sources(mbed-stm32f3
spi_api.c
)

target_link_libraries(mbed-stm32f3 INTERFACE mbed-stm mbed-stm32f3cube-fw)
target_link_libraries(mbed-stm32f3 ${CMAKE_LIBRARY_TYPE} mbed-stm mbed-stm32f3cube-fw)
8 changes: 4 additions & 4 deletions targets/TARGET_STM/TARGET_STM32F4/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ add_subdirectory(TARGET_STM32F479xG EXCLUDE_FROM_ALL)

add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)

add_library(mbed-stm32f4 INTERFACE)
add_library(mbed-stm32f4 ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-stm32f4
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
)

target_sources(mbed-stm32f4
INTERFACE
${CMAKE_LIBRARY_TYPE}
analogin_device.c
analogout_device.c
flash_api.c
Expand All @@ -57,4 +57,4 @@ target_sources(mbed-stm32f4
spi_api.c
)

target_link_libraries(mbed-stm32f4 INTERFACE mbed-stm mbed-stm32f4cube-fw)
target_link_libraries(mbed-stm32f4 ${CMAKE_LIBRARY_TYPE} mbed-stm mbed-stm32f4cube-fw)
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
set(LINKER_FILE TOOLCHAIN_ARM/stm32f407xe.sct)
endif()

add_library(mbed-stm32f407xe INTERFACE)
add_library(mbed-stm32f407xe ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-stm32f407xe
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
)

target_sources(mbed-stm32f407xe
INTERFACE
${CMAKE_LIBRARY_TYPE}
${STARTUP_FILE}
system_clock.c
)

mbed_set_linker_script(mbed-stm32f407xe ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})

target_link_libraries(mbed-stm32f407xe INTERFACE mbed-stm32f4)
target_link_libraries(mbed-stm32f407xe ${CMAKE_LIBRARY_TYPE} mbed-stm32f4)
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
set(LINKER_FILE TOOLCHAIN_ARM/stm32f429xg.sct)
endif()

add_library(mbed-stm32f429xg INTERFACE)
add_library(mbed-stm32f429xg ${CMAKE_LIBRARY_TYPE})

target_include_directories(mbed-stm32f429xg
INTERFACE
${CMAKE_LIBRARY_TYPE}
.
)

target_sources(mbed-stm32f429xg
INTERFACE
${CMAKE_LIBRARY_TYPE}
${STARTUP_FILE}
)

mbed_set_linker_script(mbed-stm32f429xg ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})

target_link_libraries(mbed-stm32f429xg INTERFACE mbed-stm32f4)
target_link_libraries(mbed-stm32f429xg
${CMAKE_LIBRARY_TYPE}
INTERFACE mbed-stm32f4)
Loading