CMake ExternalProject_Add Stop Executing on Warnin

2019-09-20 11:58发布

问题:

I am using a series of ExternalPorject_Add's to download, configure, build, and install QT5 statically using CMake. Everything goes well until the configure script. The Qt5 configure script issues the following warning when compiling statically, after which, the build and install steps are ignored:

CUSTOMBUILD : warning : Using static linking will disable the use of plugins.
           Make sure you compile ALL needed modules into the library.

My final ExternaProject_Add is as follows (there are other's to break the download step into a different target):

  ExternalProject_Add(qt5_build
    DOWNLOAD_COMMAND "" UPDATE_COMMAND "" PATCH_COMMAND ""
    SOURCE_DIR ${QT5_REPO_PATH}
    CONFIGURE_COMMAND configure ${QT5_CONFIGURE}
    BUILD_COMMAND nmake BUILD_IN_SOURCE 1
    INSTALL_COMMAND nmake install
  )

Are there any thoughts on how to get the project to ignore the warnings (is the warning even what is causing it to stop?) and continue with the build and install steps?

I am currently running on windows (working on a cross-platform installer), and using the visual studio 2013 generator with cmake.

Thanks!

回答1:

I had the same problem as you. It turns out it has nothing to do with the warnings or even the exit code (in this case).

It happens because the configure file is a batch file and Visual Studio is executing the configure build steps in another batch file.

This means that if you don't use the keyword call in front of configure, you will branch off to the configure.bat and never return and execute the remaining steps in the Visual Studio configure step.

To fix this you can do:

ExternalProject_Add(qt5_build
    DOWNLOAD_COMMAND "" UPDATE_COMMAND "" PATCH_COMMAND ""
    SOURCE_DIR ${QT5_REPO_PATH}
    CONFIGURE_COMMAND call configure.bat ${QT5_CONFIGURE}
    BUILD_COMMAND nmake BUILD_IN_SOURCE 1
    INSTALL_COMMAND nmake install)


回答2:

The configure script was returning a non-zero result causing the subsequent steps to fail, even though the warning really is non-fatal. I've stepped away from using ExternalProject and just implemented the same functionality using add_custom_target.