Support for vcpkg in CLion
Dependency management is one of the biggest pain points for C++ developers. Most of them still build libraries as part of their projects, which is not an easy task given the variety of possible build systems in the C++ world. However, as many ecosystem research studies have shown, including our own, C++ developers are starting to more actively use vcpkg and Conan for managing dependencies.
This is why we’re introducing support for vcpkg in CLion! If you’ve never heard of vcpkg, their GitHub page is a good place to start and learn more.
How to install vcpkg
If you don’t yet have vcpkg installed, CLion can help you do so. First, go to View | Tool Windows and open the Vcpkg:
Click on the + icon and then specify the name and URL of your vcpkg repository, as well as the installation directory (or rely on the default value suggested):
Finally, click OK and wait for the repository to be cloned. This might take some time. If you already have vcpkg installed, simply specify the directory where it is located in the Installation directory field. CLion will look for the vcpkg folder in it.
vcpkg provides a CMake toolchain file, which CLion will link to the CMake profiles you selected in the dialog when adding a package manager. You will be able to edit the list of CMake profiles in which you’d like to use this vcpkg repository later.
Browsing and installing packages
After a successful installation, you can browse the list of packages, see package details, and install the packages you need. Let’s find the Google Test package (just type “
gte” and speed search will get you there) and install it so we can use it in our project:
After the package is successfully installed, you can ask CLion to add it to vcpkg.json in the root of the project:
Alternatively, you can ask CLion to do it automatically:
To use Google Test in our project, we need to update the CMakeLists.txt file. CLion can help you write the CMake code you need for that. Just use the Add packages to CMakeLists.txt action after the package installation. Copy the code suggested by CLion, paste it into the CMakeLists.txt file, and update the target link name (
main) to the one you want Google Test to be linked to:
Updating vcpkg and associated packages
The other useful actions that you can perform from the Vcpkg tool window include:
- Update All (the arrow icon) – update the vcpkg Git repository to the latest version and then check the current version of the vcpkg Git repository for available package updates.
- Upgrade All (upgrade icon) – update the vcpkg Git repository to the latest version and then update all installed packages to their latest versions from the vcpkg Git repository.
- Check for Updates – quickly check whether there are any updates in the vcpkg Git repository.
- Update Repository – check the current version of the vcpkg Git repository for available package updates.
- Upgrade Repository – update all existing packages to the latest version that is in the installed version of the vcpkg Git repository.
- Update Vcpkg Repository – update the vcpkg Git repository to the latest version.
Quick-fixes for missing packages
If you add #include for the header file from a package that is not yet installed. The compilation will fail and CLion will suggest a “Fix…” message there:
A similar quick-fix will be suggested when you use a package in a CMake script that is not yet installed. A “Fix…” message will appear in the CMake tool window near the CMake loading error:
After the package is successfully installed, you can see its details inside the Installed subtree in the Vcpkg tool window. Note that for now, you have to manually reload CMake after installing the package (CPP-31802). We’ll work to remove this requirement in further updates.
CLion’s support for vcpkg is still under development, and we’re planning to address the following known issues:
- Add support for vcpkg for the Cygwin (CPP-31665), Remote (CPP-30683), Docker (CPP-30684), and WSL (CPP-30685) toolchains.
- Add support for vcpkg registers (CPP-31075).
- Add a quick-fix for missing packages to the code editor (CPP-31662).
Try working with vcpkg in CLion and let us know what you think!
Your CLion team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!