GNU Make to CMake migration issue

techtoys
Posts: 28
Joined: Sat Jun 01, 2019 11:11 am

GNU Make to CMake migration issue

Postby techtoys » Fri Aug 30, 2019 10:21 am

Hi

I have a project compile and run OK with GNU Make (ESP-IDF v4.1/3.2.2). Now I wish to include CMakeLists.txt to make this project compatible with CMake but there are issues.

The folder hierarchy of my project is like:

Code: Select all

-HelloWorld/
	- CMakeLists.txt
	- Makefile
	- sdkconfig
	- components/ - my_component/ 
				- CMakeLists.txt
				- component.mk
				- Framework/ #folder empty for now
				- Widgets/ #folder empty for now
				- HAL/ #.c and .h files in the same level
	- main/
		- CMakeLists.txt
		- component.mk
		- main.c
Component file 'component.mk' in my_component/ folder is listed below:

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := Framework \
Widgets \
HAL

COMPONENT_SRCDIRS := Framework \
Widgets \
HAL

#override compiler flags in ESP32 IDF to change some warnings to errors
CFLAGS+=-Wno-error=missing-braces -DMY_OPTIONS -D_DEBUG
An attempt to migrate it to CMake-based with CMakeLists.txt listed below:

Code: Select all

file(GLOB my_srcs Framework/*.c Widgets/*.c HAL/*.c)
set (COMPONENT_ADD_INCLUDEDIRS "Framework" "Widgets" "HAL")
set (COMPONENT_SRCS ${my_srcs})
register_component()
target_compile_definitions(${COMPONENT_TARGET} PUBLIC "-DMY_OPTION" "-D_DEBUG")
All .c and .h files are at the same level in each of the Framework/, Widgets/, and HAL/ folders. That means there is no sub-folder inside.

Unfortunately it doesn't compile with CMake. I just ran idf.py clean > idf.py menuconfig >idf.py build with error:

fatal error: esp_vfs_fat.h: No such file or directory.

No modification to source code or folder structure has been made between make and idf.py build. This esp_vfs_fat.h file was found with GNU Make but not CMake.

I am wondering if my CMakeLists.txt has some mistake so that some of the files are not found.

Any idea?

BR

John

techtoys
Posts: 28
Joined: Sat Jun 01, 2019 11:11 am

Re: GNU Make to CMake migration issue

Postby techtoys » Sat Aug 31, 2019 4:28 pm

The issue may not be entirely due to CMakeLists.txt syntax. In HAL/ folder there is a header file HW_Platform_ESP32.h with includes as below:

Code: Select all

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>

#include "driver/spi_master.h"
#include "driver/gpio.h"

#include "esp_vfs_fat.h"
#include "driver/sdmmc_host.h"
#include "driver/sdspi_host.h"
#include "sdmmc_cmd.h" 
#include "esp_timer.h"
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_event_loop.h"
Whenever it comes to #include "esp_vfs_fat.h" the error : No such file or directory came out. When this include is replaced by some others, say, #include "sdmmc_cmd.h", the same error reporting No such file as sdmmc_cmd.h is found.

This means from GNU Make with component.mk to CMakeLists.txt conversion, there is something missing in my code.

Also tried #include "vfs/esp_vfs_fat.h" but the same No such file or directory error came out. What is wrong?

Also trying to use the automatic conversion tool /tools/cmake/convert_to_cmake.py with the hello_world project as a starting point. First I deleted the CMakeLists.txt inside /main and /root, then running this command from msys2
$python convert_to_cmake.py $IDF_PATH/examples/get-started/hello_world

But it didn't go through with an error as:

Code: Select all

Traceback (most recent call last):
  File "convert_to_cmake.py", line 195, in <module>
    main()
  File "convert_to_cmake.py", line 191, in main
    convert_project(args.project)
  File "convert_to_cmake.py", line 123, in convert_project
    p = subprocess.check_output(cmd).strip()
  File "C:/msys32/mingw32/lib/python2.7/subprocess.py", line 224, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['cygpath', '-w', u'']' returned non-zero exit status 1

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: GNU Make to CMake migration issue

Postby ESP_Angus » Mon Sep 02, 2019 2:02 am

Hi techtoys,

One major difference in the CMake build system is that components in CMake need to declare the other components that they require. The automated conversion script doesn't derive these, they have to be manually filled in.

If the component CMakeLists file is using the idf_component_register() function, then the way to do this is to add a clause REQUIRES vfs sdmmc in this function call. List all of the components which are required by your component (very common components like 'freertos' can be skipped here but in general list everything).

If you use a recent version of the conversion script in IDF V4.x then an empty REQUIRES line should already be in the CMakeLists.txt file, with a comment abut filling it in.

A more detailed section in the docs about declaring requirements is coming soon.

If you're using IDF v3.x and the "idf_register()" function instead, then the way to do this is via "set(COMPONENT_REQUIRES vfs sdmmc)" instead of the way mentioned above.

techtoys
Posts: 28
Joined: Sat Jun 01, 2019 11:11 am

Re: GNU Make to CMake migration issue

Postby techtoys » Mon Sep 02, 2019 6:45 am

Thanks a lot.

It works with CMakeLists.txt like this:

Code: Select all

#all .c and .h files in the same level in each directory
file(GLOB my_srcs Framework/*.c Widgets/*.c HAL/*.c)
idf_component_register(SRCS ${my_srcs} INCLUDE_DIRS Framework Widgets HAL REQUIRES fatfs sdmmc)

target_compile_options(${COMPONENT_LIB} PRIVATE "-DMY_OPTION" "-D_DEBUG")
BR

Who is online

Users browsing this forum: No registered users and 99 guests