[CMake] Imported ExternalProject Libraries with Ninja

Zac Bergquist zbergquist99 at gmail.com
Fri Nov 20 13:02:29 EST 2015


Hello,

I'm using ExternalProject to build libxml2 into a static library, which I
link my application to.  I've read a few warnings about combining
ExternalProject with standard CMake targets, but I'm pretty sure this is
the approach I want to take.  I do not want to install libxml2 globally
because I'm configuring it with a very specific set of options.

I have something like this:

# build libxml2
ExternalProject_Add(libxml2
   BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/libxml2-2.9.1
   CONFIGURE_COMMAND ${XML_SRC}/configure ${CONFIGURE_FLAGS}
   ...
)

# tell CMake that the ExternalProject generated a library
add_library(xml2 STATIC IMPORTED GLOBAL)
set_property(TARGET xml2 PROPERTY
    IMPORTED_LOCATION
${CMAKE_CURRENT_BINARY_DIR}/libxml2-2.9.1/.libs/libxml2.a
)

add_executable(foo ${SOURCES})

add_dependency(foo libxml2)

target_link_libraries(foo xml2)


I realize that this isn't as portable as it could [should] be because I'm
including information about where the build files will be generated, but
I'm okay with this.

With the standard Unix makefile generator, everything works fine.  I can
run `make foo` and it configures and builds libxml2, then builds foo and
links to the static library.

However, with the ninja generator, I get an error:

ninja: error: "libxml2-2.9.1/.libs/libxml2.a', needed by 'out/bin/foo',
missing and no known rule to make it


For some reason the Ninja build is not picking up on the fact that
libxml2.a is generated by the external project.  The only way I'm able to
get this to build is to run `ninja xml2` followed by `ninja foo`.

Am I doing something wrong or could this be a bug in CMake?  If so, are
there any workarounds.  I just started using Ninja and am really enjoying
the speed advantage over make.

Thanks,
Zac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151120/6d0902eb/attachment.html>


More information about the CMake mailing list