Skip to content

Creating an Empty Plugin

SJulianS edited this page Jun 3, 2024 · 8 revisions

To create an empty plugin, you first need to create a new empty folder within the hal/plugins folder and then set up the initial file structure. For illustration, we want to create a plugin called example. Hence, we create the following files and folders following the unwritten HAL plugin naming conventions:

plugins
└──example
   ├── CMakeLists.txt
   ├── include
   │   └── example
   │       └── plugin_example.h
   └── src
       └── plugin_example.cpp

Before we start implementing the plugin's intended functionality, we need to prepare the CMakeLists.txt, plugin_example.h, and plugin_example.cpp files so that they implement to the HAL plugin API and thereby allow our plugin to be treated as such by HAL.

Let's start with the CMakeLists.txt. It registers the plugin with HAL whenever cmake is called and makes sure that it is build alongside HAL (if the respective cmake options are enabled; more on this later). The contents of the file should look like this:

option(PL_EXAMPLE "PL_EXAMPLE" ON)

if(PL_EXAMPLE OR BUILD_ALL_PLUGINS)
    file(GLOB_RECURSE EXAMPLE_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
    file(GLOB_RECURSE EXAMPLE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
    hal_add_plugin(example
                   SHARED
                   HEADER ${EXAMPLE_INC}
                   SOURCES ${EXAMPLE_SRC}
    )
endif()

The ON in the first line will enable the plugin by default. If you do not expect many users will need this plugin, set this to OFF so that your plugin is only build if the user explicitly asks for it to be build. This helps keep the HAL build times low. The lines with hal_add_plugin actually register the plugin with the HAL build system, which relies on cmake to coordinate the build process.

Clone this wiki locally