doctor64 / tuyaZigbee

Replacement firmwares for TuYa zigbee devices
Apache License 2.0
142 stars 20 forks source link

Add cmake install for sdk and toolchain #17

Closed vondraussen closed 8 months ago

vondraussen commented 9 months ago

Update sdk installation readme Add Windows build action Add Linux build action

vondraussen commented 9 months ago

@doctor64 Sorry for the mess 😄 old PR was closed due to deletion of my branch...

This is now building on Windows and Ubuntu. I've also tested this locally.

Actions can be viewed here: https://github.com/vondraussen/tuyaZigbee/actions/runs/7930986131 This doesn't include IAsensor but the PR actually does include it. I saw that you added the missing header file and updated the PR.

doctor64 commented 8 months ago

Hi @vondraussen Sorry for delayed reply, I was overloaded by, you know, real life :) I tried your PR and, unfortunately, it is not work for me. I try to configure build and got:

$ cmake -DSDK_PREFIX=$(pwd)/../TelinkZSDK3686/tl_zigbee_sdk -DTOOLCHAIN_PREFIX=/opt/tc32 -B build -S .                         
CMake Error at IASsensor/CMakeLists.txt:206 (ADD_BIN_TARGET):
  Unknown CMake command "ADD_BIN_TARGET".

-- Configuring incomplete, errors occurred!

I fixed this by changing line 56 in cmake/Toolchain.cmake from:

function(add_bin_target TARGET TOOLS_PATH)

to

function(ADD_BIN_TARGET TARGET TOOLS_PATH)

But, this bring another error

$ cmake -DSDK_PREFIX=$(pwd)/../TelinkZSDK3686/tl_zigbee_sdk -DTOOLCHAIN_PREFIX=/opt/tc32 -B build -S .
-- Running on Linux/MacOS host
-- Found Python3: /usr/bin/python3.11 (found version "3.11.6") found components: Interpreter 
-- Running on Linux/MacOS host
-- The C compiler identification is unknown
-- The ASM compiler identification is unknown
-- Found assembler: /home/doctor64/HDProjects/zigbee/tuyaZigbee/build/tc32/bin/tc32-elf-gcc
CMake Error at CMakeLists.txt:4 (PROJECT):
  The CMAKE_C_COMPILER:

    /home/doctor64/HDProjects/zigbee/tuyaZigbee/build/tc32/bin/tc32-elf-gcc

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.

CMake Error at CMakeLists.txt:4 (PROJECT):
  The CMAKE_ASM_COMPILER:

    /home/doctor64/HDProjects/zigbee/tuyaZigbee/build/tc32/bin/tc32-elf-gcc

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "ASM" or the CMake cache entry CMAKE_ASM_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

-- Warning: Did not find file Compiler/-ASM
-- Configuring incomplete, errors occurred!

Unfortunately, I'm unable to fix this fast. Please, can you take a look?

vondraussen commented 8 months ago

Hi @doctor64, can you please do the following steps (no changes needed)? If this works for you, I'll update docs/linux_build.md

Setting the paths to SDK and Toolchain is not needed anymore with this PR. It is done in cmake/Toolchain.cmake file.


Linux Build

Get Linux Toolchain and Zigbee SDK

mkdir build && cd build && cmake -P ../cmake/TelinkSDK_Linux.cmake
cd ..

Configure Build

cmake . -B build

Perform Project Build

cmake --build build --target IASsensor.zigbee
doctor64 commented 8 months ago

I tested with provided commands. It is working, generated binary successfully flashed and works. It will be Ok for release builds, but I need to ask you to allow manual configuration for paths for SDK and compiler. Sometimes I need to test compilation with different versions of SDK and sometimes I need to patch some files inside SDK for debug. As far as I understand, second step cmake . -B build use predefined paths for SDK and compiler? Can you make it configurable? Otherwise, great work, and thank you very much for your efforts.

vondraussen commented 8 months ago

It is still possible to set the paths manually by doing:

cmake . -B build -DTOOLCHAIN_PREFIX=~/opt/tc32 -DSDK_PREFIX=~/opt/tl_zigbee_sdk

You might need to remove CMakeCache.txt before.

doctor64 commented 8 months ago

Excellently working locally, merging the PR. Thank you very much for your work!