Repository navigation
usr.adding.new.package
If package is CMake project without third party dependencies which installed using cmake --build <dir> --target install then integration is pretty easy. Here is a step-by-step tutorial for a tiny package example-A. Other tutorials:
Install/verify project using Wget, OpenSSL and CMake:
> wget https://github.com/forexample/example-A/archive/v1.0.1.tar.gz
> openssl sha1 v1.0.1.tar.gz
SHA1(v1.0.1.tar.gz)= 48179067d11828dc347f98fc148654f88766529d
> tar xf v1.0.1.tar.gz
> cd example-A-1.0.1/
> cmake -H. -B_builds -DCMAKE_INSTALL_PREFIX=`pwd`/_install
> cmake --build _builds/ --target install
> ls _install/*
_install/libexample_A.a
_install/example_A:
foo.hpp> cat CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
include(ExternalProject) # ExternalProject_Add
ExternalProject_Add(
Example
URL https://github.com/forexample/example-A/archive/v1.0.1.tar.gz
URL_HASH SHA1=48179067d11828dc347f98fc148654f88766529d
CMAKE_ARGS
"-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_LIST_DIR}/_install"
)
> cmake -H. -B_builds
> cmake --build _builds/
> ls _install/*
_install/libexample_A.a
_install/example_A:
foo.hppFirst, new hunter.cmake file need to be add to projects directory
> git clone https://github.com/ruslo/hunter
> export HUNTER_ROOT="`pwd`/hunter"
> cd ${HUNTER_ROOT}
> mkdir cmake/projects/Example
> cat cmake/projects/Example/hunter.cmake
# !!! DO NOT PLACE HEADER GUARDS HERE !!!
# Load used modules
include(hunter_add_version)
include(hunter_download)
include(hunter_pick_scheme)
# List of versions here...
hunter_add_version(
PACKAGE_NAME
Example
VERSION
"1.0.1"
URL
"https://github.com/forexample/example-A/archive/v1.0.1.tar.gz"
SHA1
48179067d11828dc347f98fc148654f88766529d
)
hunter_add_version(
PACKAGE_NAME
Example
VERSION
"1.0.0"
URL
"https://github.com/forexample/example-A/archive/v1.0.0.tar.gz"
SHA1
d9b25aeadde5a5b1b60ba2dd39ed1a7a4846589a
)
# Probably more versions for real packages...
# Pick a download scheme
hunter_pick_scheme(DEFAULT url_sha1_cmake) # use scheme for cmake projects
# Download package.
# Two versions of library will be build by default:
# * libexample_A.a
# * libexample_Ad.a
hunter_download(PACKAGE_NAME Example)Second, specify version in default config:
> grep Example cmake/config/default.cmake
hunter_config(Example VERSION 1.0.1)Package configuration can be also be performed at a project level, e.g. customization can be performed within ${CMAKE_CURRENT_LIST_DIR}/cmake/Hunter/config.cmake. See customizing external packages for more detailed information.
That's all! Now package can be used (see next section for testing):
> cat CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
include("cmake/HunterGate.cmake")
# If Hunter is cloned this line will not
# be used if fact. See 'testing' section for me info
HunterGate(
URL "https://url/to/your/hunter-archive.tar.gz"
SHA1 "put-archive-sha1-here"
)
project(TestExampleDownload)
hunter_add_package(Example)Library can be found by EXAMPLE_ROOT cmake variable:
find_library(
example_release
example_A
${EXAMPLE_ROOT}
)
find_library(
example_debug
example_A${CMAKE_DEBUG_POSTFIX}
${EXAMPLE_ROOT}
)
message("Release: ${example_release}")
message("Debug: ${example_debug}")
EXAMPLE_ROOT variable assembled by moving package name to upper case and adding _ROOT. For the packages containing - char the "snake case" variant also available. E.g. for package foo-bar-boo both FOO-BAR-BOO_ROOT and FOO_BAR_BOO_ROOT can be used.
Note that for real packages there will be more code like searching for EXAMPLE_INCLUDE_DIR or setting EXAMPLE_COMPILE_DEFINITIONS.
Note that CMake modern-style packages can automatically produce and install CMake configs for find_package commands. This helps to avoid manually writing/supporting and distributing endless list of Find<Package>.cmake modules. Also, what is very important for Hunter, it's the one of the painless ways to support relocation. I.e. only config-mode packages (native or emulated) with imported targets can be cached and downloaded as prebuilt binary archive from build servers. Plus only imported targets works nicely with non standard build types like MinSizeRel or RelWithDebInfo. It is highly recommended to have such feature. Read this overview if you want to have code:
find_package(Example CONFIG REQUIRED)
instead of bunch of find_library in snipped from previous paragraph.
If your package is already relocatable use command hunter_cacheable to allow caching.
Let's test it (see how to do it nicely):
> cmake -H. -B_builds
-- [hunter] HUNTER_ROOT: /.../Hunter
-- [hunter] [ Hunter-ID: 7912489 | Config-ID: f1ec619 | Toolchain-ID: f8714ae ]
...
-- [hunter] EXAMPLE_ROOT: /.../Hunter/_Base/7912489/f1ec619/f8714ae/Install (ver.: 1.0.1)
-- [hunter] Building Example
...
-- downloading...
...
src='https://github.com/forexample/example-A/archive/v1.0.1.tar.gz'
-- [download 100% complete]
Install the project...
-- Install configuration: "Release"
...
-- Install configuration: "Debug"
...
Release: /.../Hunter/_Base/7912489/f1ec619/f8714ae/Install/libexample_A.a
Debug: /.../Hunter/_Base/7912489/f1ec619/f8714ae/Install/libexample_Ad.a
Note that it doesn't make sense to include in build such stuff like examples, tests or documentation. Please check that your package has CMake option to disable it and apply extra variables to all versions (if options is not disabled by default) using hunter_cmake_args function:
# bottom of cmake/projects/Foo/hunter.cmake
...
hunter_cmake_args(
Foo
CMAKE_ARGS
FOO_BUILD_EXAMPLES=OFF
FOO_BUILD_TESTS=OFF
FOO_BUILD_DOCUMENTATION=OFF
)
hunter_pick_scheme(DEFAULT url_sha1_cmake)
hunter_download(PACKAGE_NAME Foo)Options set by hunter_cmake_args have lower precedence than options set by hunter_config(... CMAKE_ARGS ...)
Default build type(s) can be set by hunter_configuration_types:
hunter_configuration_types(Foo CONFIGURATION_TYPES Release)
hunter_download(PACKAGE_NAME Foo)User can overwrite this default by using custom hunter_config parameters.
Please check that your package respect (i.e. doesn't rewrite) such CMake variables like:
- CMAKE_INSTALL_PREFIX (critical)
- CMAKE_{C,CXX}_FLAGS + variations (critical)
- CMAKE_{C,CXX}_COMPILER + friends (critical)
- CMAKE_BUILD_TYPE (not critical, but recommended)
- CMAKE_CONFIGURATION_TYPES (not critical, but recommended)
- BUILD_SHARED_LIBS (not critical, but may result some errors)
Feel free to open new issue if you want to ask any questions.
- HOME
- Packages
- Android-Apk
- Android-Modules
- Android-SDK
- ArrayFire
- Assimp
- Async++
- Avahi
- BZip2
- Boost
- Boost.compute
- Boost.process
- CLAPACK
- Comet
- CppNetlib.URI
- CsvParserCPlusPlus
- Eigen
- Expat
- GPUImage
- GSL
- GTest
- GMock
- Igloo
- IntSizeof
- Jpeg
- JsonSpirit
- LLVM (Clang)
- Leathers
- Libssh2
- Lua
- MySQL-client
- nlohmann::json
- OpenCV
- OpenSSL
- PNG
- Poco C++
- PostgreSQL
- Protobuf
- Qt
- Qt-Android-CMake
- QtQmlManager
- RapidJSON
- Sugar
- TIFF
- Washer
- WTL
- ZeroMQ
- ZMQPP
- ZLIB
- rabbitmq-c
- sparsehash
- ccv
- cereal
- convertutf
- crashpad
- cvmatio
- dest
- dlib
- eos
- flatbuffers
- fmt
- freetype
- glm
- glog
- half
- hdf5
- ios_sim
- irrXML
- libyuv
- log4cplus
- minizip
- odb-pgsql
- odb-mysql
- ogles_gpgpu
- openddlparser
- poly2tri
- polyclipping
- spdlog
- szip
- thread-pool-cpp
- tinydir
- websocketpp
- msgpack
- wxWidgets
- xgboost
Don't see packages you need? Feel free to leave a package request.