如何将环境变量传递给ExternalProject_Add CONFIGURE_COMMAND? [英] How to pass an environment variable to ExternalProject_Add CONFIGURE_COMMAND?
问题描述
我有一个带有autotools项目的第三方库.我想使用ExternalProject_Add来构建库.
I have a third party library with autotools project. I want to use ExternalProject_Add to build the library.
这可以通过以下方式完成:
This can be done the following way:
ExternalProject_Add(project_lib
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/configure --prefix=${LIB_OUTPUT}
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build
)
现在的问题是我需要将环境变量传递给 configure
,但是我找不到解决方法.
Now the problem is that I need to pass an environment variable to configure
but I cannot find a way to do it.
在控制台中,我将通过以下方式进行操作:
In the console I would do it the following way:
CPPFLAGS =-fPIC" ./configure --prefix = output
是否可以通过 ExternalProject_Add/CONFIGURE_COMMAND
将 CPPFLAGS =-fPIC"
env传递到 configure
?
Is there a way to pass CPPFLAGS="-fPIC"
env to the configure
with ExternalProject_Add/CONFIGURE_COMMAND
?
推荐答案
可以通过cmake( cmake --help
)执行 configure
命令来完成.="https://gitlab.kitware.com/cmake/cmake/commit/7abd574798f9900abfe502f3941cffaa774062b1" rel ="noreferrer">命令模式:
It can be done by executing configure
command through cmake (cmake --help
) command mode:
-E = CMake command mode.
因此,我们可以直接通过带有环境变量的cmake命令模式来执行它,而不是直接调用 configure
:
So instead of calling configure
directly we can execute it through cmake command mode with the environment variables:
ExternalProject_Add(project_lib
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib
CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env CPPFLAGS=-fPIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/configure --prefix=${LIB_OUTPUT}
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build
)
[cmake-developers]使用ExternalProject_Add <设置环境/a>
这篇关于如何将环境变量传递给ExternalProject_Add CONFIGURE_COMMAND?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!