diff --git a/CMakeLists.txt b/CMakeLists.txt index f0cbb94..e80610f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,8 @@ # - MBED_OS_IS_STANDALONE: True if Mbed OS is the top-level project. False if Mbed is being built as part of an application. # - MBED_IS_NATIVE_BUILD: True if we are building for the host machine. False if we are building for a microcontroller # - MBED_OS_ENABLE_TESTS: True if we are building *any* internal Mbed OS tests at all. Enabled by -DBUILD_TESTING=TRUE (which is enabled by default when standalone). -# - BUILD_GREENTEA_TESTS: True to build greentea on-target tests. False to build host UNITTESTS. +# - BUILD_GREENTEA_TESTS: True to build greentea on-target tests. False to build host UNITTESTS. Defaults to false when standalone. + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) # We are the top level project, so tests or unittests are being built. @@ -21,37 +22,41 @@ set(MBED_OS_IS_STANDALONE FALSE) endif() -if(CMAKE_CROSSCOMPILING) - set(MBED_IS_NATIVE_BUILD FALSE) -else() - set(MBED_IS_NATIVE_BUILD TRUE) -endif() - -if(MBED_IS_NATIVE_BUILD) - # Pick up some include files that are needed later - list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/tools/cmake) -endif() - -if(MBED_IS_NATIVE_BUILD) - # Pick up some include files that are needed later - list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/tools/cmake) - include(mbed_create_distro) -else() - # Grab the Mbed configs for this target - include(${MBED_CONFIG_PATH}/mbed_config.cmake) - include(mbed_set_linker_script) -endif() - # Set up options for testing option(BUILD_TESTING "Whether to enable CTest tests in this project" ${MBED_OS_IS_STANDALONE}) # This option is also created by include(CTest) but we need it here earlier on. if(MBED_OS_IS_STANDALONE AND BUILD_TESTING) set(MBED_OS_ENABLE_TESTS TRUE) - option(BUILD_GREENTEA_TESTS "Build greentea tests instead of unit tests" ${CMAKE_CROSSCOMPILING}) + option(BUILD_GREENTEA_TESTS "Build greentea tests instead of unit tests" FALSE) endif() +# Figure out if this is a native build if(MBED_OS_IS_STANDALONE) - # For standalong builds, look for mbed-config.cmake in the top level mbed os dir + + # Standalone build, use BUILD_GREENTEA_TESTS to determine if we are building for native or not (user can select) + if(BUILD_GREENTEA_TESTS) + set(MBED_IS_NATIVE_BUILD FALSE) + else() + set(MBED_IS_NATIVE_BUILD TRUE) + endif() + +else() + + # Building as a subdir. This means that the top-level project will already have called project(), so we can + # rely on CMake's platform detection. + if(CMAKE_CROSSCOMPILING) + set(MBED_IS_NATIVE_BUILD FALSE) + else() + set(MBED_IS_NATIVE_BUILD TRUE) + endif() + +endif() + +if(MBED_OS_IS_STANDALONE AND NOT MBED_IS_NATIVE_BUILD) + # For standalone builds, default to looking for mbed-config.cmake in the binary dir set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE STRING "") + + # Initialize Mbed build system + include(${CMAKE_CURRENT_LIST_DIR}/tools/cmake/app.cmake) endif() if(MBED_IS_NATIVE_BUILD) @@ -77,7 +82,8 @@ # Create core Mbed OS targets and set up build flags ---------------------------------------------------------------------------------- -project(mbed-os) +# Create project and find compilers (if not already found) +project(mbed-os LANGUAGES C CXX ASM) # Add all paths to the list files within Mbed OS list(APPEND CMAKE_MODULE_PATH @@ -100,8 +106,10 @@ # are spread in different directories can be referenced and can be linked against # by libraries that depend on them. add_library(mbed-device_key INTERFACE) -add_library(mbed-rtos INTERFACE) # Collects source files and flags that are in mbed-os but not mbed-baremetal -add_library(mbed-core INTERFACE) # Collects source files and flags common to mbed-baremetal and mbed-os +add_library(mbed-rtos-flags INTERFACE) # Collects source files that are in mbed-os but not mbed-baremetal +add_library(mbed-rtos-sources INTERFACE) # Collects flags that are in mbed-os but not mbed-baremetal +add_library(mbed-core-flags INTERFACE) # Collects flags common to mbed-baremetal and mbed-os +add_library(mbed-core-sources INTERFACE) # Collects source files common to mbed-baremetal and mbed-os # Validate selected C library type # The C library type selected has to match the library that the target can support @@ -132,13 +140,13 @@ ) endif() - mbed_set_cpu_core_definitions(mbed-core) + mbed_set_cpu_core_definitions(mbed-core-flags) if(${MBED_TOOLCHAIN_FILE_USED}) - 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}) + mbed_set_profile_options(mbed-core-flags ${MBED_TOOLCHAIN}) + mbed_set_c_lib(mbed-core-flags ${MBED_C_LIB}) + mbed_set_printf_lib(mbed-core-flags ${MBED_PRINTF_LIB}) - target_compile_features(mbed-core + target_compile_features(mbed-core-flags INTERFACE c_std_11 cxx_std_14 @@ -146,7 +154,7 @@ endif() - target_compile_definitions(mbed-core + target_compile_definitions(mbed-core-flags INTERFACE TARGET_NAME=${MBED_TARGET} ) @@ -172,24 +180,31 @@ # # TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without # using response files or global properties. - mbed_generate_options_for_linker(mbed-core RESPONSE_FILE_PATH) + mbed_generate_options_for_linker(mbed-core-flags RESPONSE_FILE_PATH) set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${RESPONSE_FILE_PATH}) # Add compile definitions for backward compatibility with the toolchain # supported. New source files should instead check for __GNUC__ and __clang__ # for the GCC_ARM and ARM toolchains respectively. if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") - target_compile_definitions(mbed-core + target_compile_definitions(mbed-core-flags INTERFACE TOOLCHAIN_GCC_ARM TOOLCHAIN_GCC ) elseif(${MBED_TOOLCHAIN} STREQUAL "ARM") - target_compile_definitions(mbed-core + target_compile_definitions(mbed-core-flags INTERFACE TOOLCHAIN_ARM ) endif() + + + # Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix. + string(TOLOWER ${MBED_TARGET} MBED_TARGET_CMAKE_NAME) + string(REPLACE "_" "-" MBED_TARGET_CMAKE_NAME ${MBED_TARGET_CMAKE_NAME}) + string(PREPEND MBED_TARGET_CMAKE_NAME "mbed-") + endif() if(MBED_IS_NATIVE_BUILD) @@ -202,11 +217,11 @@ # Generate target config header and include it in all files if(NOT MBED_IS_NATIVE_BUILD) 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) + target_compile_options(mbed-core-flags INTERFACE -include ${CMAKE_CURRENT_BINARY_DIR}/mbed-target-config.h) endif() # Include mbed.h and config from generate folder -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -237,20 +252,20 @@ # Create top-level targets ---------------------------------------------------------------------------------- if(NOT MBED_IS_NATIVE_BUILD) - # Ensure the words that make up the Mbed target name are separated with a hyphen, lowercase, and with the `mbed-` prefix. - string(TOLOWER ${MBED_TARGET} MBED_TARGET_CONVERTED) - string(REPLACE "_" "-" MBED_TARGET_CONVERTED ${MBED_TARGET_CONVERTED}) - string(PREPEND MBED_TARGET_CONVERTED "mbed-") -endif() -if(NOT MBED_IS_NATIVE_BUILD) - # Core Mbed OS library + # Create a distro for the microcontroller cmake target, ensuring its sources are only compiled once + mbed_create_distro(${MBED_TARGET_CMAKE_NAME}-obj ${MBED_TARGET_CMAKE_NAME} mbed-core-flags) + + # Now make core flags depend on that distro, ensuring everything has access to the uC's flags and objects. + target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-obj) + + # Core Mbed OS libraries # mbed-baremetal contains baremetal sources + target sources + target compile flags. # mbed-os will be a superset of mbed-baremetal, also containing the RTOS sources and RTOS flags. # Note that many different source files will compile differently depending on if the RTOS is in use. # So, it's needed to compile the core sources twice, once for RTOS and once for non-RTOS. - mbed_create_distro(mbed-baremetal mbed-core ${MBED_TARGET_CONVERTED}) - mbed_create_distro(mbed-os mbed-core mbed-rtos ${MBED_TARGET_CONVERTED}) + mbed_create_distro(mbed-baremetal mbed-core-flags mbed-core-sources) + mbed_create_distro(mbed-os mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources) endif() # Ninja requires to be forced for response files diff --git a/cmsis/CMSIS_5/CMSIS/RTOS2/CMakeLists.txt b/cmsis/CMSIS_5/CMSIS/RTOS2/CMakeLists.txt index 5953cc5..b8d93bb 100644 --- a/cmsis/CMSIS_5/CMSIS/RTOS2/CMakeLists.txt +++ b/cmsis/CMSIS_5/CMSIS/RTOS2/CMakeLists.txt @@ -3,12 +3,12 @@ add_subdirectory(RTX) -target_include_directories(mbed-rtos +target_include_directories(mbed-rtos-flags INTERFACE Include ) -target_sources(mbed-rtos +target_sources(mbed-rtos-sources INTERFACE Source/os_systick.c Source/os_tick_ptim.c diff --git a/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt b/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt index e25cbf8..b37c34c 100644 --- a/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt +++ b/cmsis/CMSIS_5/CMSIS/RTOS2/RTX/CMakeLists.txt @@ -22,7 +22,7 @@ set(STARTUP_RTX_FILE TARGET_RTOS_M4_M7/irq_cm4f.S) endif() - target_sources(mbed-rtos + target_sources(mbed-rtos-sources INTERFACE Source/${toolchain_dir}/${STARTUP_RTX_FILE} ) @@ -42,7 +42,7 @@ _mbed_get_cortex_m_exception_handlers(TOOLCHAIN_GCC) endif() -target_include_directories(mbed-rtos +target_include_directories(mbed-rtos-flags INTERFACE Config Include @@ -50,7 +50,7 @@ Source ) -target_sources(mbed-rtos +target_sources(mbed-rtos-sources INTERFACE Config/RTX_Config.c diff --git a/cmsis/device/CMakeLists.txt b/cmsis/device/CMakeLists.txt index d968802..937ff31 100644 --- a/cmsis/device/CMakeLists.txt +++ b/cmsis/device/CMakeLists.txt @@ -3,7 +3,7 @@ add_subdirectory(RTE) -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE . ) diff --git a/cmsis/device/RTE/CMakeLists.txt b/cmsis/device/RTE/CMakeLists.txt index f51bf23..f09cf61 100644 --- a/cmsis/device/RTE/CMakeLists.txt +++ b/cmsis/device/RTE/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE include ) diff --git a/cmsis/device/rtos/CMakeLists.txt b/cmsis/device/rtos/CMakeLists.txt index 34cd162..7c1c675 100644 --- a/cmsis/device/rtos/CMakeLists.txt +++ b/cmsis/device/rtos/CMakeLists.txt @@ -3,24 +3,24 @@ if(${CMAKE_CROSSCOMPILING}) if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM") - target_sources(mbed-rtos + target_sources(mbed-rtos-sources INTERFACE TOOLCHAIN_GCC_ARM/mbed_boot_gcc_arm.c ) elseif(${MBED_TOOLCHAIN} STREQUAL "ARM") - target_sources(mbed-rtos + target_sources(mbed-rtos-sources INTERFACE TOOLCHAIN_ARM_STD/mbed_boot_arm_std.c ) endif() endif() -target_include_directories(mbed-rtos +target_include_directories(mbed-rtos-flags INTERFACE include ) -target_sources(mbed-rtos +target_sources(mbed-rtos-sources INTERFACE source/mbed_boot.c source/mbed_rtos_rtx.c @@ -28,7 +28,7 @@ source/mbed_rtx_idle.cpp ) -target_compile_definitions(mbed-rtos +target_compile_definitions(mbed-rtos-flags INTERFACE MBED_CONF_RTOS_PRESENT=1 ) diff --git a/connectivity/cellular/CMakeLists.txt b/connectivity/cellular/CMakeLists.txt index 1128385..757ac90 100644 --- a/connectivity/cellular/CMakeLists.txt +++ b/connectivity/cellular/CMakeLists.txt @@ -31,5 +31,5 @@ target_link_libraries(mbed-cellular INTERFACE mbed-netsocket - mbed-core + mbed-core-flags ) diff --git a/connectivity/drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt b/connectivity/drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt index dd2d83e..eb944c3 100644 --- a/connectivity/drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt +++ b/connectivity/drivers/ble/FEATURE_BLE/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt @@ -14,5 +14,5 @@ target_link_libraries(mbed-ble INTERFACE - mbed-core + mbed-core-flags ) diff --git a/connectivity/libraries/nanostack-libservice/CMakeLists.txt b/connectivity/libraries/nanostack-libservice/CMakeLists.txt index 9af5a22..55026a1 100644 --- a/connectivity/libraries/nanostack-libservice/CMakeLists.txt +++ b/connectivity/libraries/nanostack-libservice/CMakeLists.txt @@ -22,16 +22,16 @@ # The definition, source files and include directories below # are needed by mbed-trace which is part of the mbed-core CMake target -target_compile_definitions(mbed-core +target_compile_definitions(mbed-core-flags INTERFACE MBED_CONF_NANOSTACK_LIBSERVICE_PRESENT=1 ) -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE . ./mbed-client-libservice ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE source/libBits/common_functions.c source/libip6string/ip6tos.c diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 0e92b77..72ca713 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -9,7 +9,7 @@ endif() endif() -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE . ./include @@ -17,7 +17,7 @@ ./include/drivers/internal ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE source/AnalogIn.cpp source/AnalogOut.cpp diff --git a/features/CMakeLists.txt b/features/CMakeLists.txt index 12e8c80..01af5f1 100644 --- a/features/CMakeLists.txt +++ b/features/CMakeLists.txt @@ -4,8 +4,8 @@ # List of all features libraries available. add_library(mbed-fpga-ci-test-shield INTERFACE) add_library(mbed-client-cli INTERFACE) -add_library(mbed-unity INTERFACE) -add_library(mbed-utest INTERFACE) +add_library(mbed-unity OBJECT EXCLUDE_FROM_ALL) +add_library(mbed-utest OBJECT EXCLUDE_FROM_ALL) add_subdirectory(frameworks/COMPONENT_FPGA_CI_TEST_SHIELD) add_subdirectory(frameworks/mbed-client-cli) diff --git a/features/frameworks/greentea-client/CMakeLists.txt b/features/frameworks/greentea-client/CMakeLists.txt index 7e8ebe4..79bdd8c 100644 --- a/features/frameworks/greentea-client/CMakeLists.txt +++ b/features/frameworks/greentea-client/CMakeLists.txt @@ -1,14 +1,17 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 +add_library(mbed-greentea OBJECT EXCLUDE_FROM_ALL) target_include_directories(mbed-greentea - INTERFACE + PUBLIC . greentea-client ) target_sources(mbed-greentea - INTERFACE + PRIVATE source/greentea_metrics.cpp source/greentea_test_env.cpp ) + +target_link_libraries(mbed-greentea PUBLIC mbed-core-flags) diff --git a/features/frameworks/mbed-greentea-io/CMakeLists.txt b/features/frameworks/mbed-greentea-io/CMakeLists.txt index 8d68931..57225f0 100644 --- a/features/frameworks/mbed-greentea-io/CMakeLists.txt +++ b/features/frameworks/mbed-greentea-io/CMakeLists.txt @@ -1,6 +1,6 @@ # Copyright (c) 2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -add_library(mbed-greentea-io INTERFACE) -target_sources(mbed-greentea-io INTERFACE mbed_io.cpp) -target_link_libraries(mbed-greentea-io INTERFACE mbed-core) +add_library(mbed-greentea-io OBJECT EXCLUDE_FROM_ALL) +target_sources(mbed-greentea-io PRIVATE mbed_io.cpp) +target_link_libraries(mbed-greentea-io PUBLIC mbed-core-flags) diff --git a/features/frameworks/unity/CMakeLists.txt b/features/frameworks/unity/CMakeLists.txt index 9697425..1287f17 100644 --- a/features/frameworks/unity/CMakeLists.txt +++ b/features/frameworks/unity/CMakeLists.txt @@ -2,12 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 target_include_directories(mbed-unity - INTERFACE + PUBLIC . unity ) target_sources(mbed-unity - INTERFACE + PRIVATE source/unity.c ) + +target_link_libraries(mbed-unity PUBLIC mbed-core-flags mbed-utest) diff --git a/features/frameworks/utest/CMakeLists.txt b/features/frameworks/utest/CMakeLists.txt index 6af46a7..1000a56 100644 --- a/features/frameworks/utest/CMakeLists.txt +++ b/features/frameworks/utest/CMakeLists.txt @@ -2,13 +2,14 @@ # SPDX-License-Identifier: Apache-2.0 target_include_directories(mbed-utest - INTERFACE + PUBLIC . utest + ../greentea-client ) target_sources(mbed-utest - INTERFACE + PRIVATE mbed-utest-shim.cpp source/unity_handler.cpp source/utest_case.cpp @@ -20,3 +21,5 @@ source/utest_stack_trace.cpp source/utest_types.cpp ) + +target_link_libraries(mbed-utest PUBLIC mbed-core-flags) diff --git a/hal/CMakeLists.txt b/hal/CMakeLists.txt index 8e1b090..3cd9f95 100644 --- a/hal/CMakeLists.txt +++ b/hal/CMakeLists.txt @@ -13,13 +13,13 @@ add_subdirectory(usb) -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE include include/hal ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE source/LowPowerTickerWrapper.cpp source/mbed_compat.c diff --git a/hal/usb/CMakeLists.txt b/hal/usb/CMakeLists.txt index 1215cf1..7c65775 100644 --- a/hal/usb/CMakeLists.txt +++ b/hal/usb/CMakeLists.txt @@ -1,13 +1,13 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE include include/usb ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE source/mbed_usb_phy.cpp ) diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt index 4831804..58be006 100644 --- a/platform/CMakeLists.txt +++ b/platform/CMakeLists.txt @@ -21,7 +21,7 @@ add_subdirectory(randlib) add_subdirectory(source) -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE include include/platform diff --git a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/CMakeLists.txt b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/CMakeLists.txt index 222bd82..b6e2016 100644 --- a/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/CMakeLists.txt +++ b/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/CMakeLists.txt @@ -20,7 +20,7 @@ src/psa_hrng.c ) -target_link_libraries(mbed-core +target_link_libraries(mbed-core-flags INTERFACE mbed-psa ) diff --git a/platform/cxxsupport/CMakeLists.txt b/platform/cxxsupport/CMakeLists.txt index f9b4651..c7a8a71 100644 --- a/platform/cxxsupport/CMakeLists.txt +++ b/platform/cxxsupport/CMakeLists.txt @@ -1,12 +1,12 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE . ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE mstd_mutex.cpp ) diff --git a/platform/mbed-trace/CMakeLists.txt b/platform/mbed-trace/CMakeLists.txt index 8ce7385..fb43e2d 100644 --- a/platform/mbed-trace/CMakeLists.txt +++ b/platform/mbed-trace/CMakeLists.txt @@ -3,13 +3,13 @@ add_subdirectory(source) -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE include include/mbed-trace ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE source/mbed_trace.c ) diff --git a/platform/source/CMakeLists.txt b/platform/source/CMakeLists.txt index 2067646..48adbb1 100644 --- a/platform/source/CMakeLists.txt +++ b/platform/source/CMakeLists.txt @@ -7,12 +7,12 @@ add_subdirectory(minimal-printf) -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE . ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE ATCmdParser.cpp CThunkBase.cpp @@ -50,7 +50,7 @@ ) if(MBED_TOOLCHAIN STREQUAL "GCC_ARM" AND MBED_C_LIB STREQUAL "small") - target_sources(mbed-core + target_sources(mbed-core-sources INTERFACE newlib_nano_malloc_workaround.c ) diff --git a/platform/source/TARGET_CORTEX_M/CMakeLists.txt b/platform/source/TARGET_CORTEX_M/CMakeLists.txt index 298fa20..d90dc31 100644 --- a/platform/source/TARGET_CORTEX_M/CMakeLists.txt +++ b/platform/source/TARGET_CORTEX_M/CMakeLists.txt @@ -1,9 +1,9 @@ # Copyright (c) 2020-2021 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -target_sources(mbed-core INTERFACE TOOLCHAIN_GCC/except.S) +target_sources(mbed-core-sources INTERFACE TOOLCHAIN_GCC/except.S) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE mbed_fault_handler.c ) diff --git a/platform/source/minimal-printf/CMakeLists.txt b/platform/source/minimal-printf/CMakeLists.txt index 4c31fb0..1855033 100644 --- a/platform/source/minimal-printf/CMakeLists.txt +++ b/platform/source/minimal-printf/CMakeLists.txt @@ -1,12 +1,12 @@ # Copyright (c) 2020 ARM Limited. All rights reserved. # SPDX-License-Identifier: Apache-2.0 -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE . ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE mbed_printf_armlink_overrides.c mbed_printf_implementation.c diff --git a/rtos/CMakeLists.txt b/rtos/CMakeLists.txt index 3f1f9f6..a126a93 100644 --- a/rtos/CMakeLists.txt +++ b/rtos/CMakeLists.txt @@ -9,7 +9,7 @@ endif() endif() -target_include_directories(mbed-core +target_include_directories(mbed-core-flags INTERFACE . ./include @@ -18,7 +18,7 @@ ./source ) -target_sources(mbed-core +target_sources(mbed-core-sources INTERFACE source/EventFlags.cpp source/Kernel.cpp @@ -30,7 +30,7 @@ ) -target_compile_definitions(mbed-core +target_compile_definitions(mbed-core-flags INTERFACE MBED_CONF_RTOS_API_PRESENT=1 ) diff --git a/tools/cmake/app.cmake b/tools/cmake/app.cmake index 5f78357..c51b1e1 100644 --- a/tools/cmake/app.cmake +++ b/tools/cmake/app.cmake @@ -13,6 +13,7 @@ include(${MBED_CONFIG_PATH}/mbed_config.cmake) include(mbed_set_post_build) include(mbed_generate_config_header) +include(mbed_create_distro) # Load toolchain file if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED) @@ -62,6 +63,3 @@ message(STATUS "Missing Python dependencies (python3, intelhex, prettytable) so the memory map cannot be printed") endif() -# load mbed_create_distro -include(${CMAKE_CURRENT_LIST_DIR}/create_distro.cmake) - diff --git a/tools/cmake/mbed_create_distro.cmake b/tools/cmake/mbed_create_distro.cmake index c4f396b..eb006b0 100644 --- a/tools/cmake/mbed_create_distro.cmake +++ b/tools/cmake/mbed_create_distro.cmake @@ -34,9 +34,6 @@ function(mbed_create_distro NAME) # ARGN: modules... add_library(${NAME} OBJECT EXCLUDE_FROM_ALL) - # First link as private dependencies - target_link_libraries(${NAME} PRIVATE ${ARGN}) - # Now copy include dirs, compile defs, and compile options (but NOT interface source files) over # to the distribution target so they will be passed into things that link to it. # To do this, we need to recursively traverse the tree of dependencies. @@ -51,6 +48,27 @@ copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME}) copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME}) + # Make sure that linking to the distro pulls in the compiled code from CURR_MODULE + target_link_libraries(${NAME} PRIVATE ${CURR_MODULE}) + + # CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries + # via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/. + # see: https://cmake.org/pipermail/cmake/2019-May/069453.html + # Once the INTERFACE_LINK_LIBRARIES_DIRECT property becomes widely available we could use that instead to fix this. + get_property(CURR_MODULE_TYPE TARGET ${CURR_MODULE} PROPERTY TYPE) + if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY") + target_sources(${NAME} INTERFACE $) + + # Check if this object library has any other libraries exported through its INTERFACE_SOURCES. + # If it does, we need to propagate those too. + get_property(OBJ_INTERFACE_SOURCES TARGET ${NAME} PROPERTY INTERFACE_SOURCES) + foreach(INTERFACE_SOURCE ${OBJ_INTERFACE_SOURCES}) + if(INTERFACE_SOURCE MATCHES "\\$") + target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE}) + endif() + endforeach() + endif() + list(REMOVE_AT REMAINING_MODULES 0) list(APPEND COMPLETED_MODULES ${CURR_MODULE}) @@ -58,8 +76,12 @@ get_property(SUBMODULES TARGET ${CURR_MODULE} PROPERTY INTERFACE_LINK_LIBRARIES) foreach(SUBMODULE ${SUBMODULES}) if(NOT "${SUBMODULE}" MATCHES "::@") # remove CMake internal CMAKE_DIRECTORY_ID_SEP markers - if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES) - list(APPEND REMAINING_MODULES ${SUBMODULE}) + # Remove LINK_ONLY genexes from target_link_libraries(... PRIVATE). We can ignore things wrapped in these + # because they will already have been handled by the target_link_libraries earlier on. + if(NOT "${SUBMODULE}" MATCHES "\\$") + if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES) + list(APPEND REMAINING_MODULES ${SUBMODULE}) + endif() endif() endif() endforeach() diff --git a/tools/cmake/mbed_greentea.cmake b/tools/cmake/mbed_greentea.cmake index 1c4df55..d02e253 100644 --- a/tools/cmake/mbed_greentea.cmake +++ b/tools/cmake/mbed_greentea.cmake @@ -78,13 +78,6 @@ return() endif() - # TODO: After we convert all greentea tests to use CTest, remove this - # add_subdirectory call. We will attach the tests to the mbed-os project, - # rather than creating a new project for each test that depends on mbed-os. - if(NOT BUILD_GREENTEA_TESTS) - add_subdirectory(${MBED_ROOT} build) - endif() - add_executable(${MBED_GREENTEA_TEST_NAME}) target_include_directories(${MBED_GREENTEA_TEST_NAME} @@ -119,6 +112,12 @@ set(MBED_GREENTEA_TEST_IMAGE_NAME "${MBED_GREENTEA_TEST_NAME}.bin") endif() + # User can set this cache variable to supply extra arguments to greentea. + # such as: -d to set the drive path, -p to set the COM port. + if(DEFINED MBED_GREENTEA_EXTRA_HTRUN_ARGUMENTS) + list(APPEND MBED_HTRUN_ARGUMENTS ${MBED_GREENTEA_EXTRA_HTRUN_ARGUMENTS}) + endif() + if(DEFINED MBED_GREENTEA_HOST_TESTS_DIR) list(APPEND MBED_HTRUN_ARGUMENTS "-e;${MBED_GREENTEA_HOST_TESTS_DIR}") endif() diff --git a/tools/cmake/mbed_set_linker_script.cmake b/tools/cmake/mbed_set_linker_script.cmake index 3a29b08..21855f0 100644 --- a/tools/cmake/mbed_set_linker_script.cmake +++ b/tools/cmake/mbed_set_linker_script.cmake @@ -6,6 +6,7 @@ # Called once for each MCU target in the build system. # function(mbed_set_linker_script input_target raw_linker_script_path) + set(LINKER_SCRIPT_PATH ${CMAKE_CURRENT_BINARY_DIR}/${input_target}.link_script.ld) # To avoid path limits on Windows, we create a "response file" and set the path to it as a # global property. We need this solely to pass the compile definitions to GCC's preprocessor,