Overriding a default option(...) value in CMake from a parent CMakeLists.txt(从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值)
问题描述
我试图在我的源代码树中包含几个第三方库,并对其构建系统进行最少的更改,以便于升级.他们和我一样都使用 CMake,所以在我自己的 CMakeLists.txt 中,我可以将 add_subdirectory(extern/foo)
用于 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.
但是 foo CMakeLists.txt 编译测试工具、构建文档、我不需要的共享库,等等.libfoo 作者有先见之明通过选项控制这些 - option(FOO_BUILD_SHARED "Build libfoo shared library" 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.
我试过在 add_subdirectory(extern/foo)
之前做 set(FOO_BUILD_SHARED OFF)
.这具有在第二次和后续构建尝试期间不尝试构建共享库的效果,但在第一次尝试构建共享库时不会尝试,这是我真正需要加速的一次.
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 中的默认选项(...)值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值
基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01