Ped*_*nte 11 linux cmake environment-variables
根据CMake文档
https://cmake.org/cmake/help/v3.3/command/set.html
一个人可以做
set(ENV{<variable>} <value>)
但这给出了结果
set(ENV{FOO} foo)
message("variable is $ENV{FOO}")
在配置时
variable is foo
但是在Linux命令中
echo $FOO
该变量未设置。
编辑:
这是问题的部分解决方案,即设置$PATH,以便用户CMAKE_INSTALL_PREFIX首先列出
set(file_sh ${CMAKE_CURRENT_BINARY_DIR}/path.sh)
set(path "${CMAKE_INSTALL_PREFIX}:$ENV{PATH}")
file(WRITE ${file_sh} "#!/usr/bin/env bash\n")
file(APPEND ${file_sh} "export PATH=\"${path}\"")
execute_process(COMMAND chmod a+x ${file_sh} RESULT_VARIABLE res)
这会创建这个文件
#!/usr/bin/env bash
export PATH="/install/prefix/path:/other/path"
稍后可以在 bash 终端上执行
source path.sh
vre*_*vre -3
您引用的文档的最后一段给出了答案:
Set the current process environment <variable> to the given value.
它影响从 shell 启动 CMake 时创建的当前进程环境。它不是 shell 本身的环境。