From 2ca03d2f8cc86821efb781c7ae97b84592c3888a Mon Sep 17 00:00:00 2001
From: "yang.lee" <yang.lee@starfivetech.com>
Date: Thu, 26 May 2022 11:01:19 +0800
Subject: [PATCH 1/3] libcxxabi: Find libunwind headers when 
 LIBCXXABI_LIBUNWIND_INCLUDES is set

Currently, when LIBCXXABI_LIBUNWIND_INCLUDES is set via CMake arguments
then it ends up not searching the specified dir and unwind.h is not found
especially for ARM targets

This patch makes the searching synthesized directories and then set
LIBCXXABI_LIBUNWIND_INCLUDES if its there in environment

Rebased by Lee Yang
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 libcxxabi/CMakeLists.txt | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt
index a7d6d1902158..16a040fcef27 100644
--- a/libcxxabi/CMakeLists.txt
+++ b/libcxxabi/CMakeLists.txt
@@ -517,13 +517,8 @@ endif()
 # Setup Source Code
 #===============================================================================
 
-set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
-    "Specify path to libunwind includes." FORCE)
-set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
-    "Specify path to libunwind source." FORCE)
-
 if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
-  find_path(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL libunwind.h
+  find_path(LIBCXXABI_LIBUNWIND_INCLUDES libunwind.h
     PATHS ${LIBCXXABI_LIBUNWIND_INCLUDES}
           ${LIBCXXABI_LIBUNWIND_PATH}/include
           ${CMAKE_BINARY_DIR}/${LIBCXXABI_LIBUNWIND_INCLUDES}
@@ -534,15 +529,21 @@ if (LIBCXXABI_USE_LLVM_UNWINDER OR LLVM_NATIVE_ARCH MATCHES ARM)
     NO_CMAKE_FIND_ROOT_PATH
   )
 
-  if (LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL-NOTFOUND")
-    set(LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL "")
+  if (LIBCXXABI_LIBUNWIND_INCLUDES STREQUAL "LIBCXXABI_LIBUNWIND_INCLUDES-NOTFOUND")
+    set(LIBCXXABI_LIBUNWIND_INCLUDES "")
   endif()
 
-  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL STREQUAL "")
-    include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES_INTERNAL}")
+  if (NOT LIBCXXABI_LIBUNWIND_INCLUDES STREQUAL "")
+    include_directories("${LIBCXXABI_LIBUNWIND_INCLUDES}")
   endif()
 endif()
 
+set(LIBCXXABI_LIBUNWIND_INCLUDES "${LIBCXXABI_LIBUNWIND_INCLUDES}" CACHE PATH
+    "Specify path to libunwind includes." FORCE)
+set(LIBCXXABI_LIBUNWIND_PATH "${LIBCXXABI_LIBUNWIND_PATH}" CACHE PATH
+    "Specify path to libunwind source." FORCE)
+
+
 # Add source code. This also contains all of the logic for deciding linker flags
 # soname, etc...
 add_subdirectory(include)
-- 
2.25.1

