Creation of new package with Hunter C++

Author - Neelima Mohanty
19/02/2022 | 10:30 PM

Hunter is a CMake driven cross-platform package manager for C/C++1 projects. With the help of Hunter you can
organize builds for Linux, Windows, macOS, iOS, Android, Raspberry Pi and other platforms. Third-party external
projects are highly customizable, effectively allowing you to have myriad variants of directories with them based on
combinations of version to build, static/shared, CMake -D options, Release/Debug, etc.
This is a guide for adding new package to Hunter. We start with the simple one (CMake based, no dependencies),
then cover “hunterization” (CMake based, depends on other packages). Final is a most complex one (non-CMake
packages, creating custom build scheme).


• Knowledge about Hunter and CMake.
• Familiarity with C++ programming language.
• CMake and hunter setup.

User Guide

Follow the steps written below:

Step 1 : Environment

Configuration of the package should be predictable. For example it should not depend on the fact that some package already installed or not:

  target_compile_definitions(... PUBLIC FOO_WITH_OPENSSL=1)

If package is optional then control behavior explicitly:

option(FOO_WITH_OPENSSL "Build with OpenSSL" ON)
  find_package(OpenSSL REQUIRED) # fatal error if not found!
  target_compile_definitions(... PUBLIC FOO_WITH_OPENSSL=1)

Same with the programs:

find_program(PYTHON_EXE python) # Use 'find_package(PythonInterp)' in real code
# generate some extra code

Step 2 : Add package to Hunter

Recommended name for the package is lowercase separated with underscore.

#include <hunter_box_1/hunter_box_1.hpp>
int main() {
// file hunter_box_1.hpp
namespace hunter_box_1 {
} // namespace hunter_box_1

CMake with Hunter:

find_package(hunter_box_1 CONFIG REQUIRED)
target_link_libraries(... hunter_box_1::hunter_box_1)

Step 3 : Fork Hunter

Hunter hosted on GitHub service where common way to add code is to fork project and create pull request.
Fork cpp-pm/hunter, clone your fork and initialize all submodules:

> git clone
> cd hunter
[hunter]> git submodule update --init --recursive .

Create branch to work on new package:

[hunter]> git checkout -b pr.hunter_box_1


People who read this also read


Application of smtplib module

Author: Neelima Mohanty
20/01/2022 | 10:30 PM