You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CMake 3.1的-E env选项在2.8版本中的兼容替代方案咨询

CMake 2.8 替代 -E env 的兼容方案

Hey there! Since CMake 2.8 doesn't include the -E env option that was introduced in CMake 3.1, you'll need a system-native workaround to replicate that functionality. For your specific ubus Python patch code, here's how to adjust it:

核心思路

CMake 3.1's -E env essentially wraps the system's native environment variable setter tool. On Unix-like systems (which Turris OS uses), you can directly use the env command to achieve the exact same result—it will pass the specified environment variables to the Python setup script just like -E env does.

修改后的代码示例

1. 调整 ADD_CUSTOM_TARGET 中的命令

原来的代码:

ADD_CUSTOM_TARGET(python ALL 
 COMMAND ${CMAKE_COMMAND} -E env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" "LDSHARED=${LDSHARED}" "CFLAGS=${PYTHON_CFLAGS}" ${PYTHON} ${SETUP_PY} build 
 DEPENDS ubus "${CURRENT_SOURCE_DIR}/ubus_python.c" 
)

修改后:

ADD_CUSTOM_TARGET(python ALL 
 COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" "LDSHARED=${LDSHARED}" "CFLAGS=${PYTHON_CFLAGS}" ${PYTHON} ${SETUP_PY} build 
 DEPENDS ubus "${CURRENT_SOURCE_DIR}/ubus_python.c" 
)

2. 调整 INSTALL 中的 execute_process 命令

原来的代码:

INSTALL( 
 CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E env \"CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}\" \"LDSHARED=${LDSHARED}\" \"CFLAGS=${PYTHON_CFLAGS}\" ${PYTHON} ${SETUP_PY} install --prefix=${CMAKE_INSTALL_PREFIX})" 
)

修改后:

INSTALL( 
 CODE "execute_process(COMMAND env \"CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}\" \"LDSHARED=${LDSHARED}\" \"CFLAGS=${PYTHON_CFLAGS}\" ${PYTHON} ${SETUP_PY} install --prefix=${CMAKE_INSTALL_PREFIX})" 
)

方案可行性说明

The env command is a standard Unix utility that runs a target command with a modified environment—this is exactly what CMake 3.1's -E env does under the hood. Since Turris OS is Linux-based, this workaround will work seamlessly without any extra dependencies.

(Note: If you were targeting Windows, you'd need to use the set command in batch-style syntax, but that's not relevant for your Turris OS use case.)

内容的提问来源于stack exchange,提问作者zer0_0ne

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:59:09