Commit Graph

110 Commits (77f8a30749defdf3094d9731372cd6f095250566)

Author SHA1 Message Date
Robert Walton cfc68a0918 CMake: Use CMAKE_MODULE_PATH to locate nuvoton post build hook
We were previously relying on the global MBED_PATH variable to provide
the root for the include path to the post build hooks. We can't
guarantee that MBED_PATH will be set by any application building us, so
use CMAKE_MODULE_PATH (which we always set) like we do for the other
post-build hooks.
2021-08-11 10:15:42 +01:00
Robert Walton 2a12566c70 CMake: greentea: Set variables usually defined by external apps
We rely on external applications to set MBED_CONFIG_PATH and include
app.cmake. Mbed OS can't build for a target without those parameters
set. When building greentea tests there is no external application. So,
we define the appropriate settings in our root CMakeLists.txt for
greentea tests.
2021-08-10 16:37:48 +01:00
Robert Walton 7842320ab7 CMake: Add option to enable greentea tests
Add an option to enable the greentea tests independently from the unit
tests.

We can't just use the typical BUILD_TESTING option to enable greentea
tests. BUILD_TESTING enables unit tests and fetches googletest, which
are compiled for the host. Greentea tests are cross compiled and require
a toolchain file. For this reason we add a new option just to enable
greentea tests, preventing build failures triggered by the unit tests
and googletest.
2021-08-10 16:35:11 +01:00
Lingkai Dong 351680fb18 Rework post-build to support multiple executables
When building greentea tests, each test is an executable with its
own output binary path. This is also the case when a user project
produces multiple executables. But the current implementation of
post-build operations always assumes there's only one executable,
at the root of the build directory.

The post-build command depends on Mbed target, and it always takes
the the executable we build as an input file. To achieve this, we
let each Mbed target (that has a post-build command) define a function

    function(mbed_post_build_function target)

which takes a CMake executable target as an argument from which it can
get its binary path using generator expressions. It generates and adds
to the passed executable target a post-build custom command.

Notes:
* The function name needs to be exact, because CMake only supports
literal function calls - CMake can't dereference a function name from
a variable. To avoid multiple definitions of this function, each Mbed
target needs to guard it with a macro to check if the user is
building this Mbed target.
* `mbed_post_build_function()` is a function, but it is usually
defined by another macro rather than a parent function, because
nesting functions would make many variables inaccessible inside the
innermost `mbed_post_build_function()`.
* There's no more need to force regenerate images. Previously, post-
build commands were custom *targets* which always got to run, so we
force regenerated images on every build to avoid patching an image
that's already been patched once on previous build. Now post-build
commands are custom *commands* of the same executable target, and they
are only run if the executable target itself is rebuilt.
2021-07-22 17:31:22 +01:00
Robert Walton fcd57b24d3 CMake: Move post build functions out of root CMakeLists.txt
The 'post build' functions are made visible by adding the mbed-os
subdirectory. This is not ideal as any components in mbed-os wishing to
call the functions must be added after the functions are defined. To
improve modularity move these functions to a separate CMake script.

We include the post build CMake script in app.cmake for now so we don't
break user's projects.
2021-07-22 11:50:43 +01:00
Martin Kojtal 8a507e651e
Merge pull request #14870 from ARMmbed/move_rtos_stub_headers
CMake: Remove mbed-stubs-rtos-headers library
2021-07-09 10:33:49 +02:00
Rajkumar Kanagaraj bb3cd37a5e CMake: Remove mbed-stubs-rtos-headers library
- Previous changes moved all rtos stubs headers into mbed-stubs-rtos-headers
lib, but the decision to keep all stubs headers under the respective
component stubs library so moved all stubs rtos headers under
mbed-stubs-rtos and updated it depend component CMake
- Remove unnecessary add_definition call for UNITTEST as any of the stubs library
added from UNITTEST/CMakeLists.txt is not required this macro
2021-07-08 07:14:56 -07:00
Jaeden Amero ef07746443 cmake: Set MBED_TEST_MODE with INTERFACE
Set MBED_TEST_MODE with INTERFACE. Use INTERFACE because mbed-os is an
interface target, and we can only set INTERFACE properties on interface
targets. This helps avoid the following error when building an
application.

    CMake Error at mbed-os/CMakeLists.txt:96 (target_compile_definitions):
      target_compile_definitions may only set INTERFACE properties on INTERFACE
        targets
