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
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to