Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
950 views
in Technique[技术] by (71.8m points)

cmake - How to pass an environment variable to ExternalProject_Add CONFIGURE_COMMAND?

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
)

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

Is there a way to pass CPPFLAGS="-fPIC" env to the configure with ExternalProject_Add/CONFIGURE_COMMAND ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It can be done by executing configure command through cmake (cmake --help) command mode:

-E                           = CMake command mode.

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] Setting up environment using ExternalProject_Add


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...