Building GridLAB-D™ from Source
Developing GridLAB-D™ will inevitably require editing source code and rebuilding the software to evaluate the changes. This section walks through the process of building GridLAB-D™ from source. We also include sub-sections on setting up your development environment to enable this build.
- Setting up WSL for Windows
- Setting up VS Code for GridLAB-D™ Development
- Visual Studio Download/Instructions
Building on ARM-based Macs
GridLAB-D™ now builds with ARM Clang. ARM Clang is a version of the Clang compiler specifically designed to target ARM architectures, allowing developers to compile code for ARM-based systems, including embedded devices and mobile platforms. You can install it on macOS using Homebrew or by downloading pre-built binaries from the LLVM project releases.
Install Required Packages Manager/Installers
Depending on the particular Operating System being used, one of the following package managers/installers are required to install packages/tools for building GridLAB-D™.
In some cases the package manager/installer may need to be separately installed.
- Ubuntu Linux -
apt- comes pre-installed - Windows -
vcpgk- Installation instructions here - Windows WSL -
apt- comes pre-installed - macOS:
homebrew- Installation instructions here
The following packages are required for compiling/running/debugging GridLAB-D™. Each platform has various means of installing these tools and the command to run to install the tools are shown as part of the list below.
Build support tooling, going by various names for each build environment
- CMAKE tools, including the "ccmake" TUI or GUI
- gdb: For debugging
- git: For source code management
- nlohmann-json3-dev: API for working with JSON in C++ to serialize and deserialize data
Options for additional support
- libxerces-c-dev: Xerces-C++ is a validating XML parser
- libhdf5-serial-dev: HDF5 is built for fast I/O processing and storage for heterogeneous data
The pre-requisite installation command list for each build platform
Ubuntu Linux or WSL:
sudo apt -y install
build-essential \
cmake \
cmake-curses-gui \
ninja-build \
libboost-dev \
libeigen3-dev \
nlohmann-json3-dev`
Libraries options for building GridLab-D
sudo apt -y install libxerces-c-dev libhdf5-serial-dev
Windows:
In PowerShell set the target environment for a 64-bit Windows application.
[System.Environment]::SetEnvironmentVariable(
'VCPKG_DEFAULT_TRIPLET', 'x64-windows', 'User'
)
Libraries options for building GridLab-D
vcpkg install xerces-c hdf5
MacOS
brew install cmake eigen
Libraries options for building GridLab-D
brew install xerces-c
Clone Source Code
GridLAB-D™ has the source code hosted on Github; to build from source this code needs to be locally cloned. From the command-line in your build environment in a folder where you want the source code to live run the following command:
git clone https://github.com/gridlab-d/gridlab-d.git
git checkout --track origin/feature/1478 (or whatever branch you need to work in)
git submodule update --init
Configure on Windows using Visual Studio and CMAKE
The following steps will allow to user to build with particular options:
- From a start menu or shortcut, open Visual Studio and start splash shows up.
- On the right, several buttons under 'Get started' will be displayed. Choose 'Open a local folder'.
- Navigate to the cloned for GridLAB-D™ and select the folder.
- After opening, find the 'Solution Explorer' double-click on the 'CMakeSettings.json' file
The following options are more popular ones to define:
CMAKE_BUILD_TYPE- options are "DEBUG" and "RELEASE"CMAKE_INSTALL_PREFIX- location on the filesystem where GridLAB-D™ will be installedGLD_HELICS_DIR- location on the filesystem wherelibhelicsis installedGLD_USE_HELICS- compile with HELICS functionality turned onGLD_ZeroMQ_DIR- location on the filesystem forlibzmq; used by HELICS
Build and Install
Assuming the configuration produces no errors, building GridLAB-D™ and installing it is easy
- From the Visual Studio menu select 'Build' the select 'Build All'
- From the Visual Studio menu select 'Build' the select 'Install GridLAB-D™'
Configure CMAKE build on Linux/WSL2/Mac
CMAKE is the build system of choice for GridLAB-D™ and there are a number of options that are generally set prior to building and installing GridLAB-D™. These options can be set via a (lengthy) list of command line options or can be set in a more persistent manner using a text user interface (TUI) that is run from the command line.
To configure the CMAKE build, do the following from the just cloned GridLAB-D™ source code folder:
mkdir cmake-build
cd cmake-build
ccmake ../
The following options are more popular ones to define:
CMAKE_BUILD_TYPE- options are "DEBUG" and "RELEASE"CMAKE_INSTALL_PREFIX- location on the filesystem where GridLAB-D™ will be installedGLD_HELICS_DIR- location on the filesystem wherelibhelicsis installedGLD_USE_HELICS- compile with HELICS functionality turned onGLD_ZeroMQ_DIR- location on the filesystem forlibzmq; used by HELICS
When all the options are set, press "c" to configure, and "g" when finished to generate the configuration.
Build and Install
Assuming the configuration produces no errors, building GridLAB-D™ and installing it is easy
sudo cmake --build . --target install
Verify Installation
To verify GridLAB-D™ built and installed successfully, you can run the built-in autotests. Assuming you're working with released or unmodified code, all autotests should pass.
cd ../
gridlabd -T 1 --validate
Alternately, if you have python3 installed use
cd ../
python3 validate_gld.py -T 1