如何修改传递给自定义 CMake 目标的环境变量? [英] How to modify environment variables passed to custom CMake target?

查看:31
本文介绍了如何修改传递给自定义 CMake 目标的环境变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我遗漏了一些明显的东西,但我似乎无法弄清楚如何显式设置通过 add_custom_target().

我尝试了以下方法:

set(ENV{PATH} "C:/Some/Path;$ENV{PATH}")add_custom_target(newtarget somecommand)

不幸的是,%PATH% 环境变量似乎对 somecommand 没有改变.(我已经设置了一个 Gist 来重现问题这里.)

我做错了什么?

解决方案

为自定义目标设置环境变量的一种可移植方式是使用 CMake 的命令行工具模式命令 env:

<块引用>

env [--unset=NAME]... [NAME=VALUE]... 命令 [ARG]...

在修改后的环境中运行命令.

例如:

add_custom_target(newtarget ${CMAKE_COMMAND} -E env NAME=VALUE somecommand)

另见命令行工具模式.

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().

I tried the following:

set(ENV{PATH} "C:/Some/Path;$ENV{PATH}")
add_custom_target(newtarget somecommand)

Unfortunately, the %PATH% environment variable appears unchanged to somecommand. (I have set up a Gist that reproduces the problem here.)

What am I doing wrong?

解决方案

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.

E.g.:

add_custom_target(newtarget ${CMAKE_COMMAND} -E env NAME=VALUE somecommand)

Also see Command Line Tool Mode.

这篇关于如何修改传递给自定义 CMake 目标的环境变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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