-
Notifications
You must be signed in to change notification settings - Fork 3k
CMake: remove MBED_PATH and use <PROJECT-NAME>_SOURCE_DIR/MODULE_PATH instead #14516
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
Conversation
This enables multiple variables we can use. One of them is source dir for a project. It will replace MBED_PATH in the tree.
@0xc0170, thank you for your changes. |
@rwalton-arm @rajkan01 Please review |
To do once approved:
|
@0xc0170 Instead of going with |
The current way it is to explicitly use mbed-os project name as a reference rather than the last/current project name. Wouldn't this be a problem when Mbed OS is taken as a component or we have multiple projects in the tree ? |
@@ -3,10 +3,10 @@ | |||
|
|||
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) | |||
|
|||
set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../.. CACHE INTERNAL "") | |||
set(mbed-os_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../.. CACHE INTERNAL "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a current implementation, every greentea test has its CMakeLists.txt similar to the application CMake. Why do we need to change into mbed-os_SOURCE_DIR
? this will be a problem when we do "Separate GreenTea from Mbed"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, this is setting it. I missed it during refactoring, I'll remove all
In the case of mbed os is taken as a component or multiple projects in the tree, how the way the CMake file gets included decides the PROJECT_NAME but mbed-os root CMake retains PROJECT_NAME as a mbed-os, but it will be a problem |
set(TEST_TARGET mbed-connectivity-ble-cordio-hci-driver) | ||
|
||
include(${MBED_PATH}/tools/cmake/mbed_greentea.cmake) | ||
include(${mbed-os_SOURCE_DIR}/tools/cmake/mbed_greentea.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed to comment here, Do we need to change this as well because if it is top-level CMake similar to application one then PROJECT_NAME and CMAKE_PROJECT_NAME will be mbed-connectivity-ble-cordio-hci-driver
and the mbed-os_SOURCE_DIR
variable is not yet created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test should not care where it is.
How we create greentea shall be changed and this MBED_PATH should be fixed there. I'll create a separate issue for greentea tests, how they use MBED_PATH and get mbed-os in. I'll revert the changes here.
I'll keep this to fix the Mbed OS files (excluding greentea tests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #14523 and I'll revert now greentea tests changes.
2e4ce1c
to
25c5de3
Compare
Updated, greentea tests removed from this PR. They need different fix unfortunately. |
tools/cmake/mbed_greentea.cmake
Outdated
@@ -3,7 +3,7 @@ | |||
|
|||
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "") | |||
|
|||
include(${MBED_PATH}/tools/cmake/app.cmake) | |||
include(${mbed-os_SOURCE_DIR}/tools/cmake/app.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix this as part of #14523? and revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1,7 +1,7 @@ | |||
# Copyright (c) 2020-2021 ARM Limited. All rights reserved. | |||
# SPDX-License-Identifier: Apache-2.0 | |||
|
|||
include(${MBED_PATH}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake) | |||
include(${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/mbed_set_post_build_tfm.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we can use CMAKE_MODULE_PATH to avoid hard coding all of the include paths. We could set the module directories in mbed-os/CMakeLists
and then include modules with e.g include(mbed_set_post_build_tfm)
in other files. The benefit of this approach, in my view, is if we ever move the location of these files we will have fewer changes to make.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, I'll check how we can create the modules for our scripts
@@ -17,7 +17,7 @@ function(mbed_post_build_tfm_sign_image | |||
set(mbed_target_name ${mbed_target}) | |||
set(post_build_command | |||
COMMAND ${Python3_EXECUTABLE} | |||
${MBED_PATH}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py | |||
${mbed-os_SOURCE_DIR}/platform/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_TFM_LATEST/scripts/generate_mbed_image.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this not be reduced to ${CMAKE_CURRENT_LIST_DIR}/generate_mbed_image.py
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are in the targets area, not in the tools so current list dir points to targets/ somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, this path is incorrect. I'll fix it.
tools/cmake/app.cmake
Outdated
@@ -12,11 +12,11 @@ include(${MBED_CONFIG_PATH}/mbed_config.cmake) | |||
# Load toolchain file | |||
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED) | |||
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "") | |||
include(${MBED_PATH}/tools/cmake/toolchain.cmake) | |||
include(${mbed-os_SOURCE_DIR}/tools/cmake/toolchain.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, fixed in the later commit.
tools/cmake/app.cmake
Outdated
endif() | ||
|
||
# Specify available build profiles and add options for the selected build profile | ||
include(${MBED_PATH}/tools/cmake/profile.cmake) | ||
include(${mbed-os_SOURCE_DIR}/tools/cmake/profile.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${CMAKE_CURRENT_LIST_DIR}/profile.cmake
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, fixed in the later commit.
tools/cmake/mbed_greentea.cmake
Outdated
@@ -3,7 +3,7 @@ | |||
|
|||
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "") | |||
|
|||
include(${MBED_PATH}/tools/cmake/app.cmake) | |||
include(${mbed-os_SOURCE_DIR}/tools/cmake/app.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${CMAKE_CURRENT_LIST_DIR}/app.cmake
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, fixed in the later commit. I realized we should use list dir in tools
tools/cmake/profile.cmake
Outdated
@@ -29,4 +29,4 @@ else() | |||
endif() | |||
endif() | |||
|
|||
include(${MBED_PATH}/tools/cmake/profiles/${LOWERCASE_CMAKE_BUILD_TYPE}.cmake) | |||
include(${mbed-os_SOURCE_DIR}/tools/cmake/profiles/${LOWERCASE_CMAKE_BUILD_TYPE}.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${CMAKE_CURRENT_LIST_DIR}/profiles/${LOWERCASE_CMAKE_BUILD_TYPE}.cmake
?
tools/cmake/app.cmake
Outdated
@@ -12,11 +12,11 @@ include(${MBED_CONFIG_PATH}/mbed_config.cmake) | |||
# Load toolchain file | |||
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED) | |||
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "") | |||
include(${mbed-os_SOURCE_DIR}/tools/cmake/toolchain.cmake) | |||
include(${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see you changed these in a later commit. It would be easier to review if we didn't make changes to already reviewed commits later on in the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not want to push force while it's being reviewed but I can clean it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be easier to review if we didn't make changes to already reviewed commits later on in the PR.
I do not follow. I fixed earlier commit in the subsequent one. how else can I make review easier without rebasing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually would force push, but marking them as fixup
commits would also work for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for force push but that is hard for some reviewers so I can mark as fixu and later rebase to get them out of history.
Jenkins CI Test : ❌ FAILEDBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Errors are legit, I'll fix them |
b16a3b1
to
3abf9d5
Compare
- list files included via module path - <project-name>_SOURCE_DIR for sources that are out of the current processed CMake - CMAKE_CURRENT_LIST_DIR for listfiles
As we still use target labels, TFM is not visible to CMake. Protect include of their scripts with the same mechanism.
Excluding greentea tests, they will be fixed separately (more work needed).
All files within tools/cmake can now include within tools/cmake. We do not expose internal folders like core/profiles/toolchains. They should be included via toolchain file (mbed_toolchain in our case).
CMAKE_CURRENT_LIST_DIR behaves differently in functions. We store it in the CMakeLists itself, so anyone calling a function would get the actual list dir where the scripts are. To illustrate: if I call a function from src/CMakelists.txt, function located in src/scripts, `CMAKE_CURRENT_LIST_DIR` in the function would point to the src/ folder but not to src/scripts.
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.
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).
3abf9d5
to
121c828
Compare
I fixed an issue with TFM. I can't still build MUSCA though - a path in python script is incorrect. :/ I'll find out what has changed. |
CI started, I would like to see if it can reproduce my testing locally and if so will compare the logs. |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Jenkins CI Test : ✔️ SUCCESSBuild Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
@rajkan01 I'll merge this now, you can update unittests to remove using |
Summary of changes
This PR is helping UNITTESTS so it should be merged prior #14426 - they need to use files within Mbed OS and already defines
project()
.We used MBED_PATH previously, it's own defined variable for Mbed OS project root. Usage were to reference CMake scripts or files out of it's current source tree.
The approach should be to use cmake module path for listfiles like .cmake to find them. Note, due to our target labels, some CMake files are hidden so
include
must be also protected if it touches conditionally added library (for instance TFM).For CMakeLists.txt files, use
mbed-os_SOURCE_DIR
- this is useful for CMakeLists.txt. For listfiles like .cmake files, please use CMAKE_CURRENT_LIST_DIR (as they are included).Impact of changes
Migration actions required
Documentation
Pull request type
Test results
Reviewers