gpt4 book ai didi

How to pass a variable from CMake to conanfile.py(如何将变量从CMake传递给conanfile.py)

转载 作者:bug小助手 更新时间:2023-10-28 13:40:32 27 4
gpt4 key购买 nike



I want to pass a variable/value from a CMake file to conanfile.py. The CMake file will be called during build method in conanfile.py and I would like to access this variable/value in package method of conanfile.py. How can I do that?

我想将CMake文件中的变量/值传递给conanfile.py。CMake文件将在conanfile.py的构建方法过程中被调用,我想访问conanfile.py的包方法中的这个变量/值。我怎么能做到这一点?


更多回答

CMake CACHE variable are saved in CMakeCache.txt file in the build directory. So, if you know that the variable you want to retrieve is the CACHE'd one, you could parse content of CMakeCache.txt (you will find the format of that file to be quite simple). Alternatively, you may modify your CMake project so it will create a file with a variable's value. So after cmake completes, your conanfile.py could open that file and read the value from it.

CMake缓存变量保存在Build目录下的CMakeCache.txt文件中。因此,如果您知道要检索的变量是缓存的变量,则可以解析CMakeCache.txt的内容(您会发现该文件的格式非常简单)。或者,您可以修改您的CMake项目,使其创建一个具有变量值的文件。因此,在cmake完成后,conanfile.py可以打开该文件并从中读取值。

@Tsyvarev thanks for the comment. If parsing the content of a file is the only option, then I will directly parse the CMake file itself which sets the value/variable. Thanks oncea again for this idea!

@Tsyvarev感谢您的评论。如果解析文件的内容是唯一的选择,那么我将直接解析设置值/变量的CMake文件本身。再次感谢Oncea的这个想法!

Yes, the package() method has access to the source and build folders, the easiest seems to just parse the file there.

是的,Package()方法可以访问源代码和构建文件夹,最简单的方法似乎只是解析那里的文件。

优秀答案推荐
更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com