Buildsystem (idf.py) - add custom command

bennyslbs
Posts: 6
Joined: Tue Jul 14, 2020 8:00 am

Buildsystem (idf.py) - add custom command

Postby bennyslbs » Thu Jul 30, 2020 7:05 am

Hi,
I would like to add custom command for generating a source file, and added the following to main/CMakeLists.txt

add_custom_command(OUTPUT version.c
COMMAND ../tools/get_version.py > version.c
DEPENDS ../.git/HEAD ../.git/index
COMMENT Generates version.c from Git version
)

But I get the error:
xtensa-esp32-elf-gcc: error: ../main/version.c: No such file or directory

Tool:
ESP-IDF: release-4.0
Buildsystem: "New" idf.py based

Br,
Benny

ESP-Marius
Posts: 74
Joined: Wed Oct 23, 2019 1:49 am

Re: Buildsystem (idf.py) - add custom command

Postby ESP-Marius » Thu Jul 30, 2020 10:15 am

The path you give for version.c is probably not correct.

add_custom_command by default creates a file relative to the current binary directory, but ../main/version.c seems to expect to find it in your main folder.

bennyslbs
Posts: 6
Joined: Tue Jul 14, 2020 8:00 am

Re: Buildsystem (idf.py) - add custom command

Postby bennyslbs » Tue Aug 11, 2020 8:12 am

The path is wrong, but get_version.py is not even called, (nothing from get_version.py printed on STDOUT or fails if contains errors)

Extra:
CMake has some PROJECT_VERSION (https://cmake.org/cmake/help/v3.0/command/project.html).
It prints Project version first time after committing, but does not detect when a project goes dirty:
-- Detecting CXX compile features - done
-- Project version: v4.0.1-197-g94d97499a
-- Building ESP-IDF components for target esp32

But I can't access PROJECT_VERSION in c-code even after
add_definitions( -DPROJECT_VERSION=${PROJECT_VERSION} )
or
set(PROJECT_VERSION ${PROJECT_VERSION})

bennyslbs
Posts: 6
Joined: Tue Jul 14, 2020 8:00 am

Re: Buildsystem (idf.py) - add custom command

Postby bennyslbs » Thu Aug 13, 2020 8:11 am

This does not answer how to generate version.c, but is better solution

Variable PROJECT_VER (https://docs.espressif.com/projects/esp ... properties)

The version of firmware is stored in the firmware and can be extracted for both running and new (OTA) firmware, see
https://github.com/espressif/esp-idf/bl ... _example.c.

ESP-Marius
Posts: 74
Joined: Wed Oct 23, 2019 1:49 am

Re: Buildsystem (idf.py) - add custom command

Postby ESP-Marius » Thu Aug 13, 2020 8:50 am

bennyslbs wrote:
Tue Aug 11, 2020 8:12 am
The path is wrong, but get_version.py is not even called, (nothing from get_version.py printed on STDOUT or fails if contains errors)
You are telling CMake "if you need ${CMAKE_CURRENT_BINARY_DIR}/version.c then this is how you generate it". It will only actually call the command if ${CMAKE_CURRENT_BINARY_DIR}/version.c is required by a target. So if you give the wrong path, e.g. main/version.c it won't understand that you are talking about the same file, and therefor not generate it.

Happy you found a way to solve this though!

Who is online

Users browsing this forum: eriksl, ESP_Roland and 157 guests