Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8015

C/C++ • CMake question in include()

$
0
0
This isn't strictly a C++ question, but it is related.

In CMake, is it possible to give a search path for use by the include() function?
This is NOT to do with the preprocessor include paths, but instead for pulling in other cmake sources.

As an example, I use the pimoroni-pico libraries in a project targeting a PicoW with a Pico Display 2.8" unit.
This means I need to pull in the pico_graphics, and pico_display_28 libraries, along with the st7789, button and rgbled drivers.

These are all located in the pimoroni-pico subfolder in the project top level directory.
I pull them in using:

Code:

set(PP ${CMAKE_CURRENT_LIST_DIR}/pimoroni-pico)include(${PP}/common/pimoroni_bus.cmake)include(${PP}/drivers/button/button.cmake)include(${PP}/drivers/rgbled/rgbled.cmake)include(${PP}/drivers/st7789/st7789.cmake)include(${PP}/libraries/bitmap_fonts/bitmap_fonts.cmake)include(${PP}/libraries/pico_display_28/pico_display_28.cmake)include(${PP}/libraries/pico_graphics/pico_graphics.cmake)
While this works, it seems like I should be able to add the folder name to a path-style variable somewhere, and let cmake figure it out without adding the complete subpath.

Since I'm not a cmake expert, and as soon as you mention 'include' in a search, you get lots of stuff relating to '#include' in your source, which isn't the same thing at all, I thought I'd ask in case someone has a relatively easy solution for this.

I had previously simply done an 'add_subdirectory(${PP}/folder) for each of common, drivers and libraries, but that ends up building a huge amount of stuff I don't want or need, so...


As ever, all replies received in the spirit they are intended :)

Statistics: Posted by SteveSpencer — Fri Dec 19, 2025 3:36 pm



Viewing all articles
Browse latest Browse all 8015

Trending Articles