Skip to content

Building mahi util

Nathan B Dunkelberger edited this page Nov 17, 2020 · 4 revisions

Previous: Getting Started

Note: These steps are not required for using mahi-util as a part of your code-base, but this process will build the examples for you, and will give you an opportunity to explore the

Requirements

This guide assumes you've already downloaded cmake, git, and the msvc compiler (see Getting Started). We would also recommend that you have VS Code installed, but it is not necessary.

Getting the code

The first thing you want to do is to get the files from github, and put them on your own computer. Github is based on the open source tool, git, which you installed in Getting-Started. In general, we recommend (but don't require) you store all repositories pulled from github in a general location, like C:/Git/. We will assume you are working in that directory for the rest of the tutorial.

To start, open a powershell terminal and move to the C:/Git/ directory. From there, you can use the git command to directly copy the source code directly from the desired repository to a new folder with the same name as the repository.

> cd C:/Git/
> git clone https://github.com/mahilab/mahi-util

From there, we recommend you open the folder C:/Git/mahi-util in the VS Code IDE, but we will provide the instructions to handle it with or without the IDE.

Generating Build Files

Open a powerhsell terminal (or use the one from before) and navigate to the root mahi-util folder (e.g. cd C:/Git/mahi-util/)) and run the following commands:

> mkdir build  # make new directory for our out-of-place build
> cd build     # change directory to ./mahi-util/build

Note: Here we have named our build folder build. We could have named this folder anything, and if you plan to build your work for multiple devices/platforms, it's suggested you use a unique name such as build-quanser, build-myrio, etc.

> cmake .. -G "Visual Studio 16 2019" -A x64         # 64-bit compile (you probably want this)

or

> cmake .. -G "Visual Studio 16 2019" -A Win32       # 32-bit compile

Breaking these commands down, cmake .. calls CMake and tells it to look one directory up for CMakeLists.txt, -G "[GENERATOR STRING]" sets the generator, and -A [PLATFORM] defines the target platform you are developing for. CMake:

The CMake output should look something like this:

-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.24.28316.0
-- The CXX compiler identification is MSVC 19.24.28316.0

...

Building mahi::util examples
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/nbd2/Desktop/mahi-util/build

Once CMake has completed, the build folder will be populated with all of the necessary build files among other CMake specific files. Next, we move on to building mahi-util and examples from the generated files.

Building and Installing

In the same terminal as before:

> cmake --build . --target install --config Release

Under the hood, this calls the MSVC compiler to build mahi-util in the Release configuration, as well as building all of the examples. These will be located in mahi-util\build\Release and mahi-util\build\examples\Release, respectively. You make also wish to build in the Debug configuration as well:

> cmake --build . --config Debug

Note: If you decided to install the VS Code, then you can do these steps using commands there instead. See Setting Up a Visual Studio Code IDE for more details