1

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

Subbu
  • 839
  • 2
  • 12
  • 34
  • 1
    Description "that has not worked" is not useful. What **exactly** is wrong with that approach? Do you have an error or something else? Please, be **specific** when describe the problem. You approach should set variable for *configuration* stage (but not for other stages: *build*, *test*, etc.). But it is better to remove the second `${CMAKE_COMMAND} -E env`: you may specify several environment variables inside a single `cmake -E env` wrapper. – Tsyvarev Jul 23 '20 at 17:42
  • BTW, here an example: https://stackoverflow.com/questions/55708589/how-to-pass-an-environment-variable-to-externalproject-add-configure-command. – Tsyvarev Jul 23 '20 at 17:45
  • @Tsyvarev - I am building the Qt library using the ExternalProject_Add feature. I am calling the "configure" script through the cmake configure command to prepare Qt for a build later. However this configure requires that I set the ANDROID_SDK_ROOT and ANDROID_API_VERSION environment variables for it to be successful. I will try your example. Thanks for your reply!!! – Subbu Jul 23 '20 at 18:01

1 Answers1

0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
j-mo
  • 142
  • 5