-
Notifications
You must be signed in to change notification settings - Fork 39
Libraries
One of Arduino's most important features, as with any programming infrastructure, are libraries.
In fact, the scope of libraries in the Arduino-CMake framework is so large that it requires its' own category, with each type of library having its own page!
Some of you have already noticed that Arduino-CMake takes an approach similar to CMake itself regarding the targets API, that is of course to ease the use of the framework.
Libraries are no different. How?
In general, to use a certain library in your CMake project you must follow the following procedure:
- Either find the library or create it yourself.
Finding a library usually means finding a pre-built binary matching the requirements of the host OS. - Link the library target to some other target.
We've emphasized usually because Arduino libraries almost always have the form of unbuilt sources.
Arduino-CMake takes a similar approach, but in our case - The library target will always be created and built by the project itself.
It's important to understand the procedure of library finding in order to fully utilize it.
First, a directory with the library's name is searched in some pre-defined (yet portable) paths which can't be changed.
Then, if found, its headers and sources are found "underneath" it as well, then assembled to create a CMake library target.
The following paths are searched during the procedure:
-
ARDUINO_SDK_LIBRARIES_PATH
- Usually the libraries directory under the SDK's root directory - Sketchbook Location - Arduino IDE's Sketchbook path, storing all user-downloaded libraries
-
CMAKE_CURRENT_SOURCE_DIRECTORY
- The directory in which the executed CMakeLists.txt file resides, i.e. Project's source directory -
PROJECT_SOURCE_DIR
- The directory in which the CMakeLists.txt file that sets theproject
resides.
Besides, the following sub-directories are searched under every path mentioned above:
- libraries
- dependencies
Most of the libraries have a properties file attached, named library.properties, as this is Arduino's standard.
This file includes various metadata about the library, some of which is useful to the framework as well - The MCU architectures supported by the library.
If this file exists for a given library, it's read to extract the architecture metadata from it.
The framework then checks whether the current platform's architecture is supported by the library, i.e. whether it's listed in the extracted metadata, and if not - Displays an error message and stops CMake generation.
Libraries that don't have the properties file are assumed to be architecture-agnostic, meaning they support any architecture.
Arduino-CMake separates libraries into 4 different types: