CLion Setup - GT-STAR-Lab/Q-ITAGS GitHub Wiki
Setup Docker
Step 1
Ensure that Dockerfile
, build.sh
, and gurobi/
are in the docker
directory. Acquire a GUROBI web license (gurobi.lic
) and put it in docker/gurobi/
.It is crucial that you do this before you build and run the dockerfile. Also, do NOT remove docker/gurobi/.placeholder
.
Step 2 - Install Host Packages
Install docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Install nvidia-docker2
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt update
sudo apt install -y nvidia-docker2
Create and add yourself to the docker group
sudo groupadd docker
- It is ok if the computer says that the group already exists.
sudo gpasswd -a $USER docker
Then restart the computer. This allows you to build/run the docker without having the escalate privileges via sudo
.
Testing
docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
- If you get a permission denied error, make sure that your user was added to the docker group and that you restarted the computer. You should get an image that looks like this:
Step 4 - Build Docker Image
Go to the docker folder and run the build.sh
script. This will take a few minutes.
Step 4 - Configure Toolchain
Open Settings->Build, Execution, Deployment->Toolchains and create a new Docker Toolchain. Select the grstapse_dev:latest
docker image. Click the gear on the right side of Container Settings:
. A small new window should pop up. Add a new volume binding with the host path being the location of the gurobi.lic
, file that you added the docker/gurobi
folder, make certain this includes gurobi.lic and the container path being /opt/gurobi/gurobi.lic
. Set this volume binding to read-only. Your volume binding should look similar to the one shown below.
Step 5 - CMake Profile
Now we must set up a CMake profile to make use of our new Docker toolchain. (I would in fact make two: one for Debug and one for Release).
Navigate to Settings->Build, Execution, Deployment->Cmake and create a new profile. The only necessary change is selecting the toolchain created in the previous step and making sure that the Build Type is the one you want. Optionally, you can set any CMake options that you need.
- Set
-DBUILD_PYTHON_WRAPPER=ON
if you want the pybind11 functionality and any classes that use embedded python. - Set
-DBUILD_EXECUTABLES=ON
if you want the itags/grstapse executables.
Step 7 - Useful extra settings
Upload on save
Go to Tools->Actions on Save
and check Reformat code
Step 8 - Running/Debugging the Program
From the CMake tab, make sure that you have the newly created CMake profile selected. After the CMake project loads into the container, you should be able to select the CMakeProfile you would like to use in the run configuration switcher in the top right corner of CLion.
Hopefully, if everything went well you should now be able to run and debug code in a docker container!
Setup Auto-Formatting
Navigate to Settings->Editor->Code Style. There should be a line: Settings may be overriden by ClangFormat
. If not then make sure that Enable ClangFormat
is checked.
Setup File and Code Templates
Navigate to Settings->Editor->File and Code Templates.
Under Files
C++ Class Header & C Header File
#set( $PascalCaseName = "" )
#set( $part = "" )
#foreach($part in $NAME.split("_"))
#set( $PascalCaseName = "${PascalCaseName}$part.substring(0,1).toUpperCase()$part.substring(1).toLowerCase()" )
#end
#pragma once
// region Includes
// Global
// External
// Local
// endregion
namespace ${PROJECT_NAME}
{
// region Forward Declarations
// endregion
/*!
* \class ${PascalCaseName}
* \brief
*/
class ${PascalCaseName}
{
public:
//region Special Member Functions
//! Default Constructor
${PascalCaseName}() = default;
//! Copy Constructor
${PascalCaseName}(const ${PascalCaseName}&) = default;
//! Move Constructor
${PascalCaseName}(${PascalCaseName}&&) noexcept = default;
//! Destructor
~${PascalCaseName}() = default;
//! Copy Assignment Operator
${PascalCaseName}& operator=(const ${PascalCaseName}&) = default;
//! Move Assignment Operator
${PascalCaseName}& operator=(${PascalCaseName}&&) noexcept = default;
// endregion
}; // class ${PascalCaseName}
} // namespace ${PROJECT_NAME}
- I usually also create a 'C++ Header File' template
C++ Class & C Source File
#set( $HeaderDirPath = "${PROJECT_NAME}" )
#set( $part = "" )
#set( $first = true )
#foreach($part in $DIR_PATH.split("/"))
#if( $first )
#set($first = false)
#else
#set( $HeaderDirPath = "${HeaderDirPath}/${part}" )
#end
#end
#[#include](/GT-STAR-Lab/Q-ITAGS/wiki/#include)# "${HeaderDirPath}/${NAME}.hpp"
namespace ${PROJECT_NAME}
{
} // namespace ${PROJECT_NAME}
- I usually also create a 'C++ Source File' template
Google Test Source
#set( $CamelCaseName = "" )
#set( $part = "" )
#set( $first = true)
#foreach($part in $NAME.split("_"))
#if($first)
#set( $first = false)
#else
#set( $CamelCaseName = "${CamelCaseName}$part.substring(0,1).toUpperCase()$part.substring(1).toLowerCase()" )
#end
#end
// External
#[#include](/GT-STAR-Lab/Q-ITAGS/wiki/#include)# <gtest/gtest.h>
// Mocks
// Project
namespace ${PROJECT_NAME}::unittests
{
TEST($CamelCaseName)
{
}
} // ${PROJECT_NAME}::unittests
Code
C++ Implemented Function Body
// TODO(${USER})
throw std::logic_error("Not Implemented");
C++ Overridden Function Body
// TODO(${USER})
throw std::logic_error("Not Implemented");
Setup Copyright
Scope
Copyright Profile
Set the copyright text (update this if the copyright changes):
Graphically Recursive Simultaneous Task Allocation, Planning,
Scheduling, and Execution
Copyright (C) 2020-2022
Author: Andrew Messing
Author: Glen Neville
Author: Jiazhen Liu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.