Conan and CMake  Setup for C++ Development on VSCode
Tags: tutorial, vscode, cpp, packagemanagement
Published: 2021-09-12 18:38:47

**Hi There, Devs! :innocent:**
We have come across various tutorials to either setup Conan or CMake with IDEs like Visual Studio or on the Terminal. These tutorials are great but for me personally I am not a big fan of Visual Studio but a very big fan of Visual Studio Code (as it is very lightweight and very much easy going for my PC).

![VSCode vs VS Meme](https://i.ibb.co/KWD4WHR/VSCode-Meme.jpg)

I mean Microsoft did a great job on retaining people like me from using other editors and still using their product.

Now for the main topic as to why we are still here...

This is a barebones tutorial for setting up Conan and CMake on Visual Studio Code, with no packages and nothing. Just a structure which I personally follow and I believe you should follow too as I've had success with it till now and only very few errors.

## :hammer_and_wrench:Requirements  

* [Visual Studio Code](https://code.visualstudio.com/download)
	* [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) - Must Have
	* [c/c++ definition generator](https://marketplace.visualstudio.com/items?itemName=reignofwebber.c-cpp-definition-generator) - Recommended
	* [CMake](https://marketplace.visualstudio.com/items?itemName=twxs.cmake) - Must Have
	* [CMake Tools](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools) - Must Have
	* [Todo Tree](https://marketplace.visualstudio.com/items?itemName=Gruntfuggly.todo-tree) - Recommended
* [Python](https://www.python.org/downloads/) - 3.7 or greater
* pip
* [CMake](https://cmake.org/download/) - 3.20.0 or greater
* Python Dependencies
	* [virtualenv](https://pypi.org/project/virtualenv/)
	* [conan](https://pypi.org/project/conan/) in virtualenv

## :wrench:Virtual Environment Setup for Conan Installation

1. [Download and Install | Python](https://www.python.org/downloads/) (skip if already installed)
2. [Download and Install | pip](https://www.geeksforgeeks.org/download-and-install-pip-latest-version/) (skip if already installed)
3. Make a directory for you Project, for example co-cpp-setup  
```
mkdir co-cpp-setup 
cd co-cpp-setup 
code . 
```
4. Make a directory for the virtualenv, for example venv
``` 
mkdir venv 
```
5. Initialize a virtualenv in venv folder
``` 
python -m venv venv 
```
6. Activate the virtualenv
**(For Windows)**
``` 
.\venv\bin\activate
 ```
7. Install Conan Package Manager <br/> ``` pip install conan ```

> To **Deactivate** the virtualenv ``` deactivate ```

## :nut_and_bolt:CMakeProject on VSCode

1. [Download and Install | CMake](https://cmake.org/download/) (skip if already installed)
2. Make sure to have **CMake** and **CMake Tools** installed in your local VSCode Copy.
3. Create the files required such that the folder structure for ``` co-cpp-setup ``` Directory is as shown.
 ![Folder Structure 1](https://i.ibb.co/74TRHHd/folder-struct-1.png)
4. Add barebone minimum code ``` int main() ``` to main.cpp and Reload the VSCode Window.
5. With CMake Tools installed it automatically detects the project now as a CMake Project and asks you to select a Kit. 
 ![Kit Selection Image](https://i.ibb.co/ZHpNyd5/kit-selection.png)
6. Then Configure the project for the first time. ``` Ctrl + Shift + P ```
 ![Configure the Project](https://i.ibb.co/Bf2KTyx/cmake-configure.png)
7. If you have followed everything correctly till here, a new directory name build will appear in your folder structure, after a successful Configuration of an empty ```CMakeLists.txt``` file.

## :gear:Conan on VSCode

1. We already have installed ```conan``` using ```pip``` in a virtualenv.
2. Now, we create a new txt file, ```conanfile.txt``` , for getting packages from **conancenter**.
3. Now the [Getting Started](https://docs.conan.io/en/latest/getting_started.html) section from conan [documentation](https://docs.conan.io/en/latest/) can be followed to go ahead with your projects, or you can go ahead with your packages for your projects.

## What's Next :question:

:arrow_right: This is Part 1 of Conan and CMake for CPP Development. In the next part we will see how to use this bare bone template for setting up a barebone OpenGL Project with GLEW, GLFW and ImGUI.

:arrow_right: Get this barebone setup on GitHub to be uploaded along with the Part2 tutorial.

:soon: Very soon I'll upload a video on how to setup (Part 1) and how to use (Part 2) on YouTube and upload the links in this article.

Thanks for your time and love from :india: ! :v: