如何在 CMake 中知道我们正在生成一个包?

发布于 2024-11-15 16:25:11 字数 306 浏览 1 评论 0原文

我希望当用户调用时忽略 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪之触 2024-11-22 16:25:11

CMake 生成包含一些“预定义”make 目标的 make 文件,这些目标遵循使用它们的人所期望的约定。诸如全部、安装、打包和测试等目标。

默认情况下,“install”和“package”make 目标通常依赖于“all”make 目标。 (因此,如果您输入“make install”,它会首先执行“make all”,以确保安装发生之前所有内容都是最新的。与“package”类似。)

“make package”实际上所做的是在幕后调用 cpack :

/full/path/to/cpack --config ./CPackConfig.cmake

如果执行以下命令,您可以看到此命令行被调用:

make package VERBOSE=1

您想在打包案例中跳过 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:

/full/path/to/cpack --config ./CPackConfig.cmake

You can see this command line being invoked if you execute:

make package VERBOSE=1

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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文