Adding a library to CMake deps

Hi folks,

When cross-compiling LLVM to ARM, using CMake+Ninja, I realized that libxml2 depends on lzma, but the dependency is not explicit on the build.ninja file under the “build bin/c-index-test”'s LINK_LIBRARIES (which is the only one that cares about it).

I couldn’t find the place to add -llzma into the deps, and the only mention of libxml2 is in config-ix.cmake:

find_package(LibXml2)
if (LIBXML2_FOUND)
set(CLANG_HAVE_LIBXML 1)
endif ()

Which I could do the same with lzma? Any ideas on what the problem is, and possibly how to fix it?

thanks,
–renato

PS: The work around is to edit the build.ninja file manually after CMake runs, but that’s sub-optimal.

libxml2 comes with a ‘xml2-config’ shell script to get the right compilation / linking flags for the platform libxml2 was built on. Is 'the required depencies ? Cheers, – Arnaud A. de Grandmaison

Oh, but that's cross-compilation, so either my host xml2-config will report
the wrong deps (for the host machine), or the target xml2-config won't run
on the host machine at all...

I believe this has something to do with the change in ld (since 2.21) to
require explicit deps on compilation command line...

cheers,
--renato

Renato Golin <renato.golin@linaro.org> writes:

When cross-compiling LLVM to ARM, using CMake+Ninja, I realized that
libxml2 depends on lzma, but the dependency is not explicit on the
build.ninja file under the "build bin/c-index-test"'s LINK_LIBRARIES (which
is the only one that cares about it).

I couldn't find the place to add -llzma into the deps, and the only mention
of libxml2 is in config-ix.cmake:

find_package(LibXml2)
if (LIBXML2_FOUND)
  set(CLANG_HAVE_LIBXML 1)
endif ()

Which I could do the same with lzma? Any ideas on what the problem is, and
possibly how to fix it?

A quick and dirty fix is to change this on
clang/tools/c-index-test/CMakeLists.txt:

  target_link_libraries(c-index-test ${LIBXML2_LIBRARIES} lzma)

That affects that instance only (maybe it is the only one.) And if you
pretend to install that change, first check that XML2 always requires
lzma (to not break the build on systems where it doesn't and libzma is
absent.)

A more robust fix shall work on llvm/cmake/config-ix.cmake: when XML2 is
detected, add lzma as a dependency. This has the some caveat mentioned
on the previous paragraph.

Finally, the real fix shall be implemented on FindLibXml2.cmake, which
belongs to the CMake project. It should take care of declaring that xml2
libraries depend on lzma, but apparently it doesn't.

PS: The work around is to edit the build.ninja file manually after CMake
runs, but that's sub-optimal.

Not sub-optimal, but `gross' :slight_smile:

Thanks Oscar! Plenty of options to choose from. :wink:

I’m writing a document that explains in details how to cross-compile with LLVM/Clang, adding the use case compiling x86->ARM LLVM/Clang, and I’ll add the first dirty solution as a work around (so that people can cross-compile without touching the ninja files), but I’ll pursue the proper libxml2 fix (http://llvm.org/PR17085).

I’ll send the document in a moment for review.

cheers,