[libunwind] 1c4867e - [libunwind] Provide a way to conveniently install libunwind headers

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 16 10:33:53 PST 2021


Author: PoYao Chang
Date: 2021-12-16T13:32:40-05:00
New Revision: 1c4867e6fc507fe6e81cfc0e3c7148307b4b7433

URL: https://github.com/llvm/llvm-project/commit/1c4867e6fc507fe6e81cfc0e3c7148307b4b7433
DIFF: https://github.com/llvm/llvm-project/commit/1c4867e6fc507fe6e81cfc0e3c7148307b4b7433.diff

LOG: [libunwind] Provide a way to conveniently install libunwind headers

This adds a CMake option (defaults to OFF to not be intrusive) to activate
2 new targets `install-unwind-headers` and `install-unwind-headers-stripped`.
So, for example:

  cmake -S runtimes -B build -G Ninja \
    -DLLVM_ENABLE_RUNTIMES='libunwind' \
    -DLIBUNWIND_INSTALL_HEADERS=ON

And then, `ninja -C build install-unwind` would install headers in addition
to good ol' dylibs and archives, i.e., targets `install-unwind*` `DEPENDS`
on `install-unwind-headers*`. On the other hand,
`ninja -C build install-unwind-headers` gives you headers only.

Differential Revision: https://reviews.llvm.org/D115535

Added: 
    libunwind/include/CMakeLists.txt

Modified: 
    libunwind/CMakeLists.txt
    libunwind/src/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index a63dc453ffb6c..eb478e4e7730c 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -78,6 +78,7 @@ option(LIBUNWIND_INCLUDE_TESTS "Build the libunwind tests." ${LLVM_INCLUDE_TESTS
 option(LIBUNWIND_IS_BAREMETAL "Build libunwind for baremetal targets." OFF)
 option(LIBUNWIND_USE_FRAME_HEADER_CACHE "Cache frame headers for unwinding. Requires locking dl_iterate_phdr." OFF)
 option(LIBUNWIND_REMEMBER_HEAP_ALLOC "Use heap instead of the stack for .cfi_remember_state." OFF)
+option(LIBUNWIND_INSTALL_HEADERS "Install the libunwind headers." OFF)
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
     "Define suffix of library directory name (32/64)")
@@ -372,7 +373,7 @@ endif()
 # Setup Source Code
 #===============================================================================
 
-include_directories(include)
+add_subdirectory(include)
 
 add_subdirectory(src)
 

diff  --git a/libunwind/include/CMakeLists.txt b/libunwind/include/CMakeLists.txt
new file mode 100644
index 0000000000000..c3bb1dd0f69fa
--- /dev/null
+++ b/libunwind/include/CMakeLists.txt
@@ -0,0 +1,31 @@
+set(files
+    __libunwind_config.h
+    libunwind.h
+    mach-o/compact_unwind_encoding.h
+    unwind_arm_ehabi.h
+    unwind_itanium.h
+    unwind.h
+    )
+
+add_library(unwind-headers INTERFACE)
+target_include_directories(unwind-headers INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
+
+if(LIBUNWIND_INSTALL_HEADERS)
+  foreach(file ${files})
+    get_filename_component(dir ${file} DIRECTORY)
+    install(FILES ${file}
+      DESTINATION "include/${dir}"
+      COMPONENT unwind-headers
+      PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+    )
+  endforeach()
+
+  if(NOT CMAKE_CONFIGURATION_TYPES)
+    add_custom_target(install-unwind-headers
+      DEPENDS unwind-headers
+      COMMAND "${CMAKE_COMMAND}"
+              -DCMAKE_INSTALL_COMPONENT=unwind-headers
+              -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
+    add_custom_target(install-unwind-headers-stripped DEPENDS install-unwind-headers)
+  endif()
+endif()

diff  --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 41513ddfff1f5..710198550a061 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -133,7 +133,8 @@ if (LIBUNWIND_ENABLE_SHARED)
   else()
     target_compile_options(unwind_shared PRIVATE -fno-rtti)
   endif()
-  target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES})
+  target_link_libraries(unwind_shared PRIVATE ${LIBUNWIND_LIBRARIES}
+                                      PRIVATE unwind-headers)
   set_target_properties(unwind_shared
     PROPERTIES
       CXX_EXTENSIONS OFF
@@ -160,7 +161,8 @@ if (LIBUNWIND_ENABLE_STATIC)
   else()
     target_compile_options(unwind_static PRIVATE -fno-rtti)
   endif()
-  target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES})
+  target_link_libraries(unwind_static PRIVATE ${LIBUNWIND_LIBRARIES}
+                                      PRIVATE unwind-headers)
   set_target_properties(unwind_static
     PROPERTIES
       CXX_EXTENSIONS OFF
@@ -207,4 +209,8 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
             -DCMAKE_INSTALL_COMPONENT=unwind
             -DCMAKE_INSTALL_DO_STRIP=1
             -P "${LIBUNWIND_BINARY_DIR}/cmake_install.cmake")
+  if(LIBUNWIND_INSTALL_HEADERS)
+    add_dependencies(install-unwind install-unwind-headers)
+    add_dependencies(install-unwind-stripped install-unwind-headers-stripped)
+  endif()
 endif()


        


More information about the cfe-commits mailing list