1

Got stuck when I'm trying ExternalProject_Add for gflags. Appreciate for anyone's help.

The snippet for CMakeLists.txt as follows.

ExternalProject_Add(gflags
  PREFIX                ${CMAKE_CURRENT_BINARY_DIR}/gflags-prefix
  SOURCE_DIR            ${CMAKE_CURRENT_SOURCE_DIR}/gflags
  CONFIGURE_COMMAND     cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/gflags -DBUILD_SHARED_LIBS=ON ${CMAKE_CURRENT_SOURCE_DIR}
  BUILD_COMMAND         $(MAKE)
  BUILD_IN_SOURCE       0
  INSTALL_COMMAND       $(MAKE) install)

It turns out -- Build files have been written to: $CMAKE_BINARY_PATH/gflags-prefix/src/gflags-build/gflags-prefix/src/gflags-build/gflags-prefix/src/gflags-build many times, when cmake ../ && make -j16.

Output sample:

Scanning dependencies of target gflags
[ 12%] Creating directories for 'gflags'
[ 25%] No download step for 'gflags'
[ 37%] No patch step for 'gflags'
[ 50%] No update step for 'gflags'
[ 62%] Performing configure step for 'gflags'
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done

-- Build files have been written to: /foopath/build/gflags-prefix/src/gflags-build
[ 75%] Performing build step for 'gflags'
Scanning dependencies of target gflags
[ 12%] Creating directories for 'gflags'
[ 25%] No download step for 'gflags'
[ 50%] No patch step for 'gflags'
[ 50%] No update step for 'gflags'
[ 62%] Performing configure step for 'gflags'
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build files have been written to: /foopath/build/gflags-prefix/src/gflags-build/gflags-prefix/src/gflags-build
sazpw
  • 23
  • 5
  • are you able to supply a minimal but complete `CMakeLists.txt` file to demonstrate the problem? This will help us to reproduce it. – Richard Hodges Aug 20 '19 at 13:12
  • You pass `${CMAKE_CURRENT_SOURCE_DIR}` as a **source directory** for `cmake` in `CONFIGURE_COMMAND`. This variable refers to the **main project's source directory**. That is, while configure `gflags` external project, it actually configures the **main project**, but in a different build directory. Because main project contains given `ExternalProject` call, the process continues recursively. If inside `ExternalProject` you want to refer to the directory specified in `SOURCE_DIR` option, use `` expression instead. – Tsyvarev Aug 20 '19 at 14:00
  • @Tsyvarev Clear explanation! The wrong **cmake project's source dir** make it build recursively. Seems that just with `CMAKE_ARGS -DFoo=Bar` is enough, instead of `CONFIGURE_COMMAND` refers to specific dir in my case. It works fine, thanks. – sazpw Aug 21 '19 at 02:56

0 Answers0