如何使用CMake生成具有个性化命令的Makefile?
我喜欢保持我的 Makefile 的灵活性和多功能性。我通常添加到 make
命令的任务之一是 tar
,例如以下指令可以完成这项工作:
tar:
tar -cvf $(PROGNAME).tar $(SRCS) Makefile
我的问题是:如何使用 CMake 来生成个性化命令,例如 tar
?
我想查看一些代码示例。
对于完整的功能,创建项目的组件并能够将它们用作参数将很有用。
(示例:仅归档头文件或某些特定库)。
预先感谢您的回答!
I like to keep my Makefiles flexible and multifunctional. One of the tasks I usually add to make
command is tar
, for example the following instruction does the job:
tar:
tar -cvf $(PROGNAME).tar $(SRCS) Makefile
My question is: How can CMake be used to generate personalized commands like tar
?
I would like to see some code samples.
For the full functionality it would be useful to create project's components and be able to use them as parameters.
(Exempli gratia: archive only header files or some specific library).
Thanks in advance for your answers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
tar 示例的字面翻译是:
这会添加一个新的目标“tar”,每当将其作为命令行目标请求时,它总是执行给定的命令,即每当您运行
make tar
时,它都会创建一个新的 tar 文件。 WORKING_DIRECTORY 参数将确保从源目录中获取源文件,而 CMAKE_CURRENT_BINARY_DIR 确保输出位于当前构建目录中。稍微好一点的迭代是将
tar
替换为${CMAKE_COMMAND} -E tar
,因为这不依赖于命令行tar
程序可用。因此,当您运行make tar
时,这样的操作会压缩所有头文件:更好的迭代是使用 CPack 功能来创建源文件或二进制 tar 文件,但这需要更多工作无论如何,可能不是您所需要的。
The literal translation of your tar example would be:
This adds a new target "tar" that always executes the given command whenever it is requested as a command line target, i.e. whenever you run
make tar
it will create a new tar file. TheWORKING_DIRECTORY
argument will ensure that the source files are taken from the source directory, while CMAKE_CURRENT_BINARY_DIR ensures the output goes in the current build directory.A slightly better iteration would be to replace
tar
with${CMAKE_COMMAND} -E tar
, as this doesn't depend on the command linetar
program being available. So something like this would tar up all the header files when you runmake tar
:An even better iteration would be to use the CPack features to create source or binary tar files, but that's quite a bit more work and may not be what you need anyway.