Problems defining component that uses code generation
Posted: Mon Nov 23, 2020 5:39 pm
I am trying to build a component for ESP-IDF v4.1, that uses code generation to generate .cpp and .h files. There is a section in the build system documentation titled "Source Code Generation" that I am trying to use as a reference. The application is not open source, so I will post a minimal dummy component here that gives the same problems. This is what I start with in my CMakeLists.txt based on the documentation.
When I try to build this, I get this error:
This is concerning because this is pretty much copied directly from the documentation. I googled the error message and I found esp-idf GitHub issue #4540 where a user has also encountered the "add_custom_command command is not scriptable" problem. The solution posted by igrr doesn't use an example directly from the original poster's report, so it's a bit hard to know exactly what he's suggesting. Basically, it comes down to wrapping with "if(NOT CMAKE_BUILD_EARLY_EXPANSION)". Based on the ESP-IDF docs Build System > Build System Internals > Build Process > Enumeration section, I believe that adding this "if" statement will prevent the contained text from being processed in the first pass of the ESP-IDF build. This is what I tried next:
And now we run into a different problem:
Why isn't COMPONENT_LIB defined? The documentation indicates that it should be defined.
This is where I'm stuck at now. I'm wondering if the "CMAKE_BUILD_EARLY_EXPANSION" stuff is all just a red herring. If it were actually required, I would expect to see it in the docs.
Code: Select all
add_custom_command(OUTPUT gen.c
COMMAND cp -a ${COMPONENT_DIR}/gen_template.c gen.c
DEPENDS ${COMPONENT_DIR}/gen_template.c)
add_custom_target(gen DEPENDS gen.c)
add_dependencies(${COMPONENT_LIB} gen)
idf_component_register(SRCS abc123.c
gen.c
INCLUDE_DIRS include)
Code: Select all
add_custom_command command is not scriptable
Code: Select all
if(NOT CMAKE_BUILD_EARLY_EXPANSION)
add_custom_command(OUTPUT gen.c
COMMAND cp -a ${COMPONENT_DIR}/gen_template.c gen.c
DEPENDS ${COMPONENT_DIR}/gen_template.c)
add_custom_target(gen DEPENDS gen.c)
add_dependencies(${COMPONENT_LIB} gen)
endif()
idf_component_register(SRCS abc123.c
gen.c
INCLUDE_DIRS include)
Code: Select all
CMake Warning (dev) at components/abc123/CMakeLists.txt:7 (add_dependencies):
uninitialized variable 'COMPONENT_LIB'
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Error at components/abc123/CMakeLists.txt:7 (add_dependencies):
add_dependencies called with incorrect number of arguments
This is where I'm stuck at now. I'm wondering if the "CMAKE_BUILD_EARLY_EXPANSION" stuff is all just a red herring. If it were actually required, I would expect to see it in the docs.