Compatibility between "normal CMake" and ESP-IDF
Posted: Wed Oct 03, 2018 9:41 am
Hi!
Despite the current crash problem with the ESP-IDF cmake build, and in the hope that it will be fixed at some point in time, I have been trying to integrate the cmake build with my own cmake based build setup. Actually my setup is similar to the ESP-IDF setup. It's interesting to see how you handle the linkerscripts. Of course there are several things which I wouldn't do the way you do it, but that's perhaps just my opinion.
One thing however, is a kind of showstopper. With your cmake build setup it's impossible to use any other cmake based projects, especially library projects, which I believe is one key aspect of using cmake in the first place. I've got a couple of library projects, coming from other cross platform developments, which I'd like to re-use on ESP32. The way you treat the concept of toolchain files and the override of the "project" macro/function makes everything fall apart unfortunately. The problem is that pretty much every cmake based project has a "project" usage in it and then you throw the whole ESP-IDF at it and treat it like an application project. Rewriting existing libraries to use your component approach does not seem feasible.
In the end, what I would like to do is something like this in the "main component" of an IDF based project:
where "utils" and "hash" are some other existing library projects.
After some digging, it seems only a few changes are needed in your cmake setup to support this. Please see the attached patch. The key point is to rename your macro "project" to "idf_project" and pass in the toolchain file from OUTSIDE the build setup. This allows using different toolchain files when setting up the build configuration. As an example, I've also attached the toolchain file which I'm using. It's got some of those additions, which are pulled in by
...but this is just an example use case.
The build is then setup for example like this
With those things in place, I can use the ESP-IDF system as well as my own cmake system. For example, one of the libraries generates include header files (used by the cross compiler build) by running the host compiler to first build a host tool out of the same source code and things like that. It works normally as expected.
So hm yeah, this way your initial build setup step is a bit more complicated, because your users will need to specify the toolchain file separately when running cmake. But even cmake-gui has an option for that
I hope you can incorporate my suggestions into your system. It would make it much much more useful and easier to use with other existing cmake setups.
Despite the current crash problem with the ESP-IDF cmake build, and in the hope that it will be fixed at some point in time, I have been trying to integrate the cmake build with my own cmake based build setup. Actually my setup is similar to the ESP-IDF setup. It's interesting to see how you handle the linkerscripts. Of course there are several things which I wouldn't do the way you do it, but that's perhaps just my opinion.
One thing however, is a kind of showstopper. With your cmake build setup it's impossible to use any other cmake based projects, especially library projects, which I believe is one key aspect of using cmake in the first place. I've got a couple of library projects, coming from other cross platform developments, which I'd like to re-use on ESP32. The way you treat the concept of toolchain files and the override of the "project" macro/function makes everything fall apart unfortunately. The problem is that pretty much every cmake based project has a "project" usage in it and then you throw the whole ESP-IDF at it and treat it like an application project. Rewriting existing libraries to use your component approach does not seem feasible.
In the end, what I would like to do is something like this in the "main component" of an IDF based project:
Code: Select all
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED 14)
set (CMAKE_CXX__EXTENSIONS OFF)
set(COMPONENT_SRCS "main.cpp")
set(COMPONENT_ADD_INCLUDEDIRS "")
register_component()
import_library (utils) // like "add_subdirectory" but with some enhancements
import_library (hash) // like "add_subdirectory" but with some enhancements
target_link_libraries (main utils hash)
After some digging, it seems only a few changes are needed in your cmake setup to support this. Please see the attached patch. The key point is to rename your macro "project" to "idf_project" and pass in the toolchain file from OUTSIDE the build setup. This allows using different toolchain files when setting up the build configuration. As an example, I've also attached the toolchain file which I'm using. It's got some of those additions, which are pulled in by
Code: Select all
include (${CMAKE_CURRENT_LIST_DIR}/../common.cmake)
The build is then setup for example like this
Code: Select all
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake <esp idf project source dir>
So hm yeah, this way your initial build setup step is a bit more complicated, because your users will need to specify the toolchain file separately when running cmake. But even cmake-gui has an option for that
I hope you can incorporate my suggestions into your system. It would make it much much more useful and easier to use with other existing cmake setups.