如何在 CMake 中知道我们正在生成一个包?
我希望当用户调用时忽略 CMakeLists.txt
文件的一部分,
make package
因此我正在寻找诸如 CMAKE_COMMAND 或 CMAKE_PACKAGING 之类的变量,以便我可以执行
if (CMAKE_COMMAND EQUAL 'package') ...
此操作或
if (CMAKE_PACKAGING) ...
这是否存在?能实现吗?
I want a part of the CMakeLists.txt
file to be ignored when a user calls
make package
I am therefore looking for a variable such as CMAKE_COMMAND or CMAKE_PACKAGING so that I could do
if (CMAKE_COMMAND EQUAL 'package') ...
or
if (CMAKE_PACKAGING) ...
Does this exist? Can it be achieved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CMake 生成包含一些“预定义”make 目标的 make 文件,这些目标遵循使用它们的人所期望的约定。诸如全部、安装、打包和测试等目标。
默认情况下,“install”和“package”make 目标通常依赖于“all”make 目标。 (因此,如果您输入“make install”,它会首先执行“make all”,以确保安装发生之前所有内容都是最新的。与“package”类似。)
“make package”实际上所做的是在幕后调用 cpack :
如果执行以下命令,您可以看到此命令行被调用:
您想在打包案例中跳过 CMakeLists.txt 文件的哪部分?没有像您正在寻找的那样的变量,因为打包不会在 CMake 配置时发生;当用户显式调用“make package”或“cpack”时,它会在构建时间之后发生。
CMake generates make files that contain some "pre-defined" make targets that follow conventions expected by those that use them. Targets such as all, install, package and test.
The 'install' and 'package' make targets typically, by default, depend on the 'all' make target. (So that if you type 'make install' it does a 'make all' first to ensure everything's up to date before the install occurs. Similarly with 'package'.)
What 'make package' actually does is to call cpack under the covers:
You can see this command line being invoked if you execute:
What part of your CMakeLists.txt file do you want to skip in the packaging case? There is no variable such as the one you are looking for, because the packaging does not occur at CMake configure-time; it occurs later, after build time, when the user explicitly invokes 'make package' or 'cpack'.