-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_VERSION #39
Add CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_VERSION #39
Conversation
Hmm. I'm a little concerned about setting these to generic values without knowing the side effects. Although it does look like this builds just fine on my local machine (MacOS 12.1). As both variables are defined as the target system name and target system version (respectively), I suggest we align these with the actual build target we're using, so CMAKE_SYSTEM_NAME would be set to "micro:bit" and CMAKE_SYSTEM_VERSION set to "2.0.0", this way if we ever need to rely on these in the future, then they're already set to appropriate values (and other platforms can adjust these to match, as required; rp2040, for example) I've tested these locally and they seem fine here, but I don't have a Windows box to hand to double check (although hopefully the CI actions will catch this if it breaks on Windows or Linux systems). |
Maybe I am missunderstanding this, but is the problem that without setting these values the build system is trying to build for macOS Arm instead of arm-none-eabi? |
Thanks @JohnVidler and @microbit-carlos Yes, the errors I was getting look like it's trying to build for my mac, and setting CMAKE_SYSTEM_NAME to anything enabled a cross-platform build, because CMAKE_SYSTEM_NAME != CMAKE_HOST_SYSTEM_NAME I backed off from a specific name because of the messages like
I don't know what triggers the problem, only that defining Generic worked without the messages and the built hex was identical to my windows build. Maybe cmake was newer or doesn't recognise M1 macs properly? After another look around, I found https://gitlab.kitware.com/cmake/cmake/-/issues/21489 |
This looks relevant: https://gitlab.kitware.com/cmake/cmake/-/issues/23105 |
Looks like this was also the way Yotta was setting up CMake 🤔: https://github.com/ARMmbed/target-mbed-gcc/blob/master/CMake/toolchain.cmake#L12 Is this a common configuration/pattern for CMake cross-compilation? Looks like "Generic" is probably what we would need to set up anyway for embedded targets. |
@microbit-carlos Good spot! I added a question.
I thought I understood, but I don't see a "mbedOS.cmake" in https://gitlab.kitware.com/cmake/cmake/-/tree/v3.22.0-rc2/Modules/Platform. I'm now worried about missing all the configurations in Darwin.cmake or Windows.cmake. I have problems starting a clean build from an XCode script, as opposed to using Terminal, which I haven't looked into yet. |
Right, sorry, I didn't expect mbedOS to be in the "official" CMake list of platforms, but I was wondering if setting that value to something not official (so something that doesn't have any additional config files in that directory from the CMake repo) was a common pattern to set up a "clean empty platform" for embedded targets. Based on the link that you posted, https://gitlab.kitware.com/cmake/cmake/-/blob/v3.22.0-rc2/Modules/Platform/Generic.cmake, the "Generic" platform is pretty close to empty, so it seems like it's their recommended value for embedded platforms like us? Rather than have "micro:bit" string and have a warning issued in all builds. Thanks for asking about possible repercussion in that thread in the issue tracker, it'd be interesting to hear back from CMake.
What files do you mean, from the CMake project like this one? https://gitlab.kitware.com/cmake/cmake/-/blob/v3.22.0-rc2/Modules/Platform/Darwin.cmake I would think those are targeting builds to run on macOS or Windows. Or do you mean other files from places like the Yotta repos? |
No, no! Nothing to be sorry for! I was thinking that has to be an official Platform.
I think so too, but if not specified, CMAKE_SYSTEM_NAME == CMAKE_HOST_SYSTEM_NAME == Darwin on macOS, so I was thinking Darwin.cmake gets used, but I expect I'm wrong! |
Thanks to both of you for digging into this some more. I'm mostly just concerned about CMake setting any other internal variables based on the value we set in these variables (and doing so invisibly) which might break the build.
So is that a CMake bug, or the expected behaviour and the other hosts just aren't as picky as M1-based kit? |
I don't know, but I think It's a bit of both! See https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html and https://gitlab.kitware.com/cmake/cmake/-/issues/23105 It was working before I tried M1. Defining CMAKE_SYSTEM_NAME let me compile the hex on my M1 and didn't change my Windows built hex. My guess now is that set(CMAKE_SYSTEM_NAME Generic) is a workaround for a CMake bug on M1s, and maybe the default behaviour will be the best bet once the bug is fixed. set(CMAKE_SYSTEM_NAME "micro:bit") might not be a good choice as I think it's used as a filename. |
Based solely on the comment at the top of the generic system config file, it sounds to me like this is the blessed way to build for embedded targets?
|
This is also helpful... https://cmake.org/cmake/help/book/mastering-cmake/chapter/Cross%20Compiling%20With%20CMake.html "CMAKE_SYSTEM_NAME This variable is mandatory... If your target is an embedded system without an OS, set CMAKE_SYSTEM_NAME to “Generic.”" ... contradicting my last thought! :) |
Very good point, I forgot that it just uses it as a lookup in the list of targets - this would make it break on Windows targets (among others), I think, where you can't have colons in filenames.
That does leave |
See confirmation in https://gitlab.kitware.com/cmake/cmake/-/issues/23105#note_1110216 I think using Generic and 2.0.0 sounds fine. Should anything unhelpful happen in Generic, I suppose the yotta example shows how to use a local custom platform. |
On M1 mac, I see errors like:
This seems to be fixed by the magic of defining CMAKE_SYSTEM_NAME in ARM_GCC/toolchain.cmake. It doesn't seem to matter what CMAKE_SYSTEM_NAME is defined as.
The cmake docs (https://cmake.org/cmake/help/v3.20/variable/CMAKE_SYSTEM_NAME.html) suggest CMAKE_SYSTEM_VERSION must be defined too, though leaving it out doesn't appear to cause a problem.
Adding these definitions doesn't upset the Windows build. The MICROBIT.hex is unchanged and the same on mac as windows.
I'm building with cmake 3.20.5 and arm-none-eabi 10.2.1.