Creation of new package with Hunter C++
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:
if(OPENSSL_FOUND)
target_compile_definitions(... PUBLIC FOO_WITH_OPENSSL=1)
endif()
If package is optional then control behavior explicitly:
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:
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++:
int main() {
hunter_box_1::foo();
}
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:
> cd hunter
[hunter]> git submodule update --init --recursive .
Create branch to work on new package:
Congratulations
Aww yeah, you successfully created a package with hunter C++ and I hope you have not missed out any step.