Page 1 of 2

COMPONENT_EMBED_FILES & Cmake

Posted: Thu Jun 27, 2019 4:43 pm
by mikemoy
Anyone have any clear information on how to embed files using cmake?

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Thu Jun 27, 2019 6:06 pm
by ESP_igrr

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Thu Jun 27, 2019 6:52 pm
by mikemoy
Thank you. Though i have read those before and it was clear as mud to me.
For instance, they say:
You can specify argument COMPONENT_EMBED_FILES in the component registration, giving space-delimited names of the files to embed:

But the example they give does not add up:
idf_component_register(...
EMBED_FILES server_root_cert.der)

Should it not read.
idf_component_register(...
COMPONENT_EMBED_FILES server_root_cert.der)

I tried both ways none the less, and it still did not work giving "undefined reference to `_binary_less_min_js_end' "


The default CMakeLists.txt file before I made any changes is:

Code: Select all

set(COMPONENT_SRCS main.c myTools.c MyWiFi.c nvs_storage.c ota_server.c Task_ClockMonitor.c Task_plantControl.c updateTime.c WebServer.c)
set(COMPONENT_ADD_INCLUDEDIRS ".")

register_component()
Using the old make way i just simply added this in component.mk file.

Code: Select all

COMPONENT_SRCDIRS += WebsiteFiles
COMPONENT_EMBED_FILES := WebsiteFiles/index.html WebsiteFiles/favicon.ico WebsiteFiles/timepicker.less WebsiteFiles/less.min.js
I need to mimic this for the Cmake way.

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Thu Jun 27, 2019 7:30 pm
by ESP_igrr
Sorry, with recent changes it indeed became not clear: the snippet shows the new component registration approach based on arguments, while the text describes the older approach based on component variables.
Which version of IDF are you using? The snippet in the documentation will work with latest IDF, but not with 3.3 or 3.2.

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Thu Jun 27, 2019 7:53 pm
by mikemoy
Thanks for clearing that all up. I am using v3.2-rc
So knowing this, what should the CMakeLists.txt file look like to embed those files using 3.2 or 3.3 ?

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Thu Jun 27, 2019 9:13 pm
by ESP_igrr

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Fri Jun 28, 2019 2:38 am
by mikemoy
Here is the complete file. CMakeLists.txt file

Code: Select all

set(COMPONENT_SRCS main.c myTools.c MyWiFi.c nvs_storage.c ota_server.c Task_ClockMonitor.c Task_plantControl.c updateTime.c WebServer.c)
set(COMPONENT_ADD_INCLUDEDIRS ".")


set(COMPONENT_EMBED_FILES index.html favicon.ico timepicker.less less.min.js)

register_component()

Using set(COMPONENT_EMBED_TXTFILES index.html favicon.ico timepicker.less less.min.js)
or
set(COMPONENT_EMBED_FILES index.html favicon.ico timepicker.less less.min.js)

Compiles to the following errors.


Code: Select all

main/libmain.a(index.html.S.obj): In function `index_html':
(.rodata.embedded+0x0): multiple definition of `index_html'
main/libmain.a(WebServer.c.obj):(.data.index_html+0x0): first defined here
main/libmain.a(timepicker.less.S.obj): In function `timepicker_less':
(.rodata.embedded+0x0): multiple definition of `timepicker_less'
main/libmain.a(WebServer.c.obj):(.data.timepicker_less+0x0): first defined here
main/libmain.a(less.min.js.S.obj): In function `less_min_js':
(.rodata.embedded+0x0): multiple definition of `less_min_js'
main/libmain.a(WebServer.c.obj):(.data.less_min_js+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
-------------------------------------------------------------
Command exited with code 1
Executable: C:\PROGRA~2\Sysprogs\VISUAL~1/ninja.exe
Arguments: 
Directory: C:\Users\Jim\source\repos\PlantLightCmake/VisualGDB/Release
VisualGDB: Error: Command-line action failed
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Fri Jun 28, 2019 5:28 am
by ESP_igrr
In Webserver.c, do you have a variable 'index_html' defined? The linker says that this variable is defined in two places: the embedded file and Webserver.c.

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Fri Jun 28, 2019 2:04 pm
by mikemoy
Yes, in WebServer.c I have the following.

Code: Select all

extern const uint8_t index_html_start[] asm("_binary_index_html_start");
extern const uint8_t index_html_end[]   asm("_binary_index_html_end");

extern const uint8_t favicon_ico_start[] asm("_binary_favicon_ico_start");
extern const uint8_t favicon_ico_end[]   asm("_binary_favicon_ico_end");

extern const uint8_t timepicker_less_start[] asm("_binary_timepicker_less_start");
extern const uint8_t timepicker_less_end[]   asm("_binary_timepicker_less_end");

extern const uint8_t less_min_js_start[] asm("_binary_less_min_js_start");
extern const uint8_t less_min_js_end[]   asm("_binary_less_min_js_end");

Re: COMPONENT_EMBED_FILES & Cmake

Posted: Mon Jul 01, 2019 11:16 am
by mikemoy
@ESP_igrr, any more suggestions ?