Hey wise people,
I am sure I am being super stupid, but cmake is a mortal enemy of mine and I am trying to hack together some stuff so that I can properly get to grips with the espidf build system as well as modularising my code and adding some build time ergonomics (at least that is the plan)! ![]()
I am using frameworks espidf and arduino in my platformIO.ini. When I run idf.py reconfigure and idf.py build my project successfully compiles, but when I compile with pio run -e <MY_ENV> it fails unable to find build_info.h in main.cpp, however, idf seems able to find it…..?
For context, the build_info.h is supposed to be a generated file that I create, kinda like the following:
I made a cmake “module” in components/ as directed in espidf. Slung a CMakeLists.txt in it: which looks kinda like this (this is only supposed to be a test at the moment whilst I get to grips with things):
# Hacky Cmake Test to Generate build_info.h
# 1. Register component (no include dirs yet)
# 2. Generated header goes in build dir (NOT source dir)
set(BUILD_INFO_HEADER ${CMAKE_CURRENT_BINARY_DIR}/build_info.h)
idf_component_register(
# SRCS ${BUILD_INFO_HEADER}
SRCS dummy.cpp
)
#/workspace/build/esp-idf/build_info/build_info.h
message(STATUS " BUILD_INFO_HEADER has value ${BUILD_INFO_HEADER} ")
# 3. Generate it using a CMake script (portable)
add_custom_command(
OUTPUT ${BUILD_INFO_HEADER}
COMMAND ${CMAKE_COMMAND}
-DOUTPUT_FILE=${BUILD_INFO_HEADER}
-DPROJECT_ROOT=${PROJECT_ROOT}
-P ${CMAKE_CURRENT_SOURCE_DIR}/generate_build_info.cmake
# DEPENDS ${CMAKE_SOURCE_DIR}/.git/HEAD
COMMENT "Generating build_info.h"
)
set_source_files_properties(${BUILD_INFO_HEADER} PROPERTIES GENERATED TRUE)
# 4. Create a target for it
add_custom_target(build_info_runner DEPENDS ${BUILD_INFO_HEADER})
# 5. Ensure this component depends on it
add_dependencies(${COMPONENT_LIB} build_info_runner)
# 6. Expose the generated header to dependents
target_include_directories(${COMPONENT_LIB} INTERFACE
${CMAKE_CURRENT_BINARY_DIR}
)
This calls a .cmake script which simply does a kinda python subprocesses thing to grab the current git hash at the project root. I have ommitted this since I didn’t want to overwhelm people and am convinced this isn’t the issue since it works under espidf.
Then I need to declare that I depend upon this components/build_info. So, in <PROJECT_ROOT>/src/CMakeLists.txt:
# Register this as an ESP-IDF component
idf_component_register(
SRCS ${app_sources}
INCLUDE_DIRS .
REQUIRES build_info
)
TLDR: Can’t understand why idf.py commands build the project just fine with the above set up with a declared dependency on a component as outlinde in the espidf build system docs, but platformIO then can’t find the generated files in main.cpp (or anywhere) where they are included.