liblightmodbus  2.0
A lightweight, cross-platform Modbus RTU library
Building liblightmodbus
Note
In order to build the library CMake 3.3 or newer is required. Versions up to 1.3 used script-based build system, no longer maintained as of version 1.4. For more information see Using old, proprietary build system.

The library's build configuration process is pretty complex, as the library consists of many modules that can be included in the build or omitted. If you want to go with default configuration first, take a look at the section below.

Default build configuration

  1. mkdir build - Create a new directory for build environment
  2. cmake .. - Run CMake with no additional flags
  3. make all - Build the library

Custom build

The only difference between default and customized builds are the arguments passed to CMake.

The MODULES CMake variable determines what library modules and functionalities are going to be included during the build process. It should take value of desired module names list, separated with semicolons (and no spaces!). See below for list of available modules along with short descriptions:

Note
If you don't specify any modules during configuration, these default modules are going to be included: SLAVE_BASE;F01S;F02S;F03S;F04S;F05S;F06S;F15S;F16S;F22S;SLAVE_USER_FUNCTIONS;MASTER_BASE;F01M;F02M;F03M;F04M;F05M; F06M;F15M;F16M;F22M;MASTER_USER_FUNCTIONS.

Disabling dynamic memory allocation

Liblightmodbus can work without dynamic memory allocation. See Disabling dynamic memory allocation for more information.

Setting endianness

Modbus is strictly big-endian protocol. That means you have to specify target system endianness when building. By default, CMake will check your system endianness and apply that setting, but in order to override it, set ENDIANNESS CMake variable to either "big" or "little".

Building for AVR

Building the library for AVR microcontrollers is pretty easy thanks to the AVR CMake variable. If you want to build for AVR, just add -DAVR=<part> argument to the CMake invocation, where <part> is the target microcontroller type (for instance atmega328).

Debug and release builds

In order to specify build type - debug or release, set CMAKE_BUILD_TYPE to either Debug or Release.

Changing compiler and linker

To change used compiler and linker, adjust these CMake variables: CMAKE_C_COMPILER, CMAKE_LINKER.

Coverage testing

Even though it's probably not what you want to do, you can enable coverage test build by setting COVERAGE_TEST variable to 1.

Library configuration file

During the build process, a special library configuration header file - include/lightmodbus/libconf.h is created. It contains macros describing current library configuration. Names of these macros correspond to CMake configuration variable names.

If you know, what you are doing you can edit this file manually, however keep in mind that the library will need rebuilding after making any changes.