build: process the libxml2 library path for embedding
authorSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 28 Feb 2020 03:23:57 +0000 (19:23 -0800)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Fri, 28 Feb 2020 06:00:30 +0000 (22:00 -0800)
Process the path for libxml2 before embedding that into the command line
that is generated in `llvm-config`.  Each element in the path is being
given a `-l` unconditionally which should not be the case for absolute
paths.  Since the library path may be absolute or not, just apply some
CMake pre-processing when generating the path.

Before:
```
/usr/lib/x86_64-linux-gnu/libz.so -lrt -ldl -ltinfo -lpthread -lm /usr/lib/x86_64-linux-gnu/libxml2.so
```

After:
```
/usr/lib/x86_64-linux-gnu/libz.so -lrt -ldl -ltinfo -lpthread -lm -lxml2
```

Resolves PR44179!

llvm/lib/WindowsManifest/CMakeLists.txt

index fe6ddcd..8cfea12 100644 (file)
@@ -7,6 +7,15 @@ add_llvm_component_library(LLVMWindowsManifest
 
 if(LIBXML2_LIBRARIES)
   target_link_libraries(LLVMWindowsManifest PUBLIC ${LIBXML2_LIBRARIES})
+
+  get_filename_component(xml2_library ${LIBXML2_LIBRARIES} NAME)
+  if(xml2_library MATCHES "^${CMAKE_STATIC_LIBRARY_PREFIX}.*${CMAKE_STATIC_LIBRARY_SUFFIX}$")
+    string(REGEX REPLACE "^${CMAKE_STATIC_LIBRARY_PREFIX}" "" xml2_library ${xml2_library})
+    string(REGEX REPLACE "${CMAKE_STATIC_LIBRARY_SUFFIX}$" "" xml2_library ${xml2_library})
+  elseif(xml2_library MATCHES "^${CMAKE_SHARED_LIBRARY_PREFIX}.*${CMAKE_SHARED_LIBRARY_SUFFIX}$")
+    string(REGEX REPLACE "^${CMAKE_SHARED_LIBRARY_PREFIX}" "" xml2_library ${xml2_library})
+    string(REGEX REPLACE "${CMAKE_SHARED_LIBRARY_SUFFIX}$" "" xml2_library ${xml2_library})
+  endif()
   set_property(TARGET LLVMWindowsManifest PROPERTY
-    LLVM_SYSTEM_LIBS ${LIBXML2_LIBRARIES})
+    LLVM_SYSTEM_LIBS ${xml2_library})
 endif()