-
Notifications
You must be signed in to change notification settings - Fork 145
Linux Build Instructions
The open source and NREL release-build platform is CentOS 7 and has been built on Ubuntu 16.04, Fedora 25 and Mint 18.2. The minimum gcc version supported is 4.8.5, the minimum libc support is 2.17, and the minimum CMake version is 3.24. The GCC, libc, and CMake versions can be found by:
gcc --version
ldd --version
Before you begin, you will need to install Git, g++, and CMake if they are not already installed. For example, to install Git and g++:
sudo apt-get install git
sudo apt-get install g++
To install CMake, download a Linux distribution from https://cmake.org/download/. For step-by-step instructions, see for example https://www.linuxfordevices.com/tutorials/install-cmake-on-linux.
-
The source code for the LK, WEX, SSC, and SAM projects should go in a single parent directory. The
git clone
command automatically creates a directory for the repository, so you do not need to create a directory before you clone it. You may first need to install git withsudo apt install git
.cd sam_dev for repo in lk wex ssc sam ; do git clone https://github.com/nrel/$repo ; done
The latest code is in the
Develop
branch of each repository. If you are contributing code, you should work with this branch. To build a specific version of SAM, you can check out a tag for that version. See List of Tags for SAM Versions for a list of tags for different versions of SAM, SSC, WEX and LK.Note. You can also download the repositories from GitHub as
.zip
files instead of cloning them. If you do that, be sure to extract them into directories namedlk
,wex
,ssc
, andsam
so that the makefiles can find them. -
The following packages are required and can be downloaded from
apt-get
:libcurl4-openssl-dev build-essential libgtk2.0-dev libgl1-mesa-dev mesa-common-dev freeglut3-dev
sudo apt-get install <PACKAGE NAME>
-
Download wxWidgets-3.2.0 (https://www.wxwidgets.org/downloads/) source code for Linux.
-
From a terminal, create a permanent folder like
/home/<USERNAME>/wxWidgets-3.2.0
and extract the archive to that folder.source codetar xvfj wxWidgets-3.2.0.tar.bz2
-
Create a new folder in the wxWidgets folder you created in Step 2 so that each release or debug build has its own folder (remember to change
/path/to
to the actual path):cd /path/to/wxWidgets-3.2.0 mkdir release-build cd release-build
-
Call
configure
with the following options. (You can also find the options in/sam_dev/sam/build_linux/wxconfigure_3.2.0.linux64
). Theprefix
path is the installation destination of the wxWidgets libraries. Again, remember to change/path/to
to the path to the installation folder:../configure --prefix=/path/to/wx-3.2.0 --enable-shared=no --enable-debug=no --with-gtk=2 --with-libjpeg=builtin --with-libpng=builtin --with-regex=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin --without-libjbig --without-liblzma --without-gtkprint --with-libnotify=no --with-libmspack=no --with-gnomevfs=no --with-opengl=yes --with-sdl=no --with-cxx=11
-
Once configure is done, call
make
, and thenmake install
. -
Look for
wx-config
in/path/to/wx-3.2.0/bin
and make a note of the complete path. -
Create a
wx-config-3
symbolic link pointing to the path you found in Step 6 so that the makefiles can find the correct wxWidgets version to run:sudo ln -s /path/to/wx-3.2.0/bin/wx-config /usr/local/bin/wx-config-3
(alternatively) If you are building on a system where you don't have root access, you can create a system variable for the wx Widgets path instead:
export WXMSW3=/path/to/wx-3.2.0
-
Test the wxWidgets build:
wx-config-3 --cflags
If the build was successful, you should see something like:
-I/home/wx-3.2.0/lib/wx/include/gtk2-unicode-static-3.1 -I/home/wx-3.2.0/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DwxDEBUG_LEVEL=0 -D__WXGTK__ -pthread
SAM's repositories contain dependencies on the Google Test framework Google Test, which is a C++ unit-test framework.
Clone Google Test and do an out-of-source build for the Debug or Release configuration:
git clone https://github.com/google/googletest.git
mkdir googletest/build
cd googletest/build
cmake .. -DCMAKE_BUILD_TYPE=<Debug;Release> -DCMAKE_CXX_FLAGS=-std=c++11
make -j4
If the builds succeed, you should see googletest/build/lib/libgtest<d>.a
.
Environment variables store values for programs and processes on your computer. The SAM build script use five environment variables to determine where the files it needs are stored on your computer. Before building the projects, you should set the following environment variables to point to each of the project folders you created in Step 1.
Name | Value (Folder Path) |
---|---|
GTEST | /path/to/googletest/ |
LKDIR | /path/to/lk/ |
WEXDIR | /path/to/wex |
SSCDIR | /path/to/ssc |
SAMNTDIR | /path/to/SAM |
To conveniently set your environment variables to be set every time you open a terminal, set them in your user .bashrc file:
gedit $HOME/.bashrc
And then in the file:
export GTEST=/path/to/googletest
export LKDIR=/path/to/lk
export WEXDIR=/path/to/wex
export SSCDIR=/path/to/ssc
export SAMNTDIR=/path/to/SAM
Finally, save and close the file and:
source $HOME/.bashrc
The build requires CMake 3.19 or higher. There are two build methods:
-
The first uses an umbrella CMakeLists.txt that bundles up all four projects into a single project.
In the
sam_dev
folder, save the following text as CMakeLists.txt:option(SAM_SKIP_TOOLS "Skips the sdktool and tcsconsole builds" OFF) option(SAM_SKIP_TESTS "Skips building tests" OFF) option(SAMAPI_EXPORT "Export of ssc binaries to the SAM_api directory; for Unix, compile ssc libraries for SAM_api" ON) option(SAM_SKIP_AUTOGEN "Skips the automatic regeneration of SAMAPI files from export_config" ON) cmake_minimum_required(VERSION 3.19) Project(system_advisor_model VERSION 1.0.0) add_subdirectory(lk) add_subdirectory(wex) add_subdirectory(ssc) add_subdirectory(sam)
There are four CMake options used for build settings:
SAM_SKIP_TOOLS
allows skipping sandboxes and the tcsconsole executables. Off by default.SAM_SKIP_TESTS
allows skipping the Test project in SSC. Off by default.SAMAPI_EXPORT
turns on the SAM api project for producing PySAM files. On by default.SAM_SKIP_AUTOGEN
allows skipping re-generation of the SAM api files. On by default. If you will be making development versions of PySAM, this should be OFF.To do an out-of-source build from command line for either the Debug or Release configuration:
mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release make -j4
To change any of the default options, such as for building development versions of PySAM, set the CMake option:
cmake .. -DCMAKE_BUILD_TYPE=Release -DSAM_SKIP_AUTOGEN=OFF
To build the Debug version, change the CMAKE_BUILD_TYPE to "Debug".
-
The second method builds each project separately.
For each project in order, LK, WEX, SSC, SAM, do an out-of-source build from the command line for either the Debug or Release configuration:
cd <proj> mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release make -j4
-
go to the SAM/build/deploy folder
-
create a shell script "SAM":
#!/bin/sh
cd <path to SAM source folder>/SAM/build/deploy
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path to SAM source folder>/SAM/build/deploy/linux_64
export GTK2_RC_FILES=<path to SAM source folder>/SAM/build/deploy/linux_64/GtkTheme/gtk-2.0/gtkrc
exec <path to SAM source folder>/SAM/build/deploy/linux_64/SAM.bin
-
save script to ./SAM in SAM/build/deploy folder
-
chmod +x ./SAM
-
from /SAM/build/deploy folder
./SAM