Hi Zac,

In recent versions of CMake (not sure when it was introduced, but it's 
available in 3.2.X) you have an extra argument for ExternalProject_Add: 
BUILD_BYPRODUCTS.

https://cmake.org/cmake/help/v3.2/module/ExternalProject.html

I use this in a setup very similar to yours to declare all the shared libraries 
that my external project target will make. This way Ninja knows where to expect 
those files from.

Cheers,
             Attila

> On 20 Nov 2015, at 19:02, Zac Bergquist <[email protected]> wrote:
> 
> 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

-- 

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