How to specify a global include directory for all components?

Zoltan Janosy
Posts: 11
Joined: Tue Apr 12, 2022 11:15 am

How to specify a global include directory for all components?

Postby Zoltan Janosy » Thu May 04, 2023 1:54 pm

My intention is to keep all product-specific configuration header files in a single directory, for example, in the 'main/include' directory. I have several reusable (not product-specific) components that need to access these header files. I did not find any hint in the documentation about how to specify a global include directory for the project. Apparently, 'main/include' is not included in the component. Adding 'main' to the REQUIRES section seems to be not the correct way. Creating a Kconfig.projbuild may do the trick, but it is a lot of work for all parameters, and actually these config parameters are fixed for a product, not editable.

I had the same problem with some ESP-IDF libraries, like NimBLE and TinyUSB. I wanted to specify my own settings, but could not figure out how to do it without editing the component files.

I'd appreciate any help.

Thanks,
Zoltan

Zoltan Janosy
Posts: 11
Joined: Tue Apr 12, 2022 11:15 am

Re: How to specify a global include directory for all components?

Postby Zoltan Janosy » Thu May 04, 2023 2:30 pm

I have figured it out. Add

Code: Select all

include_directories(${CMAKE_CURRENT_LIST_DIR}/main/include)
to the CMakeList.txt in the project's root directory, right before:

Code: Select all

project(${ProjectId})

Zoltan Janosy
Posts: 11
Joined: Tue Apr 12, 2022 11:15 am

Re: How to specify a global include directory for all components?

Postby Zoltan Janosy » Thu May 04, 2023 3:24 pm

Now, how to do the same for ULP-RISCV components? Apparently the method above does not work with the RISCV compiler.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: How to specify a global include directory for all components?

Postby ESP_Sprite » Fri May 05, 2023 1:50 am

Possibly a cleaner way (that might also work with ULP, I don't know) is to make those shared things into its own header-only component, then use EXTRA_COMPONENT_DIRS in the projects to point to that an REQUIRES in the components that need it?

Zoltan Janosy
Posts: 11
Joined: Tue Apr 12, 2022 11:15 am

Re: How to specify a global include directory for all components?

Postby Zoltan Janosy » Tue May 09, 2023 4:50 pm

That seems to be a nicer solution indeed. However, then you'd need to add this component to all the components explicitly. While I could do it for my own components, it does not work with system or managed components like NimBLE or TinyUSB, I believe. On the other hand, the "include_directories" method adds this folder to all the components' include path.

Who is online

Users browsing this forum: Bing [Bot] and 174 guests