CMake components in distant folders

malachib
Posts: 17
Joined: Tue Aug 28, 2018 9:06 am

CMake components in distant folders

Postby malachib » Tue Jan 28, 2020 3:01 am

Hi, I have a project with a structure similar to:

Code: Select all

/
/ext
/ext/submodule1
/ext/submodule1/tools/esp-idf/component.cmake
/ext/submodule2
/ext/submodule2/tools/esp-idf/component.cmake
/src/
/src/components
/src/main
The submodules each have their own CMakeLists.txt (actually I named it component.cmake)

I wish to keep the submodules under 'ext' and not move them physically under components

I struggle to use projects in this format, though I've succeeded in brute forcing through some ugly stuff before. I'll skip all those details as it's just gonna make this post huge.

If one has a folder structure like this, what's the recommended approach for putting together all the CMakeLists.txt? Thank you

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: CMake components in distant folders

Postby ESP_Angus » Wed Jan 29, 2020 4:54 am

Hi malachi,

It should be possible to use the general structure you describe with the ESP-IDF CMake build system.

(It's also possible to colour way outside the lines and do anything CMake lets you do, but this is outside the scope of the advice I'm able to give you.)

Judging from the info above, you'll need the following things:
  • A project CMakeLists.txt file somewhere, presumably in the top-level directory.
  • Component CMakeLists.txt files in the src/main directory and in any component directories under src/components
  • Rename the submodule component.cmake files to CMakeLists.txt, we don't have any way to support different names for component CMakeLists.txt files and have everything work smoothly (we spent a lot of time trying to make this work early on!)
  • In the project CMakeLists.txt file, set the variable EXTRA_COMPONENT_DIRS to the full list of relative paths to component directories. These can be a directory containing a component CMakeLists.txt, or the immediate parent directory of those directories (in your case it will be something like "set(EXTRA_COMPONENT_DIRS src/components src/main ext/submodule1/tools/esp-idf/ ext/submodule2/tools/esp-idf/". Place this command immediately before the include(...project.cmake) line in the CMakeLists.txt file.
I think that will work.

Bear in mind that when moving to CMake build system, components need to declare their requirements.

Note also that I've linked to master branch version of the CMake docs as you haven't mentioned which IDF version you plan to use. But these features are all largely the same in the other versions, as well.

Who is online

Users browsing this forum: Google [Bot], mahone and 252 guests