2021-07-07 14:29:14 +01:00
Jaeden Amero 20f6b5270f Add external greentea-client dependency
Use FetchContent to obtain greentea-client at version XXX.
2021-07-07 14:29:14 +01:00
Robert Walton eb733925dc CMake: Remove trailing whitespace from CMakeLists.txt 2021-06-10 23:24:32 +01:00
Hugues Kamba ebf495006e CMake: Remove forgotten debug message
A debug message to display the selected toolchain was left in
the main CMakeLists.txt file. This commit removes it.
2021-05-26 17:40:09 +01:00
Anna Bridge 4e586a93d3
Merge pull request #14426 from ARMmbed/feature_unittest_refactor
CMake: Refactor UNITTESTS CMake
2021-05-24 13:04:22 +01:00
Rajkumar Kanagaraj 6d4caad83d CMake: Move CMAKE_CROSSCOMPILING check inside library CMake 2021-05-20 06:26:10 -07:00
Robert Walton ccb49b506d CMake: Only force Ninja response files on Windows
We force Ninja to create response files to work around file path length
limitations on Windows. Previously we were forcing the response file
generation for all platforms, unless we were building on Windows using
ARMClang, this was to work around a CMake issue
https://gitlab.kitware.com/cmake/cmake/-/issues/21093

Unfortunately `ar` on macOS doesn't support Ninja response files. So the
check was incorrect, as forcing a response file to be generated on macOS
causes a build failure when trying to build Mbed's unit tests.

This PR changes the logic so we only generate a response file on Windows
systems if we're not building with ARMClang.
2021-05-11 13:26:12 +01:00
Rajkumar Kanagaraj f096b3b3c3 Fix missing newline 2021-05-11 04:22:26 -07:00
Rajkumar Kanagaraj a88f43f367 CMake: Update mbed os, unittest CMake and add CMAKE_CROSSCOMPILING guard
- Add a new MbedOS project in mbed os root CMake which can be used along with
  BUILD_TESTING conditional check for enabling the unittest build
- Update UNITTEST CMake for setting the CMake configuration like c, cxx flags etc.,
- Add if CMAKE_CROSSCOMPILING conditional check wherever target configuration check
  and toolchain configuration to avoid such configuration gets included for unittest build.
2021-05-11 02:49:03 -07:00
harmut01 fa1d9c059d Cmake: Add backward compatibilty support for MBED_TEST_MODE
Fixes #14494

MBED_TEST_MODE is required for backward compatibilty with CLI1. This
adds a test to ensure that the macro is created when using CLI2 for
testing. This also adds a test in `.travis.yml` that checks whether
CMake defines the macro when BUILD_TESTING is on.

CLI1 Reference: https://os.mbed.com/docs/mbed-os/v6.9/debug-test/greentea-for-testing-applications.html

Also, explicitly create and set the macro BUILD_TESTING to allow for
MBED_TEST_MODE to be defined by CMake. MBED_TEST_MODE is required for
backward compatibilty with CLI1.  BUILD_TESTING is used to determine
whether to define MBED_TEST_MODE.  Normally, this would be automatically
done by CTest (which we intend to add for test automation) but this
hasn't yet been added to our Greentea tests.
2021-04-28 14:21:33 +01:00
Martin Kojtal 121c8286da CMake: set CMAKE_MODULE_PATH in the Mbed OS CMakelists.txt
Update CMAKE_MODULE_PATH at once place.

Note, we update also CMAKE_MODULE_PATH in app.cmake. This is temporary until we get a proper way to include
Mbed Os (removing app.cmake need to be included by an application).
2021-04-14 13:09:28 +01:00
Martin Kojtal 65e246fe4d CMake: add mbed_ prefix to our CMake files
To avoid conflicts as we expose our CMake list files via CMAKE_MODULE_PATH. Some files already include it, this
aligns the rest of files.

I leave app.cmake as it is - it's user facing and it would be breaking change. We can clean this one for the next major version.
2021-04-14 13:09:27 +01:00
Martin Kojtal b88d5687e2 CMake tools: use CMAKE_CURRENT_LIST_DIR instead of MBED_PATH
Excluding greentea tests, they will be fixed separately (more work needed).
2021-04-14 13:09:27 +01:00
Martin Kojtal 1413c42410 CMake: use project name for Mbed OS
This enables multiple variables we can use. One of them is source dir for a project.

