Setting environment variables to ExternalProject_Add context

1.1k views Asked by At

I have a CMakeLists.txt file in which there are multiple external projects I need to build. I am using the ExternalProject_Add feature of CMake.

I need to set an environment variable in one of the ExternalProject_Add project modules. The project needs it to perform a build.

I have tried using the ${CMAKE_COMMAND} -E env option and that has not worked:

CONFIGURE_COMMAND
    ${CMAKE_COMMAND} -E env ANDROID_SDK_ROOT="/home/subbu/Android/Sdk"
    ${CMAKE_COMMAND} -E env ANDROID_API_VERSION="android-22"
    <SOURCE_DIR>/configure
    -prefix <INSTALL_DIR>
    -debug

I am not able to find examples on the web.

Please advise.

Thanks for your help in advance.

Subbu

1

There are 1 answers

0
j-mo On

i was doing a similar thing for msgpack, and i was able to get it to work by doing the following:

set (MsgpackBundle msgpack-1.4.1.tar.gz)
ExternalProject_Add(MsgpackBuilder
    URL ${CMAKE_CURRENT_SOURCE_DIR}/${MsgpackBundle}
    URL_MD5 ${MsgpackBundleMd5}
    CONFIGURE_COMMAND
    ${CMAKE_COMMAND} -E CFLAGS=${MsgpackCflags}
    ${CMAKE_COMMAND} -E env CXXFLAGS=${MsgpackCflags}
    ${CMAKE_COMMAND} -E env LDFLAGS=${MsgpackLdflags}
    ./configure
         --prefix=${DependenciesInstallDir}
         --host=${MsgpackHost}
         --disable-shared
    BUILD_IN_SOURCE true
    BUILD_COMMAND
    make V=1
    INSTALL_COMMAND
    make install)

MsgpackCflags, MsgpackLdflags are pre-computed, depending on the target system. MsgpackHost is used by the cross-compile toolchain (x86_64-linux-gnu for a host build), ${DependenciesInstallDir} is also a pre-computed path that varies for different os/architecture/build-configuration (debug, release) tuple. the MsgpackbundleMd5 is the result of md5sum msgpack-1.4.1.tar.gz.