Skip to content

example.custom.config.id

Ruslan Baratov edited this page Apr 22, 2015 · 5 revisions

Package version and extra CMake options can be set in user's config.cmake file.

Custom package version

# CMakeLists.txt
HunterGate(
    URL "https://github.com/ruslo/hunter/archive/v0.8.10.tar.gz"
    SHA1 "9308d01ea52c7b8cf1347073c982c679dbac3c09"
    LOCAL # <----- Use local config.cmake
)
...
hunter_add_package(GTest)
# cmake/Hunter/config.cmake
hunter_config(GTest VERSION 1.7.0-hunter-9)
hunter_config(ZLIB VERSION 1.2.8-hunter-1)

Custom CMake options

# cmake/Hunter/config.cmake
hunter_config(GTest VERSION 1.7.0-hunter-9 CMAKE_ARGS GTEST_SUPER_MODE=ON)
hunter_config(ZLIB VERSION 1.2.8-hunter-1 CMAKE_ARGS ZLIB_FEATURES=FEATURE1;FEATURE2)

If you set HUNTER_STATUS_DEBUG=ON you can see that options added to build:

-- [hunter *** DEBUG *** 2015-04-20T15:40:12] Add extra CMake args: 'GTEST_SUPER_MODE' = 'ON'
-- [hunter *** DEBUG *** 2015-04-20T15:40:12] Add package: GTest
-- [hunter *** DEBUG *** 2015-04-20T15:40:12] Download scheme: url_sha1_release_debug
-- [hunter *** DEBUG *** 2015-04-20T15:40:12] Url: https://github.com/hunter-packages/gtest/archive/v1.7.0-hunter-9.tar.gz
-- [hunter *** DEBUG *** 2015-04-20T15:40:12] SHA1: 8a47fe9c4e550f4ed0e2c05388dd291a059223d9
-- [hunter *** DEBUG *** 2015-04-20T15:40:54] Add extra CMake args: 'ZLIB_FEATURES' = 'FEATURE1'
-- [hunter *** DEBUG *** 2015-04-20T15:40:54] Add extra CMake args: 'ZLIB_FEATURES' += 'FEATURE2'
-- [hunter *** DEBUG *** 2015-04-20T15:40:54] Add package: ZLIB
-- [hunter *** DEBUG *** 2015-04-20T15:40:54] Download scheme: url_sha1_release_debug
-- [hunter *** DEBUG *** 2015-04-20T15:40:54] Url: https://github.com/hunter-packages/zlib/archive/v1.2.8-hunter-1.tar.gz
-- [hunter *** DEBUG *** 2015-04-20T15:40:54] SHA1: 24c89e4b193a56bb411fa9878968002ebe2c6209

No effects on CMakeLists.txt

Note that this file configured internally in Hunter. E.g. variable from config.cmake will not be visible in CMakeLists.txt:

# cmake/Hunter/config.cmake
hunter_config(GTest VERSION 1.7.0-hunter-9 CMAKE_ARGS GTEST_SUPER_MODE=ON)
set(HELLO_FROM_CONFIG "Hello")
# CMakeLists.txt
HunterGate(...)
message("Config say: '${HELLO_FROM_CONFIG}'")
> cmake -H. -B_builds
Config say: ''

CMake conditions

config.cmake is a usual CMake-code file, so such commands like if and global variables like WIN32 can be used:

if(WIN32)
  hunter_config(GTest VERSION 1.7.0-hunter-9 CMAKE_ARGS GTEST_SUPER_MODE=ON)
endif()

Clone this wiki locally