从父的CMakeLists.txt覆盖在CMake的默认选项(...)值 [英] Overriding a default option(...) value in CMake from a parent CMakeLists.txt

查看:653
本文介绍了从父的CMakeLists.txt覆盖在CMake的默认选项(...)值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括我的源代码树最小的改变他们的编译系统,便于升级的几个第三方库。它们都使用CMake的,因为这样做我,所以在我自己的CMakeLists.txt我可以使用 add_subdirectory(EXTERN /富)为libfoo的。

I am trying to include several third-party libraries in my source tree with minimal changes to their build system for ease of upgrading. They all use CMake, as do I, so in my own CMakeLists.txt I can use add_subdirectory(extern/foo) for libfoo.

但富的CMakeLists.txt编译一个测试工具,建立文档,共享库,我不需要,等等。该libfoo的作者有先见之明通过选项来控制这些 - 选项(FOO_BUILD_SHARED建设​​libfoo的共享库ON)例如 - 这意味着我可以通过CMake的命令行设置它们。不过,我想使该默认关闭和重写通过命令行。

But the foo CMakeLists.txt compiles a test harness, builds documentation, a shared library which I don't need, and so on. The libfoo authors had the foresight to control these via options - option(FOO_BUILD_SHARED "Build libfoo shared library" ON) for example - which means I can set them via the CMake command line. But I would like to make that off by default and overridable via the command line.

我曾尝试做设置(FOO_BUILD_SHARED OFF) add_subdirectory(EXTERN /富)。有,但不是在第一位的,这是一个我真的需要加快不是要建第二个及后续版本中尝试共享库的作用。

I have tried doing set(FOO_BUILD_SHARED OFF) before add_subdirectory(extern/foo). That has the effect of not trying to build the shared library during the second and subsequent build attempts, but not during the first one, which is the one I really need to speed up.

这是可能的,或者我需要保持分叉的CMakeLists.txt这些项目?

Is this possible, or do I need to maintain forked CMakeLists.txt for these projects?

推荐答案

尝试设置变量在CACHE

Try setting the variable in the CACHE

SET(FOO_BUILD_SHARED OFF CACHE BOOL "Build libfoo shared library")

请注意:你需要这样的CMake知道如何显示在GUI此项指​​定变量类型,并描述

Note: You need to specify the variable type and a description so CMake knows how to display this entry in the GUI.

这篇关于从父的CMakeLists.txt覆盖在CMake的默认选项(...)值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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