如何修改传递给自定义CMake目标的环境变量? [英] How to modify environment variables passed to custom CMake target?
本文介绍了如何修改传递给自定义CMake目标的环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也许我缺少一些明显的东西,但是我似乎无法弄清楚如何明确设置可以通过 add_custom_target()
。
Perhaps I am missing something obvious, but I can't seem to figure out how to explicitly set environment variables that can be seen by processes launched through add_custom_target()
.
以下:
set(ENV{PATH} "C:/Some/Path;$ENV{PATH}")
add_custom_target(newtarget somecommand)
不幸的是,%PATH%
环境变量显示为 somecommand
。 (我设置了一个Gist,重现问题这里)。
Unfortunately, the %PATH%
environment variable appears unchanged to somecommand
. (I have set up a Gist that reproduces the problem here.)
我做错了什么?
推荐答案
为自定义目标设置环境变量的便捷方式是使用CMake的命令行工具模式命令 env
:
A portable way of setting environment variables for a custom target is to use CMake's command-line tool mode command env
:
env [--unset=NAME]... [NAME=VALUE]... COMMAND [ARG]...
Run command in a modified environment.
例如:
add_custom_target(newtarget ${CMAKE_COMMAND} -E env NAME=VALUE somecommand)
另外请参阅命令行工具模式。
这篇关于如何修改传递给自定义CMake目标的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文