如何读/写入持续存在并在编译之间进行更新的变量?
我正在努力将DLL热载添加到C ++应用中。因此,我打开了MSVC:1个实例的2个实例,当我代码并在另一个实例上编译时,运行该应用程序。断点一开始就击中,我可以继续在第二个实例上代码而无需停止应用程序。
为了支持这一点,我需要读写到构建之间的(半)持久性CMAKE变量。我使用该变量来决定如何命名生成的文件。也就是说,每当我编译一些热加载的DLL时,我都需要在名称之间循环以给出要生成的文件,因为以前的文件是通过运行应用程序使用的。
因此,生成的文件将循环为:
- path/to/to/some.a.pdb
- 路径/to/to/some.b.pdb,
我如何读/写入每个构建/编译的变量,这记住了先前的编译中的值。 CMakeCache对此无效,因为它在配置阶段设置,并且在生成阶段没有更新。也许可以使用发电机表达式来完成。
I'm working on adding DLL hotloading to a C++ app. Because of this, I open 2 instances of MSVC: 1 instance runs the app while I code and compile on the other instance. Breakpoints are hit on the first instance, and I can continue to code on the 2nd instance without stopping the app.
To support this, I need to read and write to a (semi) persistent CMake variable between builds. I use that variable to decide how to name the generated files. That is, every time I compile some hot loadable DLL, I need to cycle between names to give the files being generated, because the previous files are in use by running app.
So, the generated files would cycle as:
- path/to/some.a.pdb
- path/to/some.b.pdb
How can I read/write to a variable every build/compile, which remembers the value from the previous compile. The CMakeCache doesn't work for this, because it gets set during the configure phase and not updated during the generation phase. Maybe it could be done with Generator Expressions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定您可以使用
cmake_< config _ _postfix
。是的,您需要重新配置,但是它不会遇到写作以打开/映射库的问题。来自 documentation
这部分 documentation :
您可以在不同的后缀之间循环循环:
您还可以使用
relwithdebinfo
或debug
,甚至完全自定义配置(您甚至可以创建“ A”和A“ B”配置具有不同的后缀,因此您无需重新运行配置步骤)。I'm pretty sure you can use
CMAKE_<CONFIG>_POSTFIX
. Yes, you need to reconfigure, but it won't run into problems with writing to open/mapped libraries.From the documentation
and this piece of documentation:
You can cycle between different postfixes like so:
You can also use
RelWithDebInfo
orDebug
or even a totally custom config (you could even create an "A" and a "B" config with different postfixes so you wouldn't need to re-run the configure step).