Search code examples
buildmakefilecmakemetis

Can't add external project using ExternalProject_Add in CMake


The problem I have is very strange: I try to add an external project (the metis library) to my CMake project:

set(METIS_VERSION "5.1.0")

set(METIS_ARCHIVE "${PROJECT_SOURCE_DIR}/third-party/metis-${METIS_VERSION}.tar.gz")
if(NOT EXISTS ${METIS_ARCHIVE})
  set(METIS_ARCHIVE "http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/metis-${METIS_VERSION}.tar.gz")
endif()

set(METIS_DIR ${PROJECT_BINARY_DIR}/third-party/metis)
set(METIS_ROOT ${METIS_DIR}/src/Metis)

ExternalProject_Add(Metis
  PREFIX ${METIS_DIR}
  DOWNLOAD_DIR "${PROJECT_SOURCE_DIR}/third-party"
  URL ${METIS_ARCHIVE}
  URL_HASH "MD5=5465e67079419a69e0116de24fce58fe"
  PATCH_COMMAND patch ${METIS_ROOT}/CMakeLists.txt < ${PROJECT_SOURCE_DIR}/cmake/Metis-CMakeLists.txt.patch
  SOURCE_DIR ${METIS_ROOT}
  CONFIGURE_COMMAND $(MAKE) config shared=1 prefix=${METIS_ROOT} cc=${CMAKE_C_COMPILER}
  BINARY_DIR ${METIS_ROOT}
  BUILD_COMMAND $(MAKE)
)

The configure goes fine, but when I try to make, I get the following error message:

[100%] Built target metis
make[5]: *** No rule to make target `s'.  Stop.
make[4]: *** [all] Error 2
make[3]: *** [third-party/metis/src/Metis-stamp/Metis-build] Error 2
make[2]: *** [CMakeFiles/Metis.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2

Now the interesting part, if I invoke make in verbose mode (VERBOSE=1 make), the code runs fine and I have no errors. Also, I checked running make -C build/Darwin-x86_64/third-party/metis/src/Metis/ and this also works fine Does someone know what's the issue here?

aa


Solution

  • I checked running make -C build/Darwin-x86_64/third-party/metis/src/Metis/ and this also works fine

    99,9% blame environment (:

    You can test it by using printenv command:

    BUILD_COMMAND printenv && make
    

    copy the result of printenv and compare it with the "clean" one. You must see some diffs, for me it's:

    • MFLAGS
    • MAKEFLAGS
    • MAKELEVEL

    I don't know what is the reason of the issue exactly but when I unset this variables everything works fine (note that you need to update the install command too):

    BUILD_COMMAND unset MFLAGS && unset MAKEFLAGS && unset MAKELEVEL && make
    INSTALL_COMMAND unset MFLAGS && unset MAKEFLAGS && unset MAKELEVEL && make install