It will replace MBED_PATH in the tree.
2021-04-08 13:25:02 +01:00
Lingkai Dong 45a3c7193f CMake: Image format based on MBED_OUTPUT_EXT
Requires: https://github.com/ARMmbed/mbed-tools/pull/242

The optional `OUTPUT_EXT` field in Mbed OS `targets.json` specifies
the format of the output image. This is important because
* some targets only support one image format
* each post-binary hook outputs one image only

This avoids confusion of having both .hex and .bin images generated
while only one of them is usable.
2021-03-25 12:52:59 +00:00
Lingkai Dong ad27a3ec69 CMake: pass application name to post-build hook
Pass the exact name to the post-build hook, when an application's
or test's `CMakeLists.txt` calls `mbed_set_post_build()`. The
interface is CMake's built-in mechanism:
* `set_target_properties()` to set a property, e.g. application name
* `$<TARGET_PROPERTY:target,property>` to query a property at run time
2021-03-04 09:41:48 +00:00
Lingkai Dong 3579bb65da Force regenerate application binaries on rebuild
If a target has a post binary hook, we should force regenerate
the application binaries every time so that the hook is run on a
raw binary rather than a previous build that already went through
the post-build process once.
2021-03-04 09:41:43 +00:00
Ladislas de Toldi fd7ea7305f
Configure memory map per target to allow multiple add_executable 2021-02-27 13:16:03 +01:00
Martin Kojtal eceaea54fd
Merge pull request #14299 from hugueskamba/hk_cmake_refactor_mapfile_generation
CMake: Refactor mapfile generation
2021-02-25 15:08:55 +00:00
Martin Kojtal 7da6100ff6
Merge pull request #14304 from hugueskamba/hk_cmake_remove_app_target_reference
CMake: Refactor post-build hook to remove APP_TARGET references
2021-02-25 10:41:44 +00:00
Hugues Kamba ed09a5cc95 CMake: Refactor mapfile generation
The refactoring was necessary to remove a function call
(mbed_configure_app_target()) from application's CMakeLists.txt.
2021-02-23 11:39:00 +00:00
Hugues Kamba 0eae4f6c3f CMake: Refactor post-build hook to remove APP_TARGET references
There should not be a reference to APP_TARGET in Mbed OS as end-users
may decide to use a different name for the CMake variable to store their
application name.
2021-02-19 11:52:57 +00:00
Martin Kojtal 546cdafbd9
CMake: remove debug print 2021-02-17 16:50:13 +00:00
Martin Kojtal 8bdc626ba7
Merge pull request #14286 from 0xc0170/cmake-fix-remove-target-workaround
CMake: remove workaround for targets prior refactor
2021-02-16 14:28:26 +00:00
Martin Kojtal 3894d73680
Merge pull request #14289 from hugueskamba/hk_cmake_refactor_cypress
CMake: Refactor Cypress targets
2021-02-16 13:43:35 +00:00
Hugues Kamba 68b6e6ff96 Fix post build mechanism with unique CMake custom targets
The CMake custom target must be unique to avoid more than one
Mbed target adding the same. Only the CMake custom command added for the
Mbed target being built is run as the custom CMake target now includes
the Mbed target name.
2021-02-15 17:39:27 +00:00
Martin Kojtal 9d70cb2a56 CMake: remove workaround for targets prior refactor
As we refactored all targets, we can remove this workaround from the tree.
2021-02-15 14:11:09 +00:00
Robert Walton 0c7bfe93e3 CMake: Generate response file before adding mbed-targets
We need to generate a "response file" to pass to the C preprocessor
when we preprocess the linker script, because of path length limitations
on Windows. We set the response file and bind the path to a global
property. The MBED_TARGET being built queries this global property when
it sets the linker script.

