admin管理员组文章数量:1434913
I am developing a package, say, TOOL with dependency package DEPY. In TOOL's CMakeLists.txt I may call find_package(DEPY)
and may obtain that DEPY_FOUND
is true. Then I may (depending on other things) declare via a variable, say, TOOL_HAVE_DEPY that I actually rely on DEPY and start using it, e.g., by adding targets from DEPY to those of TOOL.
I also create a tool-config.cmake
file and came up with the following code to (only) search for DEPY if TOOL_HAVE_DEPY is true, and declare TOOL to not be found if that fails.
set(TOOL_FOUND 1) # Initially we declare TOOL to be found.
if(@TOOL_HAVE_DEPY@) # Disable this block in case configuration of TOOL did not find DEPY.
if(NOT DEPY_FOUND) # No need to do anything in case DEPY was already found.
find_dependency(DEPY) # Find DEPY.
if(NOT DEPY_FOUND) # If that failed.
if(NOT TOOL_FIND_QUIETLY)
message(WARNING "DEPY was not found, but is required for TOOL.")
endif()
set(TOOL_FOUND 0) # TOOL was built with DEPY but when finding it, DEPY was not found.
endif()
endif()
endif()
Now it may happen that the configuration of TOOL only found DEPY because of some settings such as setting a DEPY_DIR
(environment) variable or build parameter. To support that I could add
if(NOT DEPY_DIR)
set(DEPY_DIR @DEPY_DIR@)
endif()
just before the find_dependency
call. However, this only works if DEPY_DIR
was really the reason for finding DEPY, and it also sets the DEPY_DIR
variable, which may have side-effect that I cannot foresee right now.
My questions are:
- Is there a better way to ensure that dependencies are found?
- Is there a standardized / recommended way for how a
depy-config.cmake
orFindDEPY.cmake
would provide information that is necessary to again find exactly the same configuration? I imagine something like declaringDEPY_FOUND_DIR
that is set to a directory such that settingDEPY_DIR
to that directory makes sure to find exactly the same configuration again?
In fact I would even add version information to the find_dependency
call. Otherwise, if two versions of DEPY are lying around, TOOL is built with one, then it can cause trouble if someone using TOOL searchers for DEPY and finds the other version.
本文标签: How to make sure in a CMake Config that finddependency will actually find a dependencyStack Overflow
版权声明:本文标题:How to make sure in a CMake Config that find_dependency will actually find a dependency? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745633056a2667388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论