且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

cmake:从脚本设置环境变量

更新时间:2022-10-20 19:17:18

阅读通过 cmake快速启动,您可以在命令上指定变量行:

  cmake -DVARIABLE1 = value1 -DVARIABLE2 = value2 ... 
/ pre>

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

  set(ENV {PATH}/ home / martink)

要设置正常变量,请执行以下操作:

  set(variablevalue)

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



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


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

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

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


A bit more details :

  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

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

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

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.

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