This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Consistently use the LibXml2::LibXml2 target instead of LIBXML2_LIBRARIES
ClosedPublic

Authored by zero9178 on Sep 17 2021, 9:07 AM.

Details

Summary

Linking against the LibXml2::LibXml2 target has the advantage of not only importing the library, but also adding the include path as well as any definitions the library requires. In case of a static build of libxml2, eg. a define is set on Windows to remove any DLL imports and export.

LLVM already makes use of the target, but c-index-test and lldb were still linking against the library only.

The workaround for Mac OS-X that I removed seems to have also been made redundant since https://reviews.llvm.org/D84563 I believe

Diff Detail

Event Timeline

zero9178 created this revision.Sep 17 2021, 9:07 AM
zero9178 requested review of this revision.Sep 17 2021, 9:07 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 17 2021, 9:07 AM

Serendipitously, I just yesterday upgraded from OSX 10.14 to 10.15, and have been unable to build clang because, even with a totally-empty-and-brand-new build directory, CMake says:

CMake Error in lib/WindowsManifest/CMakeLists.txt:
  Imported target "LibXml2::LibXml2" includes non-existent path
    "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/libxml2"
  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:
  * The path was deleted, renamed, or moved to another location.
  * An install or uninstall procedure did not complete successfully.
  * The installation package was faulty and references files it does not
  provide.
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

Do you think this PR would fix that issue on OSX 10.15?
(IMHO it's also weird that OSX would even be trying to build anything with Windows in the name.)

Serendipitously, I just yesterday upgraded from OSX 10.14 to 10.15, and have been unable to build clang because, even with a totally-empty-and-brand-new build directory, CMake says:

CMake Error in lib/WindowsManifest/CMakeLists.txt:
  Imported target "LibXml2::LibXml2" includes non-existent path
    "/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/libxml2"
  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:
  * The path was deleted, renamed, or moved to another location.
  * An install or uninstall procedure did not complete successfully.
  * The installation package was faulty and references files it does not
  provide.
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

Do you think this PR would fix that issue on OSX 10.15?
(IMHO it's also weird that OSX would even be trying to build anything with Windows in the name.)

Since there is nothing platform specific in the code of WindowsManifest it'd make sense to build it on any OS; At the very least for cross compile setups.

I sadly am not very accustomed to Macs so I don't know the details, but I don't think this patch would change anything about your situation.

Could it maybe be related to the CMAKE_OSX_SYSROOT variable somehow? CMake seems to use it to lookup packages from the platform SDK.

I was inspired to dig down and find the LLVM_ENABLE_LIBXML2 option (which is on by default) and turn it off, so now I can build clang with the following commands:

cmake -G Ninja -DLLVM_ENABLE_LIBXML2=0 -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" -DCMAKE_BUILD_TYPE=Release ../llvm
ninja clang

I suspect that my /usr/lib/libxml2.2.dylib is simply outdated/has been borked by my OS upgrade; unfortunately I still haven't figured out how to install a newer version of it.
Anyway, never mind me, then. :)

MaskRay accepted this revision.Sep 23 2021, 4:23 PM

Looks great!

This revision is now accepted and ready to land.Sep 23 2021, 4:23 PM