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).



Prerequisites

• 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:

find_package(OpenSSL)
if(OPENSSL_FOUND)
  target_compile_definitions(... PUBLIC FOO_WITH_OPENSSL=1)
endif()

If package is optional then control behavior explicitly:

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

Same with the programs:

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

Step 2 : Add package to Hunter

Recommended name for the package is lowercase separated with underscore.
C++:

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

CMake with Hunter:

hunter_add_package(hunter_box_1)
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 https://github.com/hunterbox/hunter
> cd hunter
[hunter]> git submodule update --init --recursive .

Create branch to work on new package:

[hunter]> git checkout -b pr.hunter_box_1


Congratulations


People who read this also read

article

Application of smtplib module

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