Strange ExternalProject behaviour
Running Arch Linux, cmake --version
:
cmake version 3.15.2
Create a folder, and perform the following:
git init
git submodule add https://github.com/libffi/libffi.git
touch example.cpp
Then create a CMakeLists.txt
with the following contents:
cmake_minimum_required(VERSION 3.1)
include(ExternalProject)
ExternalProject_Add(ffi
SOURCE_DIR ${CMAKE_SOURCE_DIR}/libffi
UPDATE_COMMAND ""
CONFIGURE_COMMAND <SOURCE_DIR>/autogen.sh && <SOURCE_DIR>/configure --disable-shared --disable-builddir --prefix=<INSTALL_DIR>
BUILD_IN_SOURCE 1
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/libffi.a
LOG_BUILD TRUE
LOG_CONFIGURE TRUE
LOG_INSTALL TRUE
)
ExternalProject_Get_Property(ffi INSTALL_DIR)
set(LIBFFI_INSTALL_DIR ${INSTALL_DIR}/lib/libffi-3.2.1/)
ExternalProject_Get_Property(ffi SOURCE_DIR)
set(ffi_SOURCE_DIR ${SOURCE_DIR})
add_library(libffi STATIC IMPORTED GLOBAL)
file(MAKE_DIRECTORY ${LIBFFI_INSTALL_DIR}/include)
set_target_properties(libffi PROPERTIES
IMPORTED_LOCATION ${INSTALL_DIR}/lib/libffi.a
INTERFACE_INCLUDE_DIRECTORIES ${LIBFFI_INSTALL_DIR}/include
)
add_library(example SHARED example.cpp)
target_link_libraries(example libffi)
add_dependencies(example ffi)
Next, mkdir build
, enter it and run cmake ..
as well as cmake --build .
. Observe as the build fails with the following:
Scanning dependencies of target ffi
[ 10%] Creating directories for 'ffi'
[ 20%] No download step for 'ffi'
[ 30%] No patch step for 'ffi'
[ 40%] No update step for 'ffi'
[ 50%] Performing configure step for 'ffi'
-- ffi configure command succeeded. See also build/ffi-prefix/src/ffi-stamp/ffi-configure-*.log
[ 60%] Performing build step for 'ffi'
CMake Error at build/ffi-prefix/src/ffi-stamp/ffi-build-.cmake:49 (message):
Command failed: 2
'make'
See also
build/ffi-prefix/src/ffi-stamp/ffi-build-*.log
make[2]: *** [CMakeFiles/ffi.dir/build.make:112: ffi-prefix/src/ffi-stamp/ffi-build] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/ffi.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
This is ludicrous because of course there is a Makefile
present. Now, in the CMakeLists.txt, comment out the following lines:
LOG_BUILD TRUE
LOG_CONFIGURE TRUE
LOG_INSTALL TRUE
Then nuke the build folder with rm -rf * .*
and run cmake ..
as well as cmake --build .
. Now, observe as the build succeeds:
Scanning dependencies of target ffi
[ 10%] Creating directories for 'ffi'
[ 20%] No download step for 'ffi'
[ 30%] No patch step for 'ffi'
[ 40%] No update step for 'ffi'
[ 50%] Performing configure step for 'ffi'
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal -I m4
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy
autoreconf: running: /usr/bin/autoconf
autoreconf: running: /usr/bin/autoheader
autoreconf: running: automake --add-missing --copy --no-force
autoreconf: Leaving directory `.'
<snip>
[ 60%] Performing build step for 'ffi'
<snip>
[ 70%] Performing install step for 'ffi'
<snip>
[ 80%] Completed 'ffi'
[ 80%] Built target ffi
Scanning dependencies of target example
[ 90%] Building CXX object CMakeFiles/example.dir/example.cpp.o
[100%] Linking CXX shared library libexample.so
[100%] Built target example
I expect that the presence of LOG_
configuration would not change the behaviour of my build. Apologies for the lack of clarity beyond the example above, as I am at a loss for words as to how to properly describe this strange behaviour beyond illustration.