We must set this global property before the targets subdirectory is
added to the project. This is required because the MBED_TARGET depends
on the response file. If the path to the response file is not defined
when the target requests it the config definitions will not be passed
to CPP.
2021-02-15 11:12:18 +00:00
Martin Kojtal ba1e7b53d0
Merge pull request #14272 from ladislas/ladislas/feature/cmake-current-binary-dir
Change CMAKE_BINARY_DIR to CMAKE_CURRENT_BINARY_DIR
2021-02-14 19:23:46 +00:00
Ladislas de Toldi 5a879c6a4e
Change CMAKE_BINARY_DIR to CMAKE_CURRENT_BINARY_DIR 2021-02-11 22:49:07 +01:00
Hugues Kamba deeaa7970f CMake: Add post build operation support
A CMake custom target, mbed-post-build, is added as a dependency of the
application CMake target if a Mbed target adds a CMake custom target
named mbed-post-build-bin. mbed-post-build-bin is added as a dependency
of mbed-post-build. mbed-post-build-bin depends on the application binary.
This is done so a CMake custom command that executes post-build can be added.

The Python scripts that implement the operations have been modified to add
CLI entry points so they can be called from CMake. Dependency on the old
tool has been removed on those scripts by passing them exactly what they
require instead of passing old tool Python objects. A consequence of that
was to slightly amend how the old tool calls some of those Python modules.

Support has only been added for Mbed targets that currently have a requirement
for post build operations. This includes: LPC1114, LPC1768, ARCH_PRO, LPC54114,
LPC546XX, FF_LPC546XX, CY8CKIT064B0S2_4343W, CYTFM_064B0S2_4343W, CYSBSYSKIT_01

The following targets are not supported as TFM support is not yet included:
ARM_MUSCA_B1, ARM_MUSCA_B1_NS, ARM_MUSCA_S1, ARM_MUSCA_S1_NS.
2021-02-11 17:04:41 +00:00
Martin Kojtal 33c06fb346
Merge pull request #14265 from 0xc0170/cmake-fix-app-target
CMake: remove need for APP_TARGET
2021-02-11 11:49:16 +00:00
Martin Kojtal 207dcbb88b CMake: move Gcc Arm memmap to configure app
This allows us to keep all in one place and fix (removing this function later)
2021-02-10 19:37:42 +00:00
Martin Kojtal b9990089eb
CMake: fix wording in naming
Co-authored-by: Hugues Kamba <41612201+hugueskamba@users.noreply.github.com>
2021-02-10 12:15:48 +00:00
Martin Kojtal d22772342c CMake: linker script preprocessing moved to mbed_configure_app_target
This fixes the problem for an app/test to define APP_TARGET as requirements. This is not a proper fix
but rather a workaround for broken apps/tests currently. We will address this separately via new
pull request.
2021-02-10 11:32:08 +00:00
Martin Kojtal b3344390dd CMake: move language standard to mbed-core
We set language standard via mbed-core and app inherits it if links to it.
This is breaking change for application, please remove the function call from an
application and it should build without errors.
2021-02-10 11:31:50 +00:00
Martin Kojtal 4536a5efe5
Update CMakeLists.txt
Co-authored-by: Hugues Kamba <41612201+hugueskamba@users.noreply.github.com>
2021-02-10 08:46:25 +00:00
Martin Kojtal e88e1149e2 CMake: fix the comment for naming targets 2021-02-09 17:12:23 +00:00
Martin Kojtal 39ab9c8b99 CMake: add naming convention for mbed targets
Using lowercase with dashes for targets with mbed- prefix
2021-02-09 15:23:17 +00:00
Martin Kojtal dd33463518
Merge pull request #14205 from multiplemonomials/master
CMake: better detection of memap dependencies
2021-02-05 10:13:18 +00:00
Robert Walton 0e491cc0cf cmake: Refactor mbed_set_mbed_target_linker_script
Move the mbed_set_mbed_target_linker_script function into its own file
and make it set the linkerscript on the target passed in, rather than
setting the linkerscript on the top level mbed-core target. We use
CMake's automatic forwarding of usage requirements to forward the linker
script to the top level target.

This commit also adds a condition to check whether the MBED_TARGET is a
CMake buildsystem target. If it is we will just link to it in the
idiomatic CMake way, if it's not then we use the 'old' mechanism of
setting the linkerscript for the mbed-core target. This check will be
useful when we refactor MBED_TARGETS to be CMake buildsystem targets as
it will allow us to do the refactoring incrementally.
2021-02-04 15:26:33 +00:00
Robert Walton 8f47212085 cmake: Remove whitespace from mbed-os/CMakeLists.txt 2021-02-04 15:23:49 +00:00
Jamie Smith 029486e640 Add FindPythonPackage and use it to detect memap dependencies 2021-02-03 14:11:53 -08:00