![]() overriding find_package using FetchContent_Declare(OVERRIDE_FIND_PACKAGE) and overriding FetchContent with FetchContent_Declare(FIND_PACKAGE_ARGS). So if I understand correctly that part is to override the other definitions e.g. FETCHCONTENT_TRY_FIND_PACKAGE_MODE = NEVER.Maybe works for PkgA using FETCHCONTENT_UPDATE_DISCONNECTED_?.Fails for PkgC because system will take precedence.FETCHCONTENT_TRY_FIND_PACKAGE_MODE = ALWAYS/OPT_IN.I have thought about hacking something with FETCHCONTENT_SOURCE_DIR_, but couldn’t address these situations Case A The project author designs all PkgA-E in a consistent manner, let’s say with FetchContent and FIND_PACKAGE_ARGS ![]() User wants PkgE to try the system installed version and if not possible default to downloaded source source.User wants PkgD to try the system installed version and if not possible default to git submodule source.User wants PkgC to use the downloaded source, ignore system installed.User wants PkgB to use the git submodule source, ignore system installed.User wants PkgA to always use system installed version, error if not found.Let’s consider the following package situations, and an extreme case where we want all to be setup: You also will end up seeing all calls to FetchContent_MakeAvailable() for all dependencies that go via that route, not just the one dependency that you really want to affect, so your logic would have to account for that. ![]() One down side is you would have to check for FIND_PACKAGE_ARGS and form your call to find_package() using those, if present (not crazy hard). This has the advantage that you get to see the FetchContent_Declare() arguments that were selected and then choose to act, rather than having to find them and lift them out to an earlier call to FetchContent_Declare() (the approach of workaround 1). You could intercept FetchContent_MakeAvailable() calls and make it try find_package() yourself. Workaround 2:Īnother approach is to define your own dependency provider. That may mean you need to find what details to use for the other arguments in that call though, depending on how you want to define it. If this is something you want to do as a user, that can be in a file you include via PROJECT_TOP_LEVEL_INCLUDES, for example. Since FetchContent operates on a “first to define, wins” approach, you can call FetchContent_Declare() with whatever details you want early on.
0 Comments
Leave a Reply. |