Hi p-primes,
Apologies, the CMake build system docs give incorrect instructions for this. Attached is a modified idf-template project which generates a logo.h as part of the "main" component.
The missing steps are:
- Add the header as a "source file" for the component. Similar to the second example in the CMake FAQ here.
- Use CMAKE_CURRENT_BINARY_DIR to qualify all the paths to the generated header.
- Add CMAKE_CURRENT_BINARY_DIR to the private header paths for the component.
The final CMakeLists.txt looks something like:
Code: Select all
set(COMPONENT_SRCS "main.c" ${CMAKE_CURRENT_BINARY_DIR}/logo.h)
set(COMPONENT_PRIV_INCLUDEDIRS "${CMAKE_CURRENT_BINARY_DIR}")
register_component()
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/logo.h
COMMAND xxd -i ${COMPONENT_PATH}/logo.bmp ${CMAKE_CURRENT_BINARY_DIR}/logo.h
DEPENDS ${COMPONENT_PATH}/logo.bmp
VERBATIM)
set_property(DIRECTORY "${COMPONENT_PATH}" APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_CURRENT_BINARY_DIR}/logo.h)
This generates dependencies in the correct order, the generated files are created before any other source files in the component. Using Ninja, in build.ninja this can be seen here:
Code: Select all
build cmake_object_order_depends_target_main: phony || main/logo.h
build main/CMakeFiles/main.dir/main.c.obj: C_COMPILER__main ../main/main.c || cmake_object_order_depends_target_main
Using make, the component dependencies are in the generated "CMakeFiles/main.dir/depend.make" file (this file is not generated by CMake, it's generated the first time make is run before any actual building takes place):
Code: Select all
main/CMakeFiles/main.dir/main.c.obj: main/logo.h
I remember that previously you also required the "generated" header to be part of the source tree, not generated in the build directory. This looks like it should work as well, just by changing the paths. But I haven't verified that.
Will update the CMake docs ASAP.