Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Header Only Libraries

Timor Gruber edited this page Oct 2, 2018 · 1 revision

Libraries that include only header files, without any sources, are usually called header-only libraries.
Such libraries are usually template-oriented, although in the Arduino world they're not so popular.
Still, support for them exists in the Arduino-CMake framework.

These libraries are sort of 3rd Party Libraries, and conform to the Arduino libraries standard as well.
As such, all that applies to 3rd Party Libraries applies to these as well.
One thing is different though, and it's the HEADER_ONLY option that should be passed to the find and link functions - Without it the library will be considered as an "ordinary" static library.

For example, let's assume there's a header-only library named Test-Lib, located under the Sketchbook Location so it could be easily found.
Here's what we should do in order to use it in our program:

find_arduino_library(testLib Test-Lib ${board_id} 3RD_PARTY HEADER_ONLY)
link_arduino_library(my_target testLib ${board_id} HEADER_ONLY)

Note that the example above assumes the my_target target has already been created earlier.
Also, board's ID has been retrieved as well.

Manual Addition

Just as 3rd Party Libraries, header-only libraries can also be added manually, useful especially when located in "non-locatable" paths.

To do so, one should call the add_arduino_header_only_library function.

For example, had the Test-Lib library from the example above been located under a "non-locatable" directory named custom_dir, relative to the project's source directory, we would've used the following:

add_arduino_header_only_library(testLib Test-Lib ${board_id} custom_dir/Test-Lib/TestLib.h)
link_arduino_library(my_target testLib ${board_id} HEADER_ONLY)

Note that the example above assumes the my_target target has already been created earlier.
Also, board's ID has been retrieved as well.