InfiniTimeOrg / InfiniTime

Firmware for Pinetime smartwatch written in C++ and based on FreeRTOS
GNU General Public License v3.0
2.64k stars 907 forks source link

Added CMake changes to allow for project building and debugging on MacOS ARM processor #1741

Open p-riebs opened 1 year ago

p-riebs commented 1 year ago

I recently bought an ARM-based Mac and wasn't able to build or debug the InfiniTime project.

These changes allow the project to be built and debugged on ARM-based processors. Most of these changes are actually already in the cmake-nRF5x toolchain but aren't set early enough to fix the issues. My guess is most contributors are using Intel-based processors so these issues aren't being caught.

For example, the line:

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

is set below https://github.com/InfiniTimeOrg/InfiniTime/blob/main/cmake-nRF5x/arm-gcc-toolchain.cmake#L27-L32 but isn't added in the CMakeLists.txt until the end of the build process. https://github.com/InfiniTimeOrg/InfiniTime/blob/main/CMakeLists.txt#L74

From my research these lines need to be added before the project() line: https://github.com/InfiniTimeOrg/InfiniTime/blob/main/CMakeLists.txt#L5

I'm new to this so if there are any better ways or something I missed please let me know.

Sources: https://github.com/microsoft/vscode-cmake-tools/issues/662 https://gitlab.kitware.com/cmake/cmake/-/issues/23105 https://stackoverflow.com/a/12794195

github-actions[bot] commented 1 year ago
Build size and comparison to main: Section Size Difference
text 406440B -16B
data 940B 0B
bss 53560B 0B
Riksu9000 commented 1 year ago

I'm pretty sure people are able to compile InfiniTime on Pinebooks and raspberries. This might be related to #1540.

JF002 commented 1 year ago

On my setup (CLion on x86_64 computer), I need to add set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) at the top of the main CMake file to make CMake happy. I haven't tried to understand why though, since it's seems to be working fine for many other developers and also in the Docker container.

So I'm not sure those changes are specific to MacOS on ARM CPU.

@p-riebs could you test if adding only set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) is working on your setup?

Setting the system name to Linux (set(CMAKE_SYSTEM_NAME Linux)) does not feel right since we are not using Linux and build flags are managed in the src subfolder (https://github.com/InfiniTimeOrg/InfiniTime/blob/main/src/CMakeLists.txt#L776).

p-riebs commented 1 year ago

My knowledge of CMake is very limited here.

@JF002 I tried to move the set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) line to the top without any other changes and that still has the issue of -arch being automatically appended

arm-none-eabi-gcc: error: unrecognized command-line option '-arch'; did you mean '-march='?

Setting the CMAKE_SYSTEM_NAME to Generic fixes the issue. So Linux isn't necessary. (I'll update the PR if we find we want to merge this)

set(CMAKE_SYSTEM_NAME Generic)

@Riksu9000 - Moving the toolchain up in the CMakeList file would only require moving the line add_subdirectory(src) further up right? I tried that but wasn't successful.