Description
- I've read Brief overview section and do understand basic concepts. [Yes]
- I've read F.A.Q. section and haven't found an answer to my question. [Yes]
- I've read Code of Conduct, I promise to be polite and will do my best at being constructive. [Yes]
Hi. I'm trying to add Hunter (v0.23.288) into an existing project which already has some external dependencies managed in various ways: some are expected to be installed system-wide (e.g. Boost), some are copied into the project itself as git submodules. After modifying the top-level CMake file it has roughly the following sequence of instructions:
cmake_minimum_required(VERSION 3.11)
# Including HunterGate breaks the CMake configuration step.
# Commenting the next 4 lines allows the project to be configured and built.
include("cmake/HunterGate.cmake")
HunterGate(
URL "https://github.com/cpp-pm/hunter/archive/v0.23.288.tar.gz"
SHA1 "6c9b2bc606d86ae31f96a62fc68f0a593024815b"
)
project(foo LANGUAGES CXX)
find_package(Boost COMPONENTS filesystem REQUIRED)
# It does not matter if we actually bring any dependency in using Hunter.
# Leaving this commented simply as a demo where such code would be in a real project.
#hunter_add_package(log4cplus)
#find_package(log4cplus CONFIG REQUIRED)
# mylib.cpp is just `int main() {}`. This library builds OK unless HunterGate is introduced.
# `add_library` (not `find_package` above) is what CMake will complain about when Hunter is enabled.
add_library(MyLibrary SHARED mylib.cpp)
target_link_libraries(MyLibrary PUBLIC Boost::filesystem)
Unfortunately, this yields the following CMake configuration error pointing to the line with add_library(MyLibrary...)
:
Target "MyLibrary" links to target "Boost::filesystem" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
Obviously, the project configures/builds fine unless I add hunter to the play (use HunterGate
), and Boost is clearly being located correctly (even with Hunter enabled) as I see it from the CMake output:
-- Boost version: 1.69.0
-- Found the following Boost libraries:
-- filesystem
I'm aware that Hunter may be used to manage Boost and other libraries, but leaving this option aside for a moment: is the behaviour I observe expected/known?
Is there a way to work this around and let CMake use system-wide installed Boost? I believe, there should be such an option even when Hunter is capable to provide the dependency, esp. for cases of gradual transition to Hunter or because of other reasons.
Info on my env if this helps: Mac OS 10.15, CMake version 3.18.4, Boost installed under /usr/local
.
Many thanks!