Problems with writing CMakeLists.txt for a project
Posted: Wed Aug 17, 2022 3:10 pm
Hey folks,
I am new to the esp world!
trying to setup a project I come across a problem, that can't solve and I'm freaking out.
I have the following project structure:
main.c contains following code:
#include "Includes.h"
void app_main(void){
SpiffsInit();
}
CMakeList.txt in main folder:
idf_component_register(
SRCS "main.c"
REQUIRES FileServer // tried also "FileServer.c", "../components/FileServer.c", and full path -> all the same result
INCLUDE_DIRS "."
"../components/include"
)
FileServer.c contains following code:
#include "Includes.h"
static const char* TAG = "FileServer";
esp_err_t SpiffsInit(void){
ESP_LOGI(TAG, "Initializing SPIFFS");
esp_vfs_spiffs_conf_t conf = {
.base_path = NameOfFS,
.partition_label = NULL,
.max_files = 5, // number of files that can be opened at the same time
.format_if_mount_failed = true
};
esp_err_t ret = esp_vfs_spiffs_register(&conf);
if(ret != ESP_OK) {
if(ret == ESP_FAIL){
ESP_LOGE(TAG, "Failed to mount or format filesystem");
}
else if(ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
}
else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}
return ESP_FAIL;
}
size_t total = 0, used = 0;
ret = esp_spiffs_info(NULL, &total, &used);
if(ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
return ESP_FAIL;
}
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
return ESP_OK;
}
CMakeList.txt in components folder :
idf_component_register(
SRCS "FileServer.c"
INCLUDE_DIRS "include"
"C:/Espressif/esp-idf/components/hal/include/hal"
"C:/Espressif/esp-idf/components/spi_flash/include/"
"C:/Espressif/esp-idf/components/nvs_flash/include/"
"C:/Espressif/esp-idf/components/esp_http_server/include/"
"C:/Espressif/esp-idf/components/nghttp/port/include/"
EMBED_FILES "../components/SPIFFsImage/favicon.png"
"../components/SPIFFsImage/IndexHTML.html"
)
FileServer.h :
#ifndef __FILESERVER_H
#define __FILESERVER_H
esp_err_t SpiffsInit(void);
#endif
Includes.h:
#ifndef __INCLUDES_H
#define __INCLUDES_H
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "esp_wifi.h"
#include "C:/Espressif/esp-idf/components/spiffs/include/esp_spiffs.h"
#include "C:/Espressif/esp-idf/components/nvs_flash/include/nvs_flash.h"
#include "C:/Espressif/esp-idf/components/spi_flash/sim/stubs/vfs/include/esp_vfs.h"
#include "C:/Espressif/esp-idf/components/spi_flash/include/esp_partition.h"
#include "C:/Espressif/esp-idf/components/esp_http_server/include/esp_http_server.h"
#include "C:/Espressif/esp-idf/components/nghttp/port/include/http_parser.h"
#include "driver/gpio.h"
#include "FileServer.h"
#endif
Trying to build this ends up in following error:
[0/1] Re-running CMake...
-- Project is not inside a git repository, or git repository has no commits; will not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32
CMake Error at C:/Espressif/esp-idf/tools/cmake/build.cmake:191 (message):
Failed to resolve component 'FileServer'.
Call Stack (most recent call first):
C:/Espressif/esp-idf/tools/cmake/build.cmake:217 (__build_resolve_and_add_req)
C:/Espressif/esp-idf/tools/cmake/build.cmake:441 (__build_expand_requirements)
C:/Espressif/esp-idf/tools/cmake/project.cmake:399 (idf_build_process)
CMakeLists.txt:6 (project)
If I got the example in https://docs.espressif.com/projects/esp ... cmakelists right, than this should work!
What am I doing wrong?
Leaving the 'REQUIRED "FileServer.c" ' part away and moving 'SpiffsInit()' into main.c works flawlessley.
I am new to the esp world!
trying to setup a project I come across a problem, that can't solve and I'm freaking out.
I have the following project structure:
main.c contains following code:
#include "Includes.h"
void app_main(void){
SpiffsInit();
}
CMakeList.txt in main folder:
idf_component_register(
SRCS "main.c"
REQUIRES FileServer // tried also "FileServer.c", "../components/FileServer.c", and full path -> all the same result
INCLUDE_DIRS "."
"../components/include"
)
FileServer.c contains following code:
#include "Includes.h"
static const char* TAG = "FileServer";
esp_err_t SpiffsInit(void){
ESP_LOGI(TAG, "Initializing SPIFFS");
esp_vfs_spiffs_conf_t conf = {
.base_path = NameOfFS,
.partition_label = NULL,
.max_files = 5, // number of files that can be opened at the same time
.format_if_mount_failed = true
};
esp_err_t ret = esp_vfs_spiffs_register(&conf);
if(ret != ESP_OK) {
if(ret == ESP_FAIL){
ESP_LOGE(TAG, "Failed to mount or format filesystem");
}
else if(ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
}
else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}
return ESP_FAIL;
}
size_t total = 0, used = 0;
ret = esp_spiffs_info(NULL, &total, &used);
if(ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
return ESP_FAIL;
}
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
return ESP_OK;
}
CMakeList.txt in components folder :
idf_component_register(
SRCS "FileServer.c"
INCLUDE_DIRS "include"
"C:/Espressif/esp-idf/components/hal/include/hal"
"C:/Espressif/esp-idf/components/spi_flash/include/"
"C:/Espressif/esp-idf/components/nvs_flash/include/"
"C:/Espressif/esp-idf/components/esp_http_server/include/"
"C:/Espressif/esp-idf/components/nghttp/port/include/"
EMBED_FILES "../components/SPIFFsImage/favicon.png"
"../components/SPIFFsImage/IndexHTML.html"
)
FileServer.h :
#ifndef __FILESERVER_H
#define __FILESERVER_H
esp_err_t SpiffsInit(void);
#endif
Includes.h:
#ifndef __INCLUDES_H
#define __INCLUDES_H
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <dirent.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "esp_wifi.h"
#include "C:/Espressif/esp-idf/components/spiffs/include/esp_spiffs.h"
#include "C:/Espressif/esp-idf/components/nvs_flash/include/nvs_flash.h"
#include "C:/Espressif/esp-idf/components/spi_flash/sim/stubs/vfs/include/esp_vfs.h"
#include "C:/Espressif/esp-idf/components/spi_flash/include/esp_partition.h"
#include "C:/Espressif/esp-idf/components/esp_http_server/include/esp_http_server.h"
#include "C:/Espressif/esp-idf/components/nghttp/port/include/http_parser.h"
#include "driver/gpio.h"
#include "FileServer.h"
#endif
Trying to build this ends up in following error:
[0/1] Re-running CMake...
-- Project is not inside a git repository, or git repository has no commits; will not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32
CMake Error at C:/Espressif/esp-idf/tools/cmake/build.cmake:191 (message):
Failed to resolve component 'FileServer'.
Call Stack (most recent call first):
C:/Espressif/esp-idf/tools/cmake/build.cmake:217 (__build_resolve_and_add_req)
C:/Espressif/esp-idf/tools/cmake/build.cmake:441 (__build_expand_requirements)
C:/Espressif/esp-idf/tools/cmake/project.cmake:399 (idf_build_process)
CMakeLists.txt:6 (project)
If I got the example in https://docs.espressif.com/projects/esp ... cmakelists right, than this should work!
What am I doing wrong?
Leaving the 'REQUIRED "FileServer.c" ' part away and moving 'SpiffsInit()' into main.c works flawlessley.