Automatic builds¶
No dependencies in README¶
Build instructions from the Hunter archive are triggered automatically when
the hunter_add_package
function called, hence there is no need to specify
dependencies in a raw README
file like:
For OSX please do:
> brew install foo boo
For Ubuntu please do:
> sudo apt-get install foo boo
Then run build:
> cmake -H. -B_builds
> cmake --build _builds
Now it’s simply:
Just run build:
> cmake -H. -B_builds # dependencies installed automatically
> cmake --build _builds
Optional dependencies¶
Optional dependency? No problem, optional dependencies are expressed in a straightforward way:
# required dependencies
hunter_add_package(foo)
hunter_add_package(boo)
if(BUILD_WITH_BAR)
hunter_add_package(bar)
endif()
Now instead of:
Additionally if you want bar support please run:
> brew install bar # OSX
> sudo apt-get install bar # Ubuntu
Then run build:
> cmake -H. -B_builds -DBUILD_WITH_BAR=YES
It’s simply:
> cmake -H. -B_builds -DBUILD_WITH_BAR=YES # + install bar
Compared to a ‘requirements.txt’ style approach¶
Note that Hunter’s approach differs from a
requirements.txt-like approach
(i.e. when external packages are specified in a separate file). This allows Hunter to avoid
duplication of logic in many cases, even if the requirements.txt
style approach also automatically downloads
dependencies too.
Imagine that we have to specify dependencies in some kind of requirements.cmake
file and there is a user option BUILD_WITH_BAR
:
# requirements.cmake
if(WIN32 AND BUILD_WITH_BAR)
command_to_install(Bar)
endif()
Or, in the case that it isn’t CMake code, this might by something fancy like requirements.json
:
{
"dependencies":
{
"package": "Bar",
"platform": "windows",
"cmake option": "BUILD_WITH_BAR"
}
}
You would have to repeat the same condition in the CMakeLists.txt
file:
# requirements.cmake
if(WIN32 AND BUILD_WITH_BAR)
command_to_install(Bar)
endif()
# CMakeLists.txt
if(WIN32 AND BUILD_WITH_BAR)
find_package(Bar CONFIG REQUIRED)
target_compile_definitions(... PUBLIC "WITH_BAR")
endif()
Later, when you need to change this dependency in CMakeLists.txt
, you’d better not forget to also modify requirements.cmake
accordingly. Remember real world libraries can have nontrivial chain of conditions, e.g.
OpenCV components.
Stackoverflow