Page 1 of 1

CMakeList build system question

Posted: Thu Apr 30, 2020 8:37 pm
by adesandr
Hello,

Dev env : Linux Ubuntu 18.04

My project is structured like this :

Code: Untitled.cmake Select all

My_project :
subproject 1
main
main.c
file1.c
CMakeList.txt
CMakeList.txt

subproject 2
main
main.c
file 2.c
CMakeList.txt
CMakeList.txt

extra_component
Component1
file3.c
filee3.h
CMakeList.txt
Component2
file4.c
file4.h
CmakeList.txt
Both subproject (1&2) used the components inside the extra_components directories.

I used this scheme because my project need to build two different .bin to dowload two different board.

The Subproject CmainList is as follow :

Code: Untitled.cmake Select all

cmake_minimum_required(VERSION 3.5)
set(PROJECT_VER "1.0.2")
set(EXTRA_COMPONENT_DIRS "${PROJECT_DIR}/../extra_components")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(esp-mad-server)
The CmainList for the main component of the subproject is as follow :

Code: Untitled.cmake Select all

idf_component_register(SRCS "main.c" "file1.c"
REQUIRES Component1 Component2)
When i try to build one subproject, Cmake failed with the following error :

CMake Error at /home/adesandr/esp-idf/tools/cmake/build.cmake:185 (message):
Failed to resolve component ‘Component1'.

I can’t understand that is wrong in my setup.

Thank you in advance for your help.

Regards.

Re: CMakeList build system question

Posted: Fri May 01, 2020 1:01 pm
by adesandr
Hello,

Env Dev : Linux Ubuntu 18.04 /ESP-IDF 4.00

My_project is structured as follow :

Code: Untitled.cmake Select all

- My_Project/
- CMakeList.txt
- main/
- file1.c
- file1.h
- CMakeList.txt
- extra_components/
- component1/
- file2.c
- file2.h
- CMakeList.txt
- component2/
- file3.c
- file3.h
- CMakeList.txt
My_Project/CMakeList.txt is as follow :

Code: Untitled.cmake Select all

	# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

# Project version
set(PROJECT_VER "1.0.2")

# Additional directorie to search for components
set(EXTRA_COMPONENT_DIRS "${PROJECT_DIR}/../extra_components")

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

project(My_Project)
My_Project/main/CMakeList.txt is as follow

Code: Untitled.cmake Select all

idf_component_register(SRCS "file1.c"
INCLUDE_DIRS " ")

/extra_components/component1/CMakeList.txt is as follow :

Code: Untitled.cmake Select all

idf_component_register(SRCS "file2.c"
INCLUDE_DIRS "")

When i build My_Project, extra_components/component1and extra_component/component2 are not included in the components list, either in the components path ?

It seems that the command set(EXTRA_COMPONENT_DIRS "${PROJECT_DIR}/../extra_components") is not corrected interpreted.

If I change the structure of My_Project like in the ESP32 CMAKE build system documentation  :

Code: Untitled.cmake Select all

- My_Project/
- CMakeList.txt
- main/
- file1.c
- file1.h
- CMakeList.txt
- components/
- component1/
- file2.c
- file2.h
- CMakeList.txt
- component2/
- file3.c
- file3.h
- CMakeList.txt
The build is working properly.

Thank you in advance for your help.

Regards.

Re: CMakeList build system question

Posted: Fri May 15, 2020 2:26 am
by Angus
Hi adesandr,

Thanks for being patient while someone got back to you.

I think the problem is here:
# Additional directorie to search for components
set(EXTRA_COMPONENT_DIRS "${PROJECT_DIR}/../extra_components")
The PROJECT_DIR is not set as a variable in this file, it's only set as a build property (see API for getting build properties.)

If you look closely at the build output log, there should be some error about failing to find directory "/../extra_components".

Suggest the following should work:

Code: Select all

# Additional directory to search for components
set(EXTRA_COMPONENT_DIRS "${CMAKE_SOURCE_DIR}/../extra_components")

Angus

Re: CMakeList build system question

Posted: Sun May 31, 2020 6:08 pm
by adesandr
Hello,

Thank you very much ESP_Angus, it was the problem.
It's very curious because it works under windows (${PROJECT_DIR}, but not under Linux. Maybe under windows PROJECT_DIR is set in the PATH, i will check.

Problem solved :P

Regards.