cmake - CMake将字符串解释为变量

标签 cmake

我正在寻找一种在cmake中将字符串解释为变量名的方法。

鉴于:

set(MY_SECRET_VAR "foo")

# later only the name of the variable is known.
set(THE_NAME "MY_SECRET_VAR")

# Now i'm looking for a way to get the value "foo" from the name
# something like:
set(THE_VALUE "${THE_NAME}")

# THE_VALUE should be "foo"

最佳答案

第二层展开:

set(THE_VALUE "${${THE_NAME}}")

关于cmake - CMake将字符串解释为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32631168/

相关文章:

c++ - CMAKE错误: "Cannot open source file" : 'CMakeCCompilerId.c'

android - 如何创建 *.so 文件以动态链接 OpenCV for Android?

c++ - CMAKE 3.4.1和VS2015编译opencv3.0 extra models时找不到include文件如何解决

c++ - 在CMake文件中添加头文件文件夹路径

c++ - 使用 CMake 仅构建一次外部库

c - 如何让 clion 使用以下 make 和 pkg-config?

c++ - 为什么这个 boost 示例在 OS X 上没有链接?

c++ - 在VS2019 C++跨平台程序中包含nuget包

c++ - 将 Makefile 转换为 Tiva C 系列的 CMakeLists.txt

c++ - 使用 CMake C++17 项目设置 Travis CI