Hi p-rimes,
Glad you're enjoying it!
p-rimes wrote:how did I not know about this tool before? Can ccache be used with the original esp-idf build system as well, or is that CMake-only?
It can, it's just a little fiddler. Two ways to do it:
- Set the compiler prefix in the toolchain config to "ccache xtensa-esp32-elf-"
- Create a directory of symlinks to ccache where the links all have the name of the compiler, then put this directory in the PATH variable before the "real" toolchain directory. ie, my laptop has:
Code: Select all
$ ls -l ~/bin/ccache_local/
total 0
lrwxrwxrwx 1 gus gus 15 Oct 5 2016 xtensa-esp32-elf-cc -> /usr/bin/ccache
lrwxrwxrwx 1 gus gus 15 Oct 5 2016 xtensa-esp32-elf-cpp -> /usr/bin/ccache
lrwxrwxrwx 1 gus gus 15 Oct 5 2016 xtensa-esp32-elf-g++ -> /usr/bin/ccache
lrwxrwxrwx 1 gus gus 15 Oct 5 2016 xtensa-esp32-elf-gcc -> /usr/bin/ccache
$ echo $PATH
/home/gus/bin/ccache_local: ... :/home/gus/bin/xtensa-esp32-elf/bin: ...
$ which xtensa-esp32-elf-gcc
/home/gus/bin/ccache_local/xtensa-esp32-elf-gcc
p-rimes wrote:
1. For generated sources, it seems that adding them the recommended way in the new docs only affects the `${COMPONENT_NAME}.a` output target (`add_custom_target(logo DEPENDS logo.h)`), but I am not sure how to have one source file eg Bar.c inside the component that requires the generated file(s) Foo.h, Baz.h before compiling Bar.c? It seems like a race condition -- sometimes the generated files happen first, but other times they are not ready when Bar.c is compiled.
There is a mistake in the docs, the missing line is this one:
Code: Select all
target_include_directories(${COMPONENT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Which tells cmake to include headers in the current "binary" (ie target build) directory when building the component. This is how it finds logo.h at build time.
Regarding the specific source file compile time dependencies, CMake does some "magic" here in order to determine what header files each source file depends on, and will automatically infer the dependency. Provided the dependency exists between targets in CMake (with add_dependency), and the target_include_directories() includes the directory where the header is generated, CMake should ensure everything is done in the correct order.
p-rimes wrote:
2. How to add project-wide definitions to CFLAGS? Currently I am using a `project_include.cmake` file, with `add_definitions()` in there. Is that correct? (I used to use `Makefile.projbuild`: `CFLAGS += "-Dfoo"` in the old build system)
Yes, these two are equivalent.
p-rimes wrote:
2(b). I can't figure out how to define macro *functions* (eg FOO(x)=(x*2)) at all. At the file, component, or project-level, this doesn't seem possible with CMake? (the warning message suggests modifying the source code to define it at the top but I'd prefer not to modify the source files)
I'm not familiar with this, what's the Makefile equivalent of what you were doing before?
p-rimes wrote:
3. How to create wildcard file rules? Previously I used a `Makefile.componentbuild` with custom makefile targets using `%`. Now I think I need to create CMake functions in a `project_include.cmake` file, and then call those functions from within other components CMakeLists.txt? It works, but it is kinda clunky and CMake syntax is quite tedious compared to a Makefile rule.
I think this should be possible without being too clunky. Can you give some examples of the Make functionality you're trying to reproduce?