cmake : 从脚本设置环境变量 [英] cmake : Set environment variables from a script

查看:114
本文介绍了cmake : 从脚本设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本可以设置交叉编译所需的所有变量.这只是其中的一部分:

I have a script that sets all variables needed for the cross-compilation. Here is just part of it :

export CONFIG_SITE=~/workspace/eldk-5.4/powerpc/site-config-powerpc-linux
export CC="powerpc-linux-gcc  -m32 -mhard-float --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export CXX="powerpc-linux-g++  -m32 -mhard-float --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export CPP="powerpc-linux-gcc -E  -m32 -mhard-float --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export AS="powerpc-linux-as "
export LD="powerpc-linux-ld  --sysroot=~/workspace/eldk-5.4/powerpc/sysroots/powerpc-linux"
export GDB=powerpc-linux-gdb

如果我做source environment-setup-powerpc-linux,所有的环境变量都被导入到当前的shell session,我可以编译我的例子了.

If I do source environment-setup-powerpc-linux, all environment variables are imported into the current shell session, and I can compile my example.

是否可以在 cmake 中导入这些变量?如果是,怎么做?

Is it possible to import these variables in cmake? If yes, how?

更多细节:

  1. 我正在使用 ELDK v 5.4,它的安装脚本会生成一个脚本,该脚本设置所有环境变量
  2. 我找到了本教程,里面解释了如何手动设置交叉编译,但没有如何使用设置一切的脚本
  3. 如果我在设置 cmake 之前调用脚本,一切正常,我可以交叉编译,但我希望 cmake 调用脚本
  1. I am using ELDK v 5.4, and it's install script generates a script which sets all environment variables
  2. I found this tutorial, which explains how to manually set for cross-compilation, but not how to use the script, which sets everything
  3. if I call the script before setting cmake, all works fine, and I can cross-compile, but I'd like that cmake calls the script

推荐答案

通读cmake quick start,可以在命令行指定变量:

Reading through the cmake quick start, you can specify variable on a command line:

cmake -DVARIABLE1=value1 -DVARIABLE2=value2 ...

否则,cmake 脚本中的 set 命令可能就是你想要的,见 参考手册.要设置环境变量 PATH,请执行以下操作:

Otherwise, set command in the cmake script is probably what you want, see the reference manual. To set the environment variable PATH, do:

set(ENV{PATH} "/home/martink")

要设置普通变量,请执行以下操作:

To set normal variable, do:

set(variable "value")

不确定你必须设置哪些,可能是环境的.

Not sure which ones you have to set, probably the environment ones.

也就是说,在调用 cmake 之前设置环境变量 通常是解决问题的最简单的解决方案,例如:https://stackoverflow.com/a/15053460/684229

That said, setting environment variable prior to calling cmake is often the easiest solution to solve the problem, as in this case: https://stackoverflow.com/a/15053460/684229

这篇关于cmake : 从脚本设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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