COMPONENT_EMBED_FILES & Cmake

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

COMPONENT_EMBED_FILES & Cmake

Postby mikemoy » Thu Jun 27, 2019 4:43 pm

Anyone have any clear information on how to embed files using cmake?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: COMPONENT_EMBED_FILES & Cmake

Postby ESP_igrr » Thu Jun 27, 2019 6:06 pm


mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: COMPONENT_EMBED_FILES & Cmake

Postby mikemoy » Thu Jun 27, 2019 6:52 pm

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.

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: COMPONENT_EMBED_FILES & Cmake

Postby ESP_igrr » Thu Jun 27, 2019 7:30 pm

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.

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: COMPONENT_EMBED_FILES & Cmake

Postby mikemoy » Thu Jun 27, 2019 7:53 pm

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 ?

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: COMPONENT_EMBED_FILES & Cmake

Postby ESP_igrr » Thu Jun 27, 2019 9:13 pm


mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: COMPONENT_EMBED_FILES & Cmake

Postby mikemoy » Fri Jun 28, 2019 2:38 am

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 ==========

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: COMPONENT_EMBED_FILES & Cmake

Postby ESP_igrr » Fri Jun 28, 2019 5:28 am

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.

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: COMPONENT_EMBED_FILES & Cmake

Postby mikemoy » Fri Jun 28, 2019 2:04 pm

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");

mikemoy
Posts: 626
Joined: Fri Jan 12, 2018 9:10 pm

Re: COMPONENT_EMBED_FILES & Cmake

Postby mikemoy » Mon Jul 01, 2019 11:16 am

@ESP_igrr, any more suggestions ?

Who is online

Users browsing this forum: Majestic-12 [Bot] and 80 guests