-
Notifications
You must be signed in to change notification settings - Fork 142
Mac Build Instructions
These instructions were written and tested in August 2017 with macOS Sierra 10.12.6, Xcode 8.3.3 with Command Line Developer Tools. They assume that you have at least installed Command Line Developer Tools on your Mac so that you can compile C++ projects from the command line in a terminal window. See this helpful blog for more about Xcode and Command Line Developer Tools. The builds are performed with OS X 10.9 support using the "-mmacosx-version-min=10.9" in both the CFLAGS and CXXFLAGS.
-
To install the Command Line Tools package in macOS Sierra, open a terminal window, and type the following command:
xcode-select --install
If Command Line Developer tools is not installed, you should see a message asking if you want to install them. Click Install: you do not need to get Xcode if you do not want the full Xcode package.
The SAM project depends on wxWidgets libraries, which you can build in any directory. You will create a symbolic link and change the PATH environment to tell the SAM makefiles where to find the libraries.
The source code for the LK, WEX, SSC, and SAM projects should go in a single parent directory. If you already have a directory for your projects, you can use it, or you can create a new one specifically for SAM. These instructions use the following directory structure as an example:
.../sam_dev/wxWidgets-3.1.1
.../sam_dev/lk
.../sam_dev/wex
.../sam_dev/ssc
.../sam_dev/sam
The lk
, wex
, ssc
, and sam
directories should all be in one directory. The wxWidgets directory does not have to be in the same directory as those four.
-
Download the wxWidgets 3.1.1 source code for Linux, OS X, etc. from https://github.com/wxWidgets/wxWidgets/releases/tag/v3.1.1. The code repository is available in several zip formats. These instructions explain how to unzip the following file:
wxWidgets-3.1.1.tar.bz2
-
Clone the SAM code repositories:
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.The
git clone
command automatically creates a directory for the repository, so you do not need to create a directory before you clone it. For example if you clone thelk
repository into yoursam_dev
directory, Git will create anlk
directory for the repository.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.
-
Create a wxWidgets-3.1.1 directory, and extract the compressed file and tarball into it:
bunzip2 –d wxWidgets-3.1.1.tar.bz2 tar xvf wxWidgets-3.1.1.tar
Note: You may be able to use
tar xvjf
without first runningbunzip2
according to this article on thegeekstuff.You should now have a directory named
wxWidgets-3.1.1
that contains several files and directories: -
From a build folder, run the configure command in the
sam/wxconfigure.macos64
file from the SAM repository. For example, if the file is in/sam_dev/sam
directory in your home directory:mkdir wxWidgets-3.1.1/build cd wxWidgets-3.1.1/build cat ~/sam_dev/sam/build_osx/wxconfigure.macos64 | bash
This
cat
command reads the following command from the file and sends it to the shell to be interpreted to save you some typing:../configure –prefix=$HOME/local/wx-3.1.1 --enable-stl=yes --enable-debug=no --enable-shared=no --with-cocoa --enable-macosx_arch=x86_64 --enable-unicode --enable-webview --with-cxx=11 --with-macosx-version-min=10.9 --with-libjpeg=builtin --with-libpng=builtin --with-regex=builtin --with-libtiff=builtin --with-zlib=builtin --with-expat=builtin --disable-qtkit --disable-mediactrl
Note: The
--disable-qtkit
and--disable-mediactrl
parameters are from the workarounds discussed in this wxWidgets issues ticket. -
Type the following
make
commands to install wxWidgets. The makefile will install wxWidgets in~/local/wx-3.1.1
:make make install
Note: You can use
-j
to increase the number of jobs and speed up the build, for examplemake -j2
ormake -j8
. See this discussion on Stackexchange.When the installation finishes, you should see the following message:
-
Create a symbolic link to the wxWidgets installation directory.
ln -s ~/local/wx-3.1.1/bin/wx-config /usr/local/bin/wx-config-3
-
Test the installation:
wx-config-3 --cflags
If the installation was successful, you should see:
-I/Users/<USER>/local/wx-3.1.1/lib/wx/include/osx_cocoa-unicode-static-3.1 -I/Users/<USER>/local/wx-3.1.1/include/wx-3.1 -D_FILE_OFFSET_BITS=64 -DwxDEBUG_LEVEL=0 -D__WXMAC__ -D__WXOSX__ -D__WXOSX_COCOA__
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>
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.
To conveniently set your environment variables to be set every time you open a terminal, set them in your user .bash_profile 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
Reopen the terminal to update the environment variables.
The build requires CMake 3.12 or higher.
-
In the
sam_dev
folder, save the following text as CMakeLists.txt:cmake_minimum_required(VERSION 3.12) Project(system_advisor_model VERSION 1.0.0) add_subdirectory(lk) add_subdirectory(wex) add_subdirectory(ssc) add_subdirectory(sam)
-
In the
sam_dev
folder save the following ascmake_setup_clean.sh
:cd lk && git pull cd ../wex && git pull cd ../ssc && git pull cd ../SAM && git pull cd ../SAM-private && git pull cd .. export GTEST=/Users/user/Public/Projects/GitHub/NREL/googletest export LKDIR=/Users/user/Public/Projects/GitHub/NREL/lk export WEXDIR=/Users/user/Public/Projects/GitHub/NREL/wex export SSCDIR=/Users/user/Public/Projects/GitHub/NREL/ssc export SAMNTDIR=/Users/user/Public/Projects/GitHub/NREL/SAM rm -rf $LKDIR/build && mkdir $LKDIR/build && cd $LKDIR/build && cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . -j8 --target lk rm -rf $WEXDIR/build && mkdir $WEXDIR/build && cd $WEXDIR/build && cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . -j8 --target wex rm -rf $SSCDIR/build && mkdir $SSCDIR/build && cd $SSCDIR/build && cmake .. -DCMAKE_BUILD_TYPE=Release && cmake --build . -j8 --target ssc rm -rf $SAMNTDIR/build && mkdir $SAMNTDIR/build && cd $SAMNTDIR/build && cmake .. -DCMAKE_BUILD_TYPE=Release && make -j8
To build the Debug version, change the CMAKE_BUILD_TYPE
in each of the 4 commands.
-
From the
sam_dev
folder, runbash cmake_setup_clean.sh
-
To run SAM, type
open SAM.app
at the command line, or open a Finder window, go to the build folder of the SAM project,sam_dev/build/sam
orsam_dev/sam/build
, and double-click the SAM icon.Note. If you want to make a dmg file, you can do so by typing:
bash makedmg.sh
. -
When SAM starts, click Start a new project, and then click Photovoltaic (detailed) and Residential (distributed), and OK.
-
On the Location and Resource page, click View data. That should open a DView window with data from the weather file selected on the Location and Resource page. DView is from WEX, so that confirms that WEX built correctly.
-
Close the DView window.
-
Click through the input pages to see that they display correctly. The user interface uses libraries from wxWidgets and WEX.
-
Click Simulate in the bottom left corner of the SAM window. SAM should run a simulation and display results on the Results page. The results page also uses DView from WEX, and displays data generated by SSC.
-
Click Macros (under the Simulate button), and click the Inverter Sizing Information button. Click Run macro at the top of the window. The macro should run and display a window with information about the inverter's performance. That confirms that LK (also from WEX) is working.