Building CMake project without idf.py
Posted: Tue Feb 11, 2020 6:35 pm
Hi,
I'm attempting to build a project using the esp-idf.
I've been using the idf.py script and the idf_component_register functions and that has worked however I'd like to switch to pure cmake to make debugging my own cmake files easier and to reduce the amount of 'magic' in the system a little bit.
I've tried using idf_build_process(esp32) instead of the script that seems to call cmake again in script mode which disallows certain cmake commands. My project structure is as follows:
-root
---esp-idf
---project
-----build
-----components
-------custom
---------custom.h/custom.c
---------CMakeLists.txt
-----main
-------main.c
-------CMakeLists.txt
Before running the cmake command I run the export.sh first to set any needed environment variables.
Then I cd into build and run cmake ..
I get an error stating that the add_library() command is not scriptable which I think is because the idf_build_process runs cmake again in scripting mode. When I uncomment idf_component_register and comment out add_executable it passes that stage of the build at least but I was hoping to not need idf_component_register and use straight CMake like add_library and add_executable instead.
Any hints regarding this and how to better structure a cmake idf project are highly appreciated.
Thanks.
I'm attempting to build a project using the esp-idf.
I've been using the idf.py script and the idf_component_register functions and that has worked however I'd like to switch to pure cmake to make debugging my own cmake files easier and to reduce the amount of 'magic' in the system a little bit.
I've tried using idf_build_process(esp32) instead of the script that seems to call cmake again in script mode which disallows certain cmake commands. My project structure is as follows:
-root
---esp-idf
---project
-----build
-----components
-------custom
---------custom.h/custom.c
---------CMakeLists.txt
-----main
-------main.c
-------CMakeLists.txt
Before running the cmake command I run the export.sh first to set any needed environment variables.
Then I cd into build and run cmake ..
Code: Select all
# root/project/CMakeLists.txt
cmake_minimum_required(VERSION 3.5...3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
idf_build_process(esp32)
project(hello-world)
Code: Select all
# root/project/main/CMakeLists.txt
#idf_component_register(
# SRCS "main.c"
# INCLUDE_DIRS "${COMPONENT_DIR}"
#)
add_executable(main.elf main.c)
target_link_libraries(main.elf PRIVATE custom)
idf_build_executable(main.elf)
Code: Select all
# root/project/components/custom/CMakeLists.txt
add_library(
custom STATIC
custom.c
custom.h
)
target_include_directories(custom PUBLIC ${CMAKE_CURRENT_LIST_DIR})
Any hints regarding this and how to better structure a cmake idf project are highly appreciated.
Thanks.