C++/CMake Build Instructions

We’ll be using “out of source” builds. If you’re using the lab machines, g++ and CMake are already installed. To compile your code from the command line, follow these steps from the folder containing CMakeLists.txt.

> mkdir build
> cd build
> cmake ..
> make -j4

Linux

Use a package manager to download cmake. For example, with ubuntu,

> sudo apt-get update
> sudo apt-get g++
> sudo apt-get install cmake

Follow the steps above to build and run the program from the command line.

OSX

You can use homebrew/macports or install these manually.

Make sure the commands g++ and cmake work from the command prompt. If you want to use Xcode as your IDE, then do the following from the folder containing CMakeLists.txt.

> mkdir build
> cd build
> cmake -G Xcode ..

This will generate Lab01.xcodeproj project that you can open with Xcode. To run, change the target to Lab01 by going to Product -> Scheme -> Lab00. Then click on the play button or press Command+R to run the application. Edit the scheme to add command-line arguments or to run in release mode.

Windows

You’ll need to download these manually.

Make sure the command cmake works from the command prompt. On Windows, you’ll be using Visual Studio as the IDE. Run the following from the folder containing CMakeLists.txt. to generate a solution file.

> mkdir build
> cd build
> cmake ..

By default on Windows, CMake will generate a Visual Studio solution file, Lab01.sln, which you can open by double-clicking. If you get a version mismatch, you may have to specify your visual studio version, for example:

> cmake -G "Visual Studio 14 2015" ..

Other versions of Visual Studio are listed on the CMake page (http://cmake.org/cmake/help/latest/manual/cmake-generators.7.html).