Cmake“设置”在“find_path”之后不适用于同一变量被称为
在 Cmake 模块中,我试图找到不同的路径。在某些情况下,我想在最初使用同一变量调用“find_path”后“设置”一个变量:
# general search for this include dir
find_path(LIBRARY_INCLUDE_DIR
NAMES LibraryName/LibraryHeader.h
)
# specific option enabled by user
if(USE_OTHER_LIB)
find_path(OTHER_LIB_ROOT_DIR
NAMES OtherLib/OtherLib.h
)
set(LIBRARY_INCLUDE_DIR ${OTHER_LIB_ROOT_DIR}/database/include)
endif(USE_OTHER_LIB)
这种方法在 Windows XP (CMake 2.8.1) 下运行良好。但是,它在 Mac OS 10.6 (CMake 2.8.3) 下不起作用。有人知道 mac / windows 版本之间是否存在差异以及如何解决这个问题吗?
多谢!
Within a Cmake module I am trying to locate different paths. Under some circumstances I would like to "set" a variable after I initially called "find_path" with the same variable:
# general search for this include dir
find_path(LIBRARY_INCLUDE_DIR
NAMES LibraryName/LibraryHeader.h
)
# specific option enabled by user
if(USE_OTHER_LIB)
find_path(OTHER_LIB_ROOT_DIR
NAMES OtherLib/OtherLib.h
)
set(LIBRARY_INCLUDE_DIR ${OTHER_LIB_ROOT_DIR}/database/include)
endif(USE_OTHER_LIB)
This approach did work fine under Windows XP (CMake 2.8.1). However, it did not work under Mac OS 10.6 (CMake 2.8.3). Does somebody know if there is a difference between the mac / windows version and how to resolve this?
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是关于“set”和 CMake 缓存变量的常见误解。
该行:
为 LIBRARY_INCLUDE_DIR 设置本地覆盖值,该值对 CMakeLists 文件的其余处理有效,但对同名的缓存变量没有影响。因此,它在 cmake-gui 或 ccmake 缓存编辑程序中不可见。
如果你想让它可见,你必须将它的值强制放入同名的缓存变量中,也许像这样:
然而,这通常是不受欢迎的,因为当最终用户调整 cmake-gui 中的值时程序中,您的代码将使用 FORCE-d 值覆盖用户的选择。所以...我建议只使用您一直在使用的线:抵抗力。
要查看它确实生效,只需在 CMakeLists.txt 的末尾添加以下代码:
所以...鉴于您的代码是正确的,那么一定有其他原因导致您认为出了问题。我很好奇那可能是什么......也许是您的下一个 Stack Overflow 问题。
This is a common misconception about "set" and CMake cache variables.
The line:
sets a local override value for LIBRARY_INCLUDE_DIR that takes effect for the remainder of the processing of the CMakeLists file, but it has no effect on the cache variable of the same name. Therefore, it is not visible in the cmake-gui or ccmake cache editing programs.
If you wanted to make it visible, you would have to force its value into the cache variable of the same name, perhaps like this:
This is generally frowned upon, however, because then when an end user adjusts the value in the cmake-gui program, your code will overwrite the users choice with the FORCE-d value. So... I would recommend just using the line you've been using: resist the FORCE.
To see that it really does take effect, simply add this code at the end of CMakeLists.txt:
So... given that your code is correct, there must be something else going on that causes you to think that something's wrong. I'm curious about what that might be... perhaps your next Stack Overflow question.