CPack:从子目录(googletest目录)中排除INSTALL命令 [英] CPack: Exclude INSTALL commands from subdirectory (googletest directory)

查看:119
本文介绍了CPack:从子目录(googletest目录)中排除INSTALL命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将CMake用于一个项目,并将googletest用于我的测试用例。
环顾互联网,将googletest源代码复制到存储库的子文件夹中并将其包含在 add_subdirectory(googletest)中似乎是一种常见的做法。我做到了。

I'm using CMake for a project and googletest for my test cases. Looking around the internet, it seems to be common practise to just copy the googletest source into a subfolder of your repository and include it with "add_subdirectory(googletest)". I did that.

现在我正在使用CPack为我的项目生成debian软件包。不幸的是,由CPack生成的软件包与我的项目一起安装了googletest。当然,这不是我想要的。

Now I'm using CPack to generate debian packages for my project. Unfortunately, the packages generated by CPack install googletest alongside with my project. This is of course not what I want.

在googletest目录中,我发现了一些INSTALL cmake命令,因此很清楚为什么会发生。现在的问题是-我该如何避免呢?我不喜欢从googletest修改CMakeLists.txt文件,因为我必须记住在更新时重新应用所做的修改。还有其他方法可以在CPack中禁用这些安装吗?

Looking in the googletest directory, I found some INSTALL cmake commands there, so it is clear, why it happens. The question is now - how can I avoid it? I don't like modifying the CMakeLists.txt files from googletest, because I would have to remember re-applying my modifications on an update. Is there another way to disable these installs in CPack?

推荐答案

如果您不需要在项目的发行版中进行测试(要与CPack一起交付),然后有条件地包含 googletest 子目录,并在打包时将条件设置为false:

If you don't need tests in your project's release (which you want to deliver with CPack), then include googletest subdirectory conditionally, and set conditional to false when packaging:

...
if(NOT DISABLE_TESTS)
    add_subdirectory(googletest)
endif()

包装

cmake -DDISABLE_TESTS=ON <source-dir>
cpack

或者,如果您要测试,但不想安装测试基础结构,您可以通过定义具有相同名称的宏或函数来禁用 install 命令:

Alternatively, if you want tests, but don't want to install testing infrastructure, you may disable install command via defining macro or function with same name:

# Replace install() to do-nothing macro.
macro(install)
endmacro()
# Include subproject (or any other CMake code) with "disabled" install().
add_subdirectory(googletest)
# Restore original install() behavior.
macro(install)
    _install(${ARGN})
endmacro()

CMake邮件。

这篇关于CPack:从子目录(googletest目录)中排除INSTALL